summaryrefslogtreecommitdiffstats
path: root/Makefile.rules.in
blob: 6a0091611b08261ee508bb8b7bca6a701c803429 (plain)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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) --defines=$*.h.tmp -o $@ $<
			( \
				echo "#ifndef __$(*F)_H"; \
				echo "#define __$(*F)_H"; \
				cat $*.h.tmp; \
				echo "#endif /* __$(*F)_H */" \
			) > $*.h
			$(RM) $*.h.tmp

%.c %.h:		%.l	$(makedeps)
			@echo -e "  LEX\t\t$<"
			$(LEX) -t --header-file=$(<:.l=.h) $< > $@

%.8:			%.xml	$(makedeps)
			@echo -e "  MAN\t\t$@"
			(cd $(SUBDIR); $(DB2MAN) --xinclude ../$<)

%.pdf:			%.xml	$(makedeps)
			@echo -e "  PDF\t\t$@"
			dblatex -q -t pdf -o $@ $<

archive:
			git archive --prefix=nftables-@PACKAGE_VERSION@/ HEAD | \
				bzip2 -c > nftables-@PACKAGE_VERSION@.tar.bz2

define program_template
$(1)-obj		:= $$(patsubst %,$(SUBDIR)%,$$($(1)-obj))
$(1)-extra-clean-files	:= $$(patsubst %,$(SUBDIR)%,$$($(1)-extra-clean-files))

depfiles		:= $$(patsubst $(SUBDIR)%.o,$(SUBDIR).%.d,$$($(1)-obj))

$(SUBDIR)$(1):		$$($(1)-extra-targets) $$($(1)-obj)
			@echo -e "  LD\t\t$$@"
			$$(CC) $$($(1)-obj) $$(LDFLAGS) -o $$@
all_targets		+= $(SUBDIR)$(1)

.PHONY:			$(1)-clean
$(1)-clean:
			@echo -e "  CLEAN\t\t$(1)"
			$$(RM) $$($(1)-obj) $$(depfiles) $$($(1)-extra-clean-files) $(SUBDIR)$(1)
clean_targets		+= $(1)-clean

.PHONY:			$(1)-install
$(1)-install:
			@echo -e "  INSTALL\t$1"
			$(MKDIR_P) $$(DESTDIR)/$$($(1)-destdir)
			$(INSTALL) -m 755 -p \
				$(SUBDIR)$(1) \
				$$(DESTDIR)/$$($(1)-destdir)/$(1)
install_targets		+= $(1)-install

ifneq ($(MAKECMDGOALS),clean)
-include $$(depfiles)
endif
endef

ifneq ($(SUBDIR),)
include $(SUBDIR)/Makefile
$(foreach prog,$(PROGRAMS),$(eval $(call program_template,$(prog))))
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="$@/" SUBDIRS=""