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 [email protected] $<

%.dep : %.c
	@$(PP) $(CXFLAGS) -MM -MT $(@:.dep=.o) -o [email protected] $<

%.dep : %.cpp
	@$(PP) $(CXFLAGS) -MM -MT $(@:.dep=.o) -o [email protected] $<

%.o : %.s
	$(AS) $(ASFLAGS) -o [email protected] $<

%.o : %.c
	$(CC) $(CCFLAGS) -c -o [email protected] $<

%.o : %.cpp
	$(CX) $(CXFLAGS) -c -o [email protected] $<

-include $(DEPEND)

Leave a Reply

Your email address will not be published.