1 ### The build commands and verbosity
3 # If we are verbose, we will show commands prefixed by $(Q) (which acts as
4 # @ in the non-verbose mode), and we will show the "real" cmds instead of
5 # their quiet versions (which are used in the non-verbose mode).
6 # Inspired by the Linux kernel build system.
17 # Show the command (quiet or non-quiet version based on the assignment
18 # just above) and then execute it.
19 ncmd = $(if $($(quiet)cmd_$(1)),echo $($(quiet)cmd_$(1)) &&) $(cmd_$(1))
20 cmd = @$(if $($(quiet)cmd_$(1)),echo $($(quiet)cmd_$(1)) &&) $(cmd_$(1))
21 mcmd = @$(if $($(mquiet)cmd_$(1)),echo $($(mquiet)cmd_$(1)) &&) $(cmd_$(1))
23 quiet_cmd_compile = ' [CC] $(RELPATH)$@'
24 masq_cmd_compile = $(COMPILE) -c $<
25 cmd_compile = $(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
27 # Rule to compile a set of .o files into one .o file
28 quiet_cmd_ld_objs = " [LD] $(RELPATH)$@"
29 cmd_ld_objs = $(LD) -r -o $@ $(filter $(OBJS), $^) \
30 $(foreach subdir,$(sort $(filter-out src,$(SUBDIRS))), \
31 `test -e $(subdir)/lib.o && echo $(subdir)/lib.o`)
33 quiet_cmd_link = ' [LINK] $(RELPATH)$@'
34 cmd_link = $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
36 quiet_cmd_sparse = ' [SPARSE] $(RELPATH)$(2)'
37 cmd_sparse = $(SPARSE) $(DEFS) $(INCLUDES) $(AM_CFLAGS) $(CFLAGS) $(SPARSE_FLAGS) $(2)
40 quiet_cmd_recmake = "[MAKE $(3)] $(RELPATH)$(2)"
41 cmd_recmake = $(MAKE) -C $(2) $(3)
43 quiet_cmd_installdata = " [INSTALL] $(RELPATH)$(2) -> $(3)"
44 cmd_installdata = $(INSTALL_DATA) $(2) $(3)
46 quiet_cmd_installprog = " [INSTALL] $(RELPATH)$(2) -> $(3)"
47 cmd_installprog = $(INSTALL_PROGRAM) $(2) $(3)
50 ### Internal build rules
52 DEP_FILES_1 = $(foreach src,$(OBJS),.deps/$(src))
53 DEP_FILES = $(DEP_FILES_1:%.o=%.P)
55 DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
63 @-cp .deps/$(*F).pp .deps/$(*F).P; \
64 tr ' ' '\012' < .deps/$(*F).pp \
65 | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
70 SUBDIRS += $(SUBDIRS-yes)
77 ifneq ($(findstring cleanall,$(MAKECMDGOALS)),)
81 ifneq ($(findstring init,$(MAKECMDGOALS)),)
82 # FIXME: Detect when $(subdir)/Makefile is $(srcdir)/$(subdir)/Makefile
83 # and error out so the user won't overwrite the 'master' Makefiles.
89 SUBDIRS += $(SUBDIRS-no)
99 lib.o: $(sort $(OBJS)) $(foreach subdir,$(sort $(filter-out src,$(SUBDIRS))), $(wildcard $(subdir)/lib.o))
103 CLEAN += $(OBJS) $(LIB_O)
108 all-default: $(LIB_O) $(PROGS) $(MAN1) $(MAN5)
111 @$(foreach subdir,$(sort $(SUBDIRS)), \
112 $(MKINSTALLDIRS) $(subdir) >/dev/null; \
113 echo 'include $(SRC)/$(RELPATH)/$(subdir)/Makefile' > $(subdir)/Makefile;)
116 -test -z "$(CLEAN)" || $(RM) $(CLEAN)
118 cleanall-default: clean-default
122 @$(foreach file, $(wildcard *.c), \
123 $(call ncmd,sparse,$(file));)
126 # sparse is architecture-neutral, which means that we need to tell it
127 # explicitly what architecture to check for. Fix this up for yours..
128 SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__
129 install-default: all-default
131 @$(MKINSTALLDIRS) $(DESTDIR)$(bindir)
132 @$(foreach file,$(PROGS), \
133 $(call ncmd,installprog,$(file),$(DESTDIR)$(bindir));)
136 @$(MKINSTALLDIRS) $(DESTDIR)$(mandir)/man1
137 @$(foreach file,$(MAN1), \
138 $(call ncmd,installdata,$(file),$(DESTDIR)$(mandir)/man1);)
141 @$(MKINSTALLDIRS) $(DESTDIR)$(mandir)/man5
142 @$(foreach file,$(MAN5), \
143 $(call ncmd,installdata,$(file),$(DESTDIR)$(mandir)/man5);)
148 .PHONY: all-recursive install-recursive clean-recursive cleanall-recursive init-recursive check-recursive
150 all-recursive install-recursive clean-recursive cleanall-recursive init-recursive check-recursive:
152 @$(foreach subdir,$(sort $(SUBDIRS)), \
153 $(call ncmd,recmake,$(subdir),$(subst -recursive,,$@)) || exit 1;)
156 all: all-recursive all-default all-local
157 install: install-recursive install-default install-local
158 check: check-recursive check-default check-local
159 clean: clean-recursive clean-default clean-local
161 cleanall: cleanall-recursive cleanall-default
162 init: init-default init-recursive
169 # Tell versions [3.59,3.63) of GNU make to not export all variables.
170 # Otherwise a system limit (for SysV at least) may be exceeded.