-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.Nice.mk
48 lines (42 loc) · 1.48 KB
/
.Nice.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
47
48
.EXTRA_PREREQS+= Makefile .Nice.mk
# location for intermediate files (.o and .mk)
# (will be created automatically, as well as any subdirectories)
# (ex: src `subdir/file` will create `.junk/subdir/` and compile `subdir/file.c` to `.junk/subdir/file.o`)
junkbase:= .junk
ifdef junkdir
junkdir:= $(junkbase)/$(junkdir)
else
junkdir:= $(junkbase)
endif
srcdir?= .
# print status nicely (assumes ansi-compatible terminal)
empty:=
comma:= ,
#printlist = [$1m$(subst $(empty) $(empty),[m$(comma) [$1m,$(2:$(3)%=[37m$(3)[$1m%))
printlist = [$1m$(subst $(empty) $(empty),[m$(comma) [$1m,$(2:$3%=[$1m%))
print = echo '$(call printlist,33,$1,$2) [37mfrom: $(call printlist,32,$3,$4)[m'
#\time -f %e
# Link
$(output): $(srcs:%=$(junkdir)/%.o)
@$(call print,$@,,$^,$(junkdir)/)
@$(CC) $(LDFLAGS) $^ $(libs:%=-l%) -o $@
# Compile
$(junkdir)/%.o $(junkdir)/%.mk : $(srcdir)/%.c
@echo $(MAKE_VERSION)
@mkdir -p $(@D)
@$(call print,$(junkdir)/$*.o,$(junkdir)/,$^,$(srcdir)/)
@$(CC) $(CFLAGS) -MMD -MF$(junkdir)/$*.mk -MQ$(junkdir)/$*.mk -MQ$(<:%.c=$(junkdir)/%.o) -c $< -o $(junkdir)/$*.o
.PHONY: clean
clean:
$(RM) -r $(junkdir)
$(RM) $(output)
ifneq ($(findstring clean,$(MAKECMDGOALS)),)
#disable multiple jobs when clean is running, since that will break.
.NOTPARALLEL:
else
ifeq ($(findstring B,$(MAKEFLAGS)),)
# if `clean` is specified as a goal, or if the -B flag is passed,
# we skip including these files, because that will be redundant.
include $(srcs:%=$(junkdir)/%.mk)
endif
endif