模板1
test:prog.o code.o
gcc –o test prog.o code.or
prog.o:prog.c prog.h code.h
gcc –c prog.c –o prog.o
code.o:code.c code.h
gcc –c code.c –o code.o
clean:rm –f *.o
*************************************************************************
模板2
SRC:= adc_text.c
INC:= twl4030-madc.h
CFLAGS:= -g
OPTION:= -lpthread
EXTINC:= -I/home/belter/dm3730/linux-2.6.32/include/linux/i2c
adc_text:$(SRC) $(INC)
arm-none-linux-gnueabi-gcc -o $@ $^
cp adc_text /opt/myrootfs/
.PHONY:clean
clean:
rm -rf adc_text
****************************************************************************************
模板3 (内核ko模块)
ifeq ($(KERNELRELEASE),)
KERNELDIR =/home/guozhen/linux-2.6.35.5
PWD =$(shell pwd)
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
cp ./hello_dev.ko /opt/rootfs/mytext
modules_install:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
clean:
rm -rf *.o *.ko .tmp_versions *.mod.c
else
obj-m :=hello_dev.o
endif
****************************************************************************************
模板4(多目录工程)
1 SRC:= main.c dispro.c def.c
2 INC:= def.h dispro.h print.h
3 CC:=gcc
4 CFLAGS:= -g
5 OPTION:= -lpthread
6
7 vpath %.c = ./src
8 vpath %.h = ./inc
9 #VPATH = ./src:./inc
10
11
12 guo:$(SRC) $(INC)
13 $(CC) $(CFLAGS) -o $@ $^ $(OPTION)
14
15 .PHONY:clean
16 clean:
17 @$(RM) -f *.o guo
****************************************************************************************
makefile调试
在makefile中打印输出信息的方法是:
$(warning xxxxx)或者$(error xxxxx)
输出变量方式为:$(warning $(XXX))
阅读(1188) | 评论(0) | 转发(0) |