makefile多级目录的编译

方法一、

##############################
# file   Makefile
# author  chenli
# date  2008-02-01
###############################
 

#编译所有子目录
#SUBDIRS=`ls -d */ | grep -v 'bin' | grep -v 'lib' | grep -v'include'`
#编译指定子目录
SUBDIRS=dir1 dir2 dir3
define make_subdir
 @for subdir in $(SUBDIRS) ; do \
 ( cd $$subdir && make $1) \
 done;
endef
all:
 $(call make_subdir , all)
 
install :
 $(call make_subdir , install)
 
debug:
 $(call make_subdir , debug)
clean:
 
$(call make_sub


方法二、


DIRS = by-util spoolers input-plugins output-plugins main

.PHONY:all clean $(DIRS)

all:$(DIRS)

clean:$(DIRS)

$(DIRS):
    $(MAKE) -C $@ $(MAKECMDGOALS)

子目录:

CC := gcc
SOURCE := $(wildcard *.c)
OBJS := $(patsubst %.c, %.o, $(SOURCE))
INCLUDE := -I.
CFLAGS := -g -Wall -fPIC -shared $(INCLUDE)
TARGET_LIB := libby_util.so

ARCH := /usr/lib/
ifeq ($(shell uname -m), x86_64)
    ARCH := /usr/lib64/
else
    ARCH := /usr/lib/
endif
ARCH := ../../../target/lib/

all: $(OBJS)
    $(CC) $(CFLAGS) $(OBJS) -o $(TARGET_LIB)
    install -c -m 644 -g bin -o root "${TARGET_LIB}" $(ARCH)

.PHONY: clean

clean:
    rm -rf *.o $(TARGET_LIB)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值