-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
56 lines (42 loc) · 1.58 KB
/
Copy pathMakefile
File metadata and controls
56 lines (42 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
TOPDIR = $(shell DIR=.; while [ ! "`readlink -f \"$${DIR}\"`" = "/" -a ! -f "$${DIR}/config.mk" ]; do DIR="../$${DIR}"; done; echo "$${DIR}")
ifeq ($(shell readlink -f "$(TOPDIR)"),/)
$(error Could not find the project top directory with config.mk)
endif
include $(TOPDIR)/config.mk
ASMFILES = $(wildcard *.S)
SRCFILES = $(wildcard *.c)
OBJFILES = $(SRCFILES:.c=.c.o)
OBJFILES += $(ASMFILES:.S=.S.o)
OUTFILE = out.a
# Sub directories to build
SUBDIRS = $(foreach dir,$(wildcard */Makefile),$(dir $(dir)))
LIBS = $(addsuffix /$(OUTFILE),$(SUBDIRS))
DEPDIR = .deps
df = $(DEPDIR)/$(*F)
.PHONY: all clean
.PHONY: $(SUBDIRS)
all: $(OUTFILE)
@echo " [DONE] $(CURRENTPATH)"
clean: $(SUBDIRS)
@echo " [ RM ] $(OBJFILES) $(OUTFILE)"
@$(RM) $(OBJFILES) $(OUTFILE)
@$(RM) -R $(DEPDIR)
$(OUTFILE): $(OBJFILES) $(SUBDIRS)
@echo " [ AR ] $(CURRENTPATH)$(OUTFILE)"
@$(RM) $(OUTFILE)
@$(AR) -cmT $(OUTFILE) $(OBJFILES) $(LIBS)
$(SUBDIRS):
@echo " [ CD ] $(CURRENTPATH)$@"
@+make -C "$@" "CURRENTPATH=$(CURRENTPATH)$@" $(MAKECMDGOALS)
$(DEPDIR):
@mkdir -p $@
%.c.o: %.c | $(DEPDIR)
@echo " [ CC ] $(CURRENTPATH)$<"
@$(CC) $(CFLAGS) -c -MD -o $@ $<
@cp $*.c.d $(df).c.P; sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' -e '/^$$/ d' -e 's/$$/ :/' < $*.c.d >> $(df).c.P; $(RM) $*.c.d
%.S.o: %.S | $(DEPDIR)
@echo " [ AS ] $(CURRENTPATH)$<"
@$(CC) $(CFLAGS) $(ASFLAGS) -c -MD -o $@ $<
@cp $*.S.d $(df).S.P; sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' -e '/^$$/ d' -e 's/$$/ :/' < $*.S.d >> $(df).S.P; $(RM) $*.S.d
-include $(SRCFILES:%.c=$(DEPDIR)/%.c.P)
-include $(ASMFILES:%.S=$(DEPDIR)/%.S.P)