1 #[ Rules and Depends ]##################################################{{{#
3 AUTO_DEPENDS += filter_c
4 filter_c = $(addprefix $2/,$(patsubst %.c,%.o,$(filter %.c,$1)))
6 # this implicit rule is used to force directory existence, without depending
7 # on the directory itself, since its mtime changes too often.
8 %/.exists: Makefile $(CONFDIR)/$(wildcard *.mk)
12 # We don't want make to remove these files because of default rules.
16 $(_cobjs)/$1/%.o: %.c $(_cobjs)/$1/.exists
17 $(CC) $$(CFLAGS) $$($1_CPPFLAGS) $2 -MMD -MT "$$(@D)/$$*.d $$(@D)/$$*.o" -MF $$(@D)/$$*.d -g -c -o $$@ $$<
19 $(_cobjs)/$1/%.d: %.c $(_cobjs)/$1/.exists
20 @$(CPP) $$(CFLAGS) $$($1_CPPFLAGS) $2 -MM -MT "$$(@D)/$$*.d $$(@D)/$$*.o" -MF $$(@D)/$$*.d $$<
22 -include $$(wildcard $(_cobjs)/$1/*.d) /dev/null
25 ########################################################################}}}#
26 #[ Classes ]############################################################{{{#
28 deps_create = $(foreach f,$(AUTO_DEPENDS),$(call $f,$1,$2))
31 ## rules for *_PROGRAMS
35 $(if $($*dir),$(INSTALL_DIR) $(DESTDIR)$($*dir))
36 $(if $($*dir),$(INSTALL_PROGRAMS) $($*_PROGRAMS:=.so*) $(DESTDIR)$($*dir))
38 define CLASS_PROGRAMS_tpl
40 install-PROGRAMS/$2:: $1
41 install:: install-PROGRAMS/$2
43 $1: $$(call deps_create,$$($1_SOURCES),$(_cobjs)/$1)
44 $(CC) $$(CFLAGS) $$($1_CPPFLAGS) -o $$@ $$(filter %.o,$$^) \
45 $$(LDFLAGS) $$($1_LDFLAGS) $$($1_LIBADD)
47 $$(eval $$(call RULE_C_tpl,$1,))
52 $(foreach v,$(filter %_PROGRAMS,$(.VARIABLES)), \
53 $(foreach x,$($v),$(eval $(call CLASS_PROGRAMS_tpl,$x,$(v:_PROGRAMS=)))))
56 ## rules for *_LIBRARIES
60 $(if $($*dir),$(INSTALL_DIR) $(DESTDIR)$($*dir))
61 $(if $($*dir),$(INSTALL_DATA) $($*_LIBRARIES:=.so*) $(DESTDIR)$($*dir))
63 define CLASS_LIBRARIES_tpl
64 all:: $1.so$$(if $$($1_VERSION),.$$($1_VERSION))
65 install-LIBRARIES/$2:: $1.so$$(if $$($1_VERSION),.$$($1_VERSION))
67 install:: install-LIBRARIES/$2
69 $1.so$$(if $$($1_VERSION),.$$($1_VERSION)): $$(call deps_create,$$($1_SOURCES),$(_cobjs)/$1)
70 $(CC) $$(CFLAGS) $$($1_CPPFLAGS) -fPIC -shared -o $$@ $$(filter %.o,$$^) \
71 $$(LDFLAGS) $$($1_LDFLAGS) $$($1_LIBADD)
73 $$(eval $$(call RULE_C_tpl,$1,-fPIC))
78 $(foreach v,$(filter %_LIBRARIES,$(.VARIABLES)), \
79 $(foreach x,$($v),$(eval $(call CLASS_LIBRARIES_tpl,$x,$(v:_LIBRARIES=)))))
87 $(if $($*dir), $(INSTALL_DIR) $(DESTDIR)$($*dir))
88 $(if $($*dir), $(INSTALL_DATA) $($*_DATA) $(DESTDIR)$($*dir))
90 install:: $(foreach v,$(filter %_DATA,$(.VARIABLES)),$(patsubst %_DATA,install-DATA/%,$v))
93 ## rules for *_SCRIPTS
97 $(if $($*dir), $(INSTALL_DIR) $(DESTDIR)$($*dir))
98 $(if $($*dir), $(INSTALL_PROGRAMS) $($*_SCRIPTS) $(DESTDIR)$($*dir))
100 install:: $(foreach v,$(filter %_SCRIPTS,$(.VARIABLES)),$(patsubst %_SCRIPTS,install-SCRIPTS/%,$v))
103 ########################################################################}}}#
104 #[ Candy ]##############################################################{{{#
112 ifeq (".","$(DEPTH)")
114 ctags -o .$@ --recurse=yes --exclude=.svn --exclude=\*.mk --totals=yes;
120 $(MAKE) -C $(DEPTH) $@
125 ########################################################################}}}#
127 all check clobber distclean install::
128 @set -e $(patsubst %,; $(MAKE) -rC % $@,$(SUBDIRS))
132 $(RM) -r $(_cobjs) $(CLEANFILES)
133 @$(if $(CLEAN_RECURSE),$(patsubst %,$(MAKE) -rC % $@;,$(SUBDIRS)))
135 clobber distclean:: CLEAN_RECURSE=
136 clobber distclean:: clean
137 $(RM) -r .objs* $(DISTCLEANFILES)
139 ifeq (".","$(DEPTH)")
141 $(RM) $(patsubst %.in,%,$(wildcard $(CONFDIR)/*.in))
144 .PHONY: all check clean clobber distclean install FORCE