主Makefile:
CURDIR := $(shell pwd)
include $(CURDIR)/config.mk
SHARELIBS := uimmshare param comm global
MODULES := hdtst mntn bst
all :
for module in $(MODULES); do make -w -C $$module all; done //到子目录去执行里面的Makefile,这里与shell编程相结合了
for module in $(MODULES); do make -w -C $$module ; done
share :
for module in $(SHARELIBS); do make -w -C $$module all; done
for module in $(SHARELIBS); do make -w -C $$module ; done
clean :
for module in $(MODULES); do make -w -C $$module clean; done
share_clean :
for module in $(SHARELIBS); do make -w -C $$module clean; done
子Makefile:
TOPDIR := $(shell pwd)
ROOTDIR := $(shell cd ..; pwd)
include $(ROOTDIR)/config.mk
LIB = $(shell basename $(TOPDIR)).$(LIB_TYPE)
SOURCE := $(wildcard *.c) $(wildcard *.cpp) //这个也很有用
OBJS := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCE))) //还有这个
all: $(LIB)
$(LIB): $(OBJS)
ifeq ($(LIB_TYPE),a)
$(AR) crsv $@ $(OBJS) //编译静态库
-mv $@ $(ROOTDIR)/appfs/lib/$(TARGET_ARCH)/lib$@
else
$(CC) -fpic -shared -o $@ $(OBJS)
-mv -f $@ $(ROOTDIR)/appfs/lib/$(TARGET_ARCH)/lib$@
ifeq ($(TARGET_ARCH), arm)
$(STRIP) $(ROOTDIR)/appfs/lib/$(TARGET_ARCH)/lib$@
endif
endif
.PHONY : depend clean clean_obj clean_depend
depend: Makefile $(SOURCE)
$(CC) -M $(CFLAGS) $(SOURCE) > .depend
clean : clean_obj clean_depend
-rm -f $(ROOTDIR)/appfs/lib/$(TARGET_ARCH)/lib$(LIB)
clean_obj :
-rm -f *.o
clean_depend :
-rm -f .depend
sinclude .depend
另附上几个简单的Makefile:
1.
CURDIR := $(shell pwd)
MODULES := 1 2 3
all:
for module in $(MODULES); do make -w -C $$module; done
#%.o:%.c
# $(CC) $(CFLAGS) -c $< -o $@ //这两个也很有用
clean:
make -C 3 clean
rm -vf main
2.
TOPDIR := $(shell pwd)
ROOTDIR := $(shell cd ..; pwd)
SRC=main.c
OBJS=main.o
CC=gcc
CFLAGS=-Wall -O -g
#all: $(OBJS)
$(OBJS): $(SRC)
$(CC) $(CFLAGS) -I$(ROOTDIR)/xx/ -c $< -o $@ //这里用到了-I来包含非当前目录下的头文件
-mv $@ $(ROOTDIR)/yy/$@
clean:
-rm -f *.o
3.
CUDIR := $(shell pwd)
ROOTDIR := $(shell cd ..; pwd)
CFLAGS := -I$(ROOTDIR)/t/h/
hello:hello.c
gcc $< $(CFLAGS) -o $@
阅读(5486) | 评论(0) | 转发(1) |