一个简单的Makefile示例
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一个简单的Makefile示例相关的知识,希望对你有一定的参考价值。
#* #*********************************************************************************************** # Makefile # # Author : Lyu Yang # Description : Makefile for GNU/GCC # #*********************************************************************************************** #* # Project Name PROJECT = main # Architecture and Platform ARCH = x86 PLATFORM = Debug CROSS = # Include Dirs and Library Dirs INCLUDE_DIRS = -I ./ LIBRARY_DIRS = -L ./ # GCC Parameters CC = $(CROSS)gcc CFLAGS = -c $(INCLUDE_DIRS) CXX = $(CROSS)g++ CXXFLAGS = -c $(INCLUDE_DIRS) AS = $(CROSS)gcc ASFLAGS = -x assembler-with-cpp LD = $(CROSS)g++ LDFLAGS = $(LIBRARY_DIRS) OBJCP = $(CROSS)objcopy OBJCPFLAGS = -O binary -S -R .note -R .commen AR = $(CROSS)ar ARFLAGS = cr DUMP = $(CROSS)objdump DUMPFLAG = -d SIZE = $(CROSS)size # Make Temp Dirs $(shell mkdir $(PLATFORM) && mkdir $(PLATFORM)/$(ARCH)) # Source Files SRCS := $(wildcard dir1/*.cpp) SRCS += $(wildcard dir2/*.cpp) # Build Objects OBJS = $(SRCS:.cpp=.o) OBJB = $(patsubst %.cpp, $(PLATFORM)/$(ARCH)/%.o, $(notdir ${SRCS})) # Make ALL .PHONY: all clean debug all: $(PROJECT).exe $(PROJECT).exe: $(OBJB) @$(LD) $(LDFLAGS) $^ -o $(PLATFORM)/$(ARCH)/[email protected] @echo "$(CXX) $(notdir $^) -o $(notdir [email protected])" $(OBJB): $(OBJS) %.o: %.cpp @$(CXX) $(CFLAGS) $^ -o $(PLATFORM)/$(ARCH)/$(notdir [email protected]) @echo "$(CXX) $(notdir $^) -o $(notdir [email protected])" clean: @rm -rf $(PLATFORM) @echo "Clean All!" debug: @$(CROSS)gdb $(PLATFORM)/$(ARCH)/$(PROJECT).exe
以上是关于一个简单的Makefile示例的主要内容,如果未能解决你的问题,请参考以下文章