makefile

Makefile
CROSS_COMPILE =
AS		= $(CROSS_COMPILE)as
LD		= $(CROSS_COMPILE)ld
CC		= $(CROSS_COMPILE)gcc
CPP		= $(CC) -E
AR		= $(CROSS_COMPILE)ar
NM		= $(CROSS_COMPILE)nm

STRIP		= $(CROSS_COMPILE)strip
OBJCOPY		= $(CROSS_COMPILE)objcopy
OBJDUMP		= $(CROSS_COMPILE)objdump

export AS LD CC CPP AR NM
export STRIP OBJCOPY OBJDUMP

#获取TOP_PATH
#TOP_PATH = $(shell pwd)
#添加vpath变量
#VPATH = $(TOP_PATH)/DIR
#添加头文件自动搜索路径
#CINCLUDES = -I(TOP_PATH)/DIR

CFLAGS := -Wall -O0 -g   #$(CINCLUDES)
SAVE_TEMPS := -save-temps

LDFLAGS := 

export CFLAGS LDFLAGS

TOPDIR := $(shell pwd)
export TOPDIR
lpthread :=-lpthread
TARGET := test


 obj-y += main.o
 #obj-y += tpool.o
 #obj-y += b/
 #obj-y += cc/

all : 
	make -C ./ -f $(TOPDIR)/Makefile.build
	$(CC)  $(LDFLAGS) -o $(TARGET) built-in.o $(lpthread)


clean:
	rm -f $(shell find -name "*.o")
	rm -f $(shell find -name "*.d")
	rm -f $(shell find -name "*.i*")
	rm -f $(shell find -name "*.s")
	rm -f $(TARGET)
	rm -f $(shell find -name "core")
.PHONY:all clean 


Makefile.build
PHONY := build
build :
obj-y :=
subdir-y :=

include Makefile
__subdir-y	:= $(patsubst %/,%,$(filter %/, $(obj-y)))
subdir-y	+= $(__subdir-y)
subdir_objs := $(foreach f,$(subdir-y),$(f)/built-in.o)
cur_objs := $(filter-out %/, $(obj-y))
dep_files := $(foreach f,$(cur_objs),.$(f).d)

PHONY += $(subdir-y)
build : $(subdir-y) built-in.o
$(subdir-y):
	make -C $@ -f $(TOPDIR)/Makefile.build
built-in.o : $(cur_objs) $(subdir_objs)
	$(LD) -r -o $@ $^
dep_file = .$@.d
%.o : %.c
	$(CC)  $(SAVE_TEMPS) $(CFLAGS) -Wp,-MD,$(dep_file)  -c -o   $@  $< 
.PHONY : $(PHONY)

posted @ 2021-11-05 14:26  上官鸿信の  阅读(33)  评论(0编辑  收藏  举报