summaryrefslogtreecommitdiffstats
path: root/Makefile.rules.in
blob: c626f225414f87225a293aac20b23b0f243bde63 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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))
$(1)-depfiles		:= $$(patsubst $(SUBDIR)%.o,$(SUBDIR).%.d,$$($(1)-obj))

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

.PHONY:			$(1)-install

ifneq ($(MAKECMDGOALS),clean)
-include $$($(1)-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) $$($(1)-ldflags) $$(LDFLAGS) -o $$@
all_targets		+= $(SUBDIR)$(1)

$(1)-clean_files	+= $(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 $$@
			$(LN_S) -f lib$(1).so $$@.0
all_targets		+= $(SUBDIR)lib$(1).so

$(1)-clean_files	+= $(SUBDIR)lib$(1).so $(SUBDIR)lib$(1).so.0

$(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="$@/" SUBDIRS=""