-
Notifications
You must be signed in to change notification settings - Fork 1
/
rules.mk
80 lines (61 loc) · 1.88 KB
/
rules.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#
# rules.mk: build rules
#
# For automatic dependency resolution, set $(objects) to the list of object
# files needed for the build before including this file.
#
# $(clean) and $(distclean) should be set to the files to be removed on
# 'make clean' and 'make distclean', respectively.
#
# $(verbose) controls whether build commands are echoed verbatim, or in
# prettier " PROG FILE" format. Set verbose=y for verbatim output.
#
.SUFFIXES:
.PHONY: clean distclean
dependencies = $(addprefix ., $(addsuffix .d, $(basename $(objects))))
distclean += $(dependencies)
ifeq ($(verbose),y)
quiet =
else
quiet = quiet_
endif
clean:
$(if $(clean), rm -f $(clean))
distclean: clean
$(if $(distclean), rm -f $(distclean))
%.o: %.c
$(call cmd,cc)
%.o: %.S
$(call cmd,ccas)
.%.d: %.c
$(call cmd,dep)
# CC for program object files (.o)
quiet_cmd_cc = CC $@
cmd_cc = $(CC) -c $(CPPFLAGS) $(ALLCFLAGS) $(1) -o $@ $<
# create archive
quiet_cmd_ar = AR $@
cmd_ar = $(AR) $(ARFLAGS) $@ $^
quiet_cmd_ccas = AS $@
cmd_ccas = $(CC) -c $(CPPFLAGS) $(1) -o $@ $<
quiet_cmd_as = AS $@
cmd_as = $(AS) $(ASFLAGS) -o $@ $<
# LD for programs; optional parameter: libraries
quiet_cmd_ld = LD $@
cmd_ld = $(LD) $(LDFLAGS) -o $@ $^ $(1)
# generate dependencies file
quiet_cmd_dep = DEP $@
cmd_dep = echo "$@ `$(CC) -MM $(CPPFLAGS) $<`" > $@
# call submake
quiet_cmd_smake = MAKE $@
cmd_smake = cd $@ && $(MAKE)
# generate man page from .txt file
quiet_cmd_ttman = MAN $@
cmd_ttman = doc/ttman $< $@
# generate man page as plain text file
quiet_cmd_groff = GROFF $@
cmd_groff = groff -man -Tascii $< | col -bx > $@
# cmd macro (taken from kbuild)
cmd = @$(if $($(quiet)cmd_$(1)),echo ' $(call $(quiet)cmd_$(1),$(2))' &&) $(call cmd_$(1),$(2))
ifneq ($(dependencies),)
-include $(dependencies)
endif