一个makefile调用多个makefile 文件示例

项目1makefile:

LIBDIR = /root
INCDIR = . ./Include
TARGET = x
MAKEFILE = makefile
LIBS = dl pthread rt
TXLIB = aes
#CC = gcc -ggdb
CC = gcc
CPPFLAGS = -MD
# add -D_INTERRUPT to CFLAGS to switch to interrupt mode.
CFLAGS := -O -Wall -D_REENTRANT -fPIC $(addprefix -I, $(INCDIR)) -g
LDFLAGS = -Wl,-Bsymbolic -rdynamic
SOURCE := $(wildcard *.c) $(wildcard *.cpp)
OBJS := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCE)))
DEPS := $(patsubst %.o,%.d,$(OBJS))
all : $(TARGET)
clean :
        -rm -f  ../$(TARGET) $(OBJS) $(DEPS) *~ core*
-include $(DEPS)
$(TARGET) : $(OBJS) $(MAKEFILE)
        $(CC) -o ../$(TARGET) $(LDFLAGS) $(OBJS) $(addprefix -l,$(LIBS)) -laes -L/usr/lib/mysql -lmysqlclient -lm -lz -lstdc++

项目2makefile:

TARGET=moni_x
CC=gcc
CFLAGS=-Wall -O -g
SOURCE=$(wildcard *.c)
OBJS=${SOURCE:.c=.o}
all: $(TARGET)
$(TARGET):$(OBJS)
        $(CC) $(CFLAGS)  $^ -o ../$@
#       $(CC) $(CFLAGS) $(OBJS) -o ../$(TARGET)
.PHONY: clean
clean:
        rm -rf  ../$(TARGET) $(OBJS) *~ core*

总makefile:

SUBDIRS = Clean-with-com4  moni_x
all:
        @list='$(SUBDIRS)'; for subdir in $$list; do \
                echo "Making all in $$list"; \
                (cd $$subdir && make all); \
        done;
.PHONY: clean
clean:
        @list='$(SUBDIRS)'; for subdir in $$list; do \
                echo "Clean in $$subdir"; \
                (cd $$subdir && make clean); \

        done

 

来源

你可能感兴趣的:(shell,makefile)