summaryrefslogtreecommitdiffstats
path: root/Makefile.rules.in
diff options
context:
space:
mode:
authorPatrick McHardy <kaber@trash.net>2009-05-06 18:41:57 +0200
committerPatrick McHardy <kaber@trash.net>2009-05-06 18:41:57 +0200
commit0406a88b39a9c978d47ababf9fd93d9e244e1a4a (patch)
tree89a082e027d10bb77c9f817cbdc1accb72424ec4 /Makefile.rules.in
Import libdect
Signed-off-by: Patrick McHardy <kaber@trash.net>
Diffstat (limited to 'Makefile.rules.in')
-rw-r--r--Makefile.rules.in108
1 files changed, 108 insertions, 0 deletions
diff --git a/Makefile.rules.in b/Makefile.rules.in
new file mode 100644
index 0000000..6165393
--- /dev/null
+++ b/Makefile.rules.in
@@ -0,0 +1,108 @@
+include Makefile.defs
+
+makedeps += $(SUBDIR)Makefile
+makedeps += Makefile
+makedeps += Makefile.defs
+makedeps += Makefile.rules
+
+configure: configure.ac
+ sh autogen.sh
+
+%: %.in configure
+ sh configure
+
+%.o: %.c $(makedeps)
+ @echo -e " CC\t\t$<"
+ $(CC) $(CFLAGS) -c -o $@ $<
+
+.%.d: %.c $(makedeps)
+ @echo -e " DEP\t\t$<"
+ $(RM) $@
+ $(CC) -M $(CFLAGS) $< | sed 's,$(*F)\.o[ :]*,$*.o $@ : ,g' > $@
+
+%.c %.h: %.y $(makedeps)
+ @echo -e " YACC\t\t$<"
+ $(YACC) $(YACCFLAGS) -d -o $@ $<
+
+%.c %.h: %.l $(makedeps)
+ @echo -e " LEX\t\t$<"
+ $(LEX) -t --header-file=$(<:.l=.h) $< > $@
+
+%.8: %.xml $(makedeps)
+ @echo -e " MAN\t\t$<"
+ docbook2x-man $<
+
+%.pdf: %.xml $(makedeps)
+ @echo -e " PDF\t\t$<"
+ db2pdf $<
+
+define generic_template
+$(1)-obj := $$(patsubst %,$(SUBDIR)%,$$($(1)-obj))
+depfiles := $$(patsubst $(SUBDIR)%.o,$(SUBDIR).%.d,$$($(1)-obj))
+
+.PHONY: $(1)-clean
+$(1)-clean:
+ @echo -e " CLEAN\t\t$(1)"
+ $$(RM) $$($(1)-obj) $$(depfiles) $$($(1)-extra-clean-files) $(1)
+clean_targets += $(1)-clean
+
+.PHONY: $(1)-install
+
+ifneq ($(MAKECMDGOALS),clean)
+-include $$(depfiles)
+endif
+endef
+
+define program_template
+$(eval $(call generic_template,$(1)))
+
+$(SUBDIR)$(1): $$($(1)-extra-targets) $$($(1)-obj)
+ @echo -e " LD\t\t$$@"
+ $$(CC) $$($(1)-obj) $$(LDFLAGS) -o $$@
+all_targets += $(SUBDIR)$(1)
+
+$(1)-install:
+ @echo -e " INSTALL\t$1"
+ $(MKDIR_P) $$(DESTDIR)/$$($(1)-destdir)
+ $(INSTALL) -m 755 -o root -g root $(SUBDIR)$(1) \
+ $$(DESTDIR)/$$($(1)-destdir)/$(1)
+install_targets += $(1)-install
+endef
+
+define library_template
+$(eval $(call generic_template,$(1)))
+
+$(SUBDIR)lib$(1).so: $$($(1)-extra-targets) $$($(1)-obj)
+ @echo -e " LD\t\t$$@"
+ $$(CC) -shared -Wl,-soname,lib$(1).so.0 $$($(1)-obj) $$(LDFLAGS) -o $$@
+all_targets += $(SUBDIR)lib$(1).so
+
+$(1)-install:
+ @echo -e " INSTALL\t$1"
+ $(MKDIR_P) $$(DESTDIR)/$$($(1)-destdir)
+ $(INSTALL) -m 755 -o root -g root $(SUBDIR)lib$(1).so \
+ $$(DESTDIR)/$$($(1)-destdir)/lib$(1).so.$(PACKAGE_VERSION)
+ $(LN_S) -f lib$(1).so.$(PACKAGE_VERSION) \
+ $(DESTDIR)/$$($(1)-destdir)/lib$(1).so.0
+ $(LN_S) -f lib$(1).so.$(PACKAGE_VERSION) \
+ $(DESTDIR)/$$($(1)-destdir)/lib$(1).so
+install_targets += $(1)-install
+endef
+
+ifneq ($(SUBDIR),)
+include $(SUBDIR)/Makefile
+$(foreach prog,$(PROGRAMS),$(eval $(call program_template,$(prog))))
+$(foreach lib,$(LIBS),$(eval $(call library_template,$(lib))))
+endif
+
+.DEFAULT_GOAL := all
+
+.PHONY: all clean install
+all: $(SUBDIRS) $(all_targets)
+clean: $(SUBDIRS) $(clean_targets)
+install: all $(SUBDIRS) $(install_targets)
+
+.PHONY: $(SUBDIRS)
+$(SUBDIRS):
+ @echo -e " SUBDIR\t$@/"
+ @$(MAKE) -s -f Makefile.rules $(MAKECMDGOALS) SUBDIR="$@/"