CFLAGS = -g -lobapi -L. %.o : CFLAGS = -L. scan_sync_demo.o : scan_sync_demo.c gcc -c $(CFLAGS) {1}lt; -o $@ set_sync_demo.o : set_sync_demo.c gcc -c $(CFLAGS) set_sync_demo.c time_test.o : time_test.c gcc -c $(CFLAGS) time_test.c sum_async_demo.o : sum_async_demo.c gcc -c $(CFLAGS) sum_async_demo.c scan_sync_demo: scan_sync_demo.o gcc $(CFLAGS) {1}lt; -o $@ set_sync_demo:set_sync_demo.o gcc $(CFLAGS) $@ -o set_sync_demo time_test:time_test.o gcc $(CFLGGS) $@ -o time_test sum_async_demo:sum_async_demo.o gcc $(CFLAGS) $@ -o sum_async_demo .PHONY : clean clean: rm scan_sync_demo scan_sync_demo.o \ set_sync_demo set_sync_demo.o \ time_test time_test.o \ sum_async_demo sum_async_demo.o
利用通配符的简化版本:
CFLAGS = -g -L. LDFLAGS = -lobapi -L. targets = scan_sync_demo set_sync_demo time_test sum_async_demo objects = scan_sync_demo.o set_sync_demo.o time_test.o sum_async_demo.o all: $(targets) $(objects): %.o: %.c $(CC) -c $(CFLAGS) {1}lt; -o $@ $(targets): $(objects) $(CC) $(CFLAGS) $(LDFLAGS) {1}lt; -o $@ .PHONY : clean clean: rm scan_sync_demo scan_sync_demo.o \ set_sync_demo set_sync_demo.o \ time_test time_test.o \ sum_async_demo sum_async_demo.oCFLAGS = -g -L. LDFLAGS = -lobapi -L. targets = scan_sync_demo set_sync_demo time_test sum_async_demo objects = scan_sync_demo.o set_sync_demo.o time_test.o sum_async_demo.o all: $(targets) %.o: %.c $(CC) -c $(CFLAGS) {1}lt; -o $@ $(targets): %: %.o $(CC) $(CFLAGS) $(LDFLAGS) {1}lt; -o $@ .PHONY : clean clean: rm scan_sync_demo scan_sync_demo.o \ set_sync_demo set_sync_demo.o \ time_test time_test.o \ sum_async_demo sum_async_demo.o
本文详细介绍了如何使用CFLAGS参数和Makefile进行代码编译配置,包括目标、对象、编译命令和清理操作,提供了简化版Makefile示例及改造方法。
6025

被折叠的 条评论
为什么被折叠?



