首页 > 其他 > 详细

多层级的makefile编写——递归调用makefile

时间:2014-03-26 03:31:07      阅读:334      评论:0      收藏:0      [点我收藏+]

文件层级结构:

│  Makefile
│  tmp

├─include
│      public.h

└─src
    ├─moda
    │      Makefile
    │      moda.c
    │      moda.h
    │
    └─modb
            Makefile
            modb.c
            modb.h

public.h

#define MAX_SIZE 10

moda.c  (modb.c类似)

#include <stdio.h>
#include "moda.h"
#include "public.h"

int main(void)
{
	printf("This is mod A, MAX_SIZE:%d \n", MAX_SIZE);
	return 0;
}

顶层makefile:

CC = gcc

ROOT := $(shell pwd)
INCLUDE := $(ROOT)/include
SRC := $(ROOT)/src

USR_SUB_DIR := $(SRC)/moda $(SRC)/modb

default:usr

usr:
	@for n in $(USR_SUB_DIR); do $(MAKE) -C $$n ; done
	
clean:
	@for n in $(USR_SUB_DIR); do $(MAKE) -C $$n clean; done

moda目录下makefile

CC = gcc

ROOT := $(shell pwd)/../..
INCLUDE := $(ROOT)/include

CFLAGS += -I$(INCLUDE)

target:moda

modb:moda.o
	$(CC) -o moda moda.o

modb.o:moda.c
	$(CC) $(CFLAGS) -c moda.c 
	
clean:
	-rm *.o moda

执行:

linux:/mnt/hgfs/vmware-share/makefile # make 
make[1]: Entering directory `/mnt/hgfs/vmware-share/makefile/src/moda‘
gcc -I/mnt/hgfs/vmware-share/makefile/src/moda/../../include   -c -o moda.o moda.c
gcc   moda.o   -o moda
make[1]: Leaving directory `/mnt/hgfs/vmware-share/makefile/src/moda‘
make[1]: Entering directory `/mnt/hgfs/vmware-share/makefile/src/modb‘
gcc -I/mnt/hgfs/vmware-share/makefile/src/modb/../../include -c modb.c 
gcc -o modb modb.o
make[1]: Leaving directory `/mnt/hgfs/vmware-share/makefile/src/modb‘
linux:/mnt/hgfs/vmware-share/makefile #
linux:/mnt/hgfs/vmware-share/makefile # cd src/moda/
linux:/mnt/hgfs/vmware-share/makefile/src/moda # ll
总用量 5
drwxrwxrwx  1 root root    0 2014-03-25 23:51 .
drwxrwxrwx  1 root root    0 2014-03-25 23:10 ..
-rwxrwxrwx  1 root root  219 2014-03-25 23:30 Makefile
-rwxrwxrwx  1 root root 6803 2014-03-25 23:51 moda
-rwxrwxrwx  1 root root  149 2014-03-25 23:39 moda.c
-rwxrwxrwx  1 root root    0 2014-03-25 23:10 moda.h
-rwxrwxrwx  1 root root  908 2014-03-25 23:51 moda.o
linux:/mnt/hgfs/vmware-share/makefile/src/moda # ./moda
This is mod A, MAX_SIZE:10
linux:/mnt/hgfs/vmware-share/makefile #
linux:/mnt/hgfs/vmware-share/makefile #
linux:/mnt/hgfs/vmware-share/makefile #
linux:/mnt/hgfs/vmware-share/makefile # make clean
make[1]: Entering directory `/mnt/hgfs/vmware-share/makefile/src/moda‘
rm *.o moda
make[1]: Leaving directory `/mnt/hgfs/vmware-share/makefile/src/moda‘
make[1]: Entering directory `/mnt/hgfs/vmware-share/makefile/src/modb‘
rm *.o modb
make[1]: Leaving directory `/mnt/hgfs/vmware-share/makefile/src/modb‘


 




多层级的makefile编写——递归调用makefile,布布扣,bubuko.com

多层级的makefile编写——递归调用makefile

原文:http://blog.csdn.net/wangyuling1234567890/article/details/22111271

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!