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_LDADD)
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
65 install-LIBRARIES/$2:: $1.so$3
67 install:: install-LIBRARIES/$2
69 $1.so$3: $$(call deps_create,$$($1_SOURCES),$(_cobjs)/$1)
70 $(CC) $$(CFLAGS) $$($1_CPPFLAGS) -fPIC -shared -o $$@ $$(filter %.o,$$^) \
71 $$(LDFLAGS) $$($1_LDFLAGS) $$($1_LDADD)
72 $$(if $$(word 2,$$(subst ., ,$3)),ln -sf $$@ $1.so.$$(word 1,$$(subst ., ,$3)))
73 $$(if $$($1_VERSION), ln -sf $$@ $1.so)
75 $$(eval $$(call RULE_C_tpl,$1,-fPIC))
80 $(foreach v,$(filter %_LIBRARIES,$(.VARIABLES)), \
81 $(foreach x,$($v),$(eval $(call CLASS_LIBRARIES_tpl,$x,$(v:_LIBRARIES=),$(...\
82 ...)$(if $($x_VERSION),.$($x_VERSION))))))
90 $(if $($*dir), $(INSTALL_DIR) $(DESTDIR)$($*dir))
91 $(if $($*dir), $(INSTALL_DATA) $($*_DATA) $(DESTDIR)$($*dir))
93 install:: $(foreach v,$(filter %_DATA,$(.VARIABLES)),$(patsubst %_DATA,install-DATA/%,$v))
96 ## rules for *_SCRIPTS
100 $(if $($*dir), $(INSTALL_DIR) $(DESTDIR)$($*dir))
101 $(if $($*dir), $(INSTALL_PROGRAMS) $($*_SCRIPTS) $(DESTDIR)$($*dir))
103 install:: $(foreach v,$(filter %_SCRIPTS,$(.VARIABLES)),$(patsubst %_SCRIPTS,install-SCRIPTS/%,$v))
106 ## rules for *_HEADERS
110 $(if $($*dir), $(INSTALL_DIR) $(DESTDIR)$($*dir))
111 $(if $($*dir), $(INSTALL_DATA) $($*_HEADERS) $(DESTDIR)$($*dir))
113 install:: $(foreach v,$(filter %_HEADERS,$(.VARIABLES)),$(patsubst %_HEADERS,install-HEADERS/%,$v))
116 ########################################################################}}}#
117 #[ Candy ]##############################################################{{{#
125 ifeq (".","$(DEPTH)")
127 ctags -o .$@ --recurse=yes --exclude=.svn --exclude=\*.mk --totals=yes;
133 $(MAKE) -C $(DEPTH) $@
138 ########################################################################}}}#
140 all check clobber distclean install::
141 @$(if $(SUBDIRS),set -e $(patsubst %,; $(MAKE) -rC % $@,$(SUBDIRS)))
145 $(RM) -r $(_cobjs) $(CLEANFILES)
146 @$(if $(CLEAN_RECURSE),$(patsubst %,$(MAKE) -rC % $@;,$(SUBDIRS)))
148 clobber distclean:: CLEAN_RECURSE=
149 clobber distclean:: clean
150 $(RM) -r .objs* $(DISTCLEANFILES)
151 @[ -f Makefile.in ] && $(RM) Makefile
153 ifeq (".","$(DEPTH)")
155 $(RM) $(patsubst %.in,%,$(wildcard $(CONFDIR)/*.in))
158 .PHONY: all check clean clobber distclean install FORCE