A common Makefile

如果你不喜欢写 Makefile, 使用这个 Makefile 做少量的修改就可以使用了。

# Toolchain Setup
PP=cpp
AS=as
CC=gcc
CX=g++
LD=gcc
 
# Compilation Configurations
ASFLAGS=
CCFLAGS=
CXFLAGS=
LDFLAGS=
 
# Objectives
TARGET= 	# 目标程序名称
OBJECT= 	# 此处填写模块名称,例如: main.o
DEPEND=$(OBJECT:.o=.dep)
 
# Procedures
all : $(TARGET)
 
$(TARGET) : $(OBJECT)
	$(LD) -o $(TARGET) $(OBJECT) $(LDFLAGS)
 
clean:
	$(RM) $(TARGET) $(OBJECT) $(DEPEND)
 
# Standard Procedures
%.dep : %.s
	@$(PP) $(ASFLAGS) -MM -MT $(@:.dep=.o) -o $@ $<
 
%.dep : %.c
	@$(PP) $(CXFLAGS) -MM -MT $(@:.dep=.o) -o $@ $<
 
%.dep : %.cpp
	@$(PP) $(CXFLAGS) -MM -MT $(@:.dep=.o) -o $@ $<
 
%.o : %.s
	$(AS) $(ASFLAGS) -o $@ $<
 
%.o : %.c
	$(CC) $(CCFLAGS) -c -o $@ $<
 
%.o : %.cpp
	$(CX) $(CXFLAGS) -c -o $@ $<
 
-include $(DEPEND)

Leave a Reply

Your email address will not be published. Required fields are marked *