This repository has been archived by the owner on Sep 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgen.mk
47 lines (40 loc) · 1.4 KB
/
gen.mk
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
include $(UTILMK)
MKENV = SRCDIR="../../$(SRCDIR)" OBJDIR="../../$(OBJDIR)" UTILMK="../../$(UTILMK)" CC="$(CC)" CFLAGS="$(CFLAGS) -I../../$(SRCDIR)"
MKENV2 = SRCDIR="$(SRCDIR)" OBJDIR="$(OBJDIR)" UTILMK="$(UTILMK)" CC="$(CC)" CFLAGS="$(CFLAGS)"
ifndef MKRULES
MKOUT = $(OBJDIR)/[email protected]
all: $(BASEDIRS)
else
MKOUT = $(OBJDIR)/$(NAME).mk
all: $(OFILES)
.NOTPARALLEL:
endif
ifndef MKSUB
$(BASEDIRS):
@$(MAKE) --silent --no-print-directory -f gen.mk NAME="$@" ${MKENV2} MKSUB=y NAME="$@" $(MKOUT)
else
define MKSRC
$(subst .mk,,$(subst $(OBJDIR)/,$(SRCDIR)/,$@))
endef
define MKND
$(OBJDIR)/$(subst .mk,,$(subst $(OBJDIR)/,,$@))
endef
$(OBJDIR)/%.mk: $(wildcard $(SRCDIR)/$(NAME)/*.c $(SRCDIR)/$(NAME)/*.h)
@echo Writing $@...
@echo include $$$(esc)(UTILMK$(esc)) > $@
@$(echoblank) >> $@
@echo all: $(addprefix ../../$(OUTDIR)/,$(notdir $(CFILES:.c=.o))) >> $@
@$(echoblank) >> $@
@$(MAKE) --silent --no-print-directory -C "$(MKSRC)" -f ../../gen.mk NAME="$(subst .mk,,$(subst $(OBJDIR)/,,$@))" ${MKENV} MKRULES=y
ifeq ($(SHCMD),unix)
@[ ! -d "$(MKND)" ] && echo Creating $(MKND)... && mkdir -p "$(MKND)"; true
else ifeq ($(SHCMD),win32)
@if not exist "$(MKND)" echo Creating $(MKND)... & md "$(subst /,\,$(MKND))"
endif
endif
$(OUTDIR)/%.o: FORCE
@$(CC) $(CFLAGS) -MM "$(notdir $(@:.o=.c))" -MT "$@" >> $(MKOUT)
@echo $(TAB)$$$(esc)(COMPC$(esc)) >> $(MKOUT)
@$(echoblank) >> $(MKOUT)
FORCE:
.PHONY: all $(BASEDIRS)