每次想写个makefile都忘了咋写,大概还是要记一下的。
windows下的可用模板
Windows下的Makefile
windows下的makefile教程
Basic Win32 GUI application which can be built using MinGW.
大概如果要用mingw32-make来搞的话,直接参考linux下的写法即可。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
OBJS = obj/AboutDialog.o obj/MainWindow.o obj/Resource.o obj/WinMain.o
WARNS = -Wall
CC = gcc RC = windres TARGET = Win32App.exe
ifeq ($(CHARSET), ANSI) CFLAGS = -O2 -std=c99 -D _WIN32_IE=0x0500 -D WINVER=0x0500 $(WARNS) -Iinclude else CFLAGS = -O2 -std=c99 -D UNICODE -D _UNICODE -D _WIN32_IE=0x0500 -D WINVER=0x0500 $(WARNS) -Iinclude endif
LDFLAGS = -s -lcomctl32 -Wl,--subsystem,windows
.PHONY: all clean
all: bin/$(TARGET)
clean: [ -e bin/$(TARGET) ] && rm -rf bin/$(TARGET) [ -d obj ] && rm -rf obj
bin obj: [ ! -d $@ ] && mkdir $@
obj/%.o: src/%.c | obj $(CC) $(CFLAGS) -c $< -o $@
obj/Resource.o: res/Resource.rc res/Application.manifest res/Application.ico include/Resource.h | obj $(RC) -I./include -I./res -i $< -o $@
bin/$(TARGET): $(OBJS) | bin $(CC) -o $@ $(OBJS) $(LDFLAGS)
obj/AboutDialog.o: include/AboutDialog.h include/Globals.h include/Resource.h obj/MainWindow.o: include/AboutDialog.h include/Globals.h include/MainWindow.h include/Resource.h obj/WinMain.o: include/Globals.h include/MainWindow.h include/Resource.h
|
Linux
Linux环境C语言编程项目多级Makefile管理模板
大概是可用的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| exclude_dirs := .git
SRCS = $(wildcard *.c ../lib/*.c) $(wildcard *.cpp ../lib/*.cpp) OBJS = $(SRCS:.c = .o) OUTPUT = test
CC = gcc CXX = g++ INCLUDES = -I../include \
LIBS = -L../lib \ CCFLAGS = -g -Wall -O1 CXXFLAGS:= $(CFLAGS) -DHAVE_CONFIG_H
all:$(OUTPUT)
$(OUTPUT) : $(OBJS) mkdir -p output $(CC) $^ -o $@ $(INCLUDES) $(LIBS)
%.o : %.c $(CC) -c $< $(CCFLAGS)
rebuild: clean all
clean: rm -rf *.out *.o
.PHONY:clean
|