多目录makefile的书写

    技术2022-05-20  58

    多目录makefile的书写

    多目录makefile的书写

    由于涉及到多目录下makefile文件的编写,每个目录下makefile 文件都不相同。现在简单说下我的多目录下makefile文件的编写。 我把所需要的目录都放在src里面,如图所示 其中libs存放库文件,bin存放可执行文件,app存放源文件目录,include存放所要包含的头文件 makefile编写如下: TOPDIR := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi) export TOPDIR LIBPATH := $(TOPDIR)/libs export LIBPATH ######################################################################### # sub directories SUBDIRS = app .PHONY : $(SUBDIRS) ######################################################################### all: depend $(SUBDIRS) depend dep: @for dir in $(SUBDIRS) ; do $(MAKE) -C $$dir .depend ; done $(SUBDIRS): $(MAKE) -C $@ all clean: @for dir in $(SUBDIRS) ; do $(MAKE) -C $$dir clean ; done 在app下有自己的源文件目录,如图: 里面有一个项目叫ebook,当然还可以放更多的项目进来,ebook里面放的就是源文件了,makefile如下: SUBDIRS = ebook #项目是什么,就改什么 .PHONY : $(SUBDIRS) all: .depend $(SUBDIRS) $(SUBDIRS): $(MAKE) -C $@ all .depend dep: @for dir in $(SUBDIRS) ; do $(MAKE) -C $$dir .depend ; done clean: @for dir in $(SUBDIRS) ; do $(MAKE) -C $$dir clean ; done 同样在ebook中也要写makefile,也是最后一个makefile了 INCLUDEDIRS += -I. -I/usr/include/microwin -I/$(TOPDIR)/include CC = gcc CFLAGS = -O4 $(INCLUDEDIRS) ELF = ../../bin/ebook #相对于可执行文件 AOBJS = $(patsubst %.s, %.o, $(wildcard *.s)) COBJS = $(patsubst %.c, %.o, $(wildcard *.c)) CPPOBJS = $(patsubst %.cpp, %.o, $(wildcard *.cpp)) OBJS = $(AOBJS) $(COBJS) $(CPPOBJS) all: .depend $(OBJS) $(CC) $(CFLAGS) $(OBJS) / -L $(LIBPATH) -lini/ -L /usr/lib -ljpeg -lnano-X -lfreetype -lttf -lz -lpthread/ -L /usr/X11R6/lib -lX11/ -o $(ELF) chmod 755 $(ELF) ######################################################################### .depend: Makefile $(AOBJS:.o=.S) $(COBJS:.o=.c) $(CPPOBJS:.o=.cpp) $(CC) -M $(CFLAGS) $(AOBJS:.o=.S) $(COBJS:.o=.c) $(CPPOBJS:.o=.cpp) > $@ sinclude .depend ######################################################################### clean: rm -f *.o .depend rm -f $(ELF) 好了,现在就可以在src下敲写make了

     


    最新回复(0)