Makefile: Sink the silent-rules machinery.
[preload-hacks] / Makefile
... / ...
CommitLineData
1### -*-makefile-*-
2###
3### Makefile for preload-hacks
4###
5### (c) 2008 Straylight/Edgeware
6###
7
8###----- Licensing notice ---------------------------------------------------
9###
10### This file is part of the preload-hacks package.
11###
12### Preload-hacks are free software; you can redistribute it and/or modify
13### them under the terms of the GNU General Public License as published by
14### the Free Software Foundation; either version 2 of the License, or (at
15### your option) any later version.
16###
17### Preload-hacks are distributed in the hope that it will be useful, but
18### WITHOUT ANY WARRANTY; without even the implied warranty of
19### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
20### Public License for more details.
21###
22### You should have received a copy of the GNU General Public License along
23### with preload-hacks; if not, write to the Free Software Foundation, Inc.,
24### 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
26PACKAGE = preload-hacks
27VERSION := $(shell ./auto-version)
28
29.SECONDEXPANSION: #sorry
30
31###--------------------------------------------------------------------------
32### Configuration.
33
34## Where to install things.
35prefix = /usr/local
36exec_prefix = ${prefix}
37bindir = ${exec_prefix}/bin
38libdir = ${exec_prefix}/lib
39datadir = ${prefix}/share
40mandir = ${datadir}/man
41man1dir = ${mandir}/man1
42
43## Private installation tree for packagers.
44DESTDIR =
45
46###--------------------------------------------------------------------------
47### Build parameters.
48
49## Mess with these if you like.
50CC = gcc
51LD = gcc
52CFLAGS = -O2 -g -Wall
53LDFLAGS =
54LDLIBS = -ldl
55INSTALL = install
56INST_BIN = $(INSTALL) -c -m755
57INST_LIB = $(INSTALL) -c -m644
58INST_MAN = $(INSTALL) -c -m644
59INST_BIN = $(INSTALL) -c -m755
60MKDIRS = $(INSTALL) -d -m755
61
62## Probably best if you leave these alone.
63REAL_CFLAGS = $(CFLAGS) -fPIC -MD
64REAL_LDFLAGS = $(LDFLAGS) -shared
65
66###--------------------------------------------------------------------------
67### Quiet building.
68
69## Verbosity.
70V = 0
71v_tag = $(call v_tag_$V,$1)
72v_tag_0 = @printf " %-8s %s\n" "$1" "$@";
73V_AT = $(V_AT_$V)
74V_AT_0 = @
75
76###--------------------------------------------------------------------------
77### Main targets.
78
79## noip
80HACKS += noip
81noip_SOURCES = noip.c
82
83## uopen
84HACKS += uopen
85uopen_SOURCES = uopen.c
86
87## Sources.
88ALL_SOURCES = $(foreach h,$(HACKS),$($h_SOURCES))
89DISTFILES += $(ALL_SOURCES)
90
91## Libraries.
92LIBS += $(addsuffix .so, $(HACKS))
93TARGETS += $(LIBS)
94
95## Scripts.
96SCRIPTS = $(HACKS)
97TARGETS += $(SCRIPTS)
98DISTFILES += withlib.in
99
100## Manual pages.
101MAN1 += $(addsuffix .1, $(HACKS))
102DISTFILES += $(MAN1)
103
104###--------------------------------------------------------------------------
105### Distribution arrangements.
106
107## Names.
108distdir = $(PACKAGE)-$(VERSION)
109DISTTAR = $(distdir).tar.gz
110
111## Distribute the build utilities.
112DISTFILES += Makefile
113DISTFILES += auto-version
114
115## Documentation.
116DISTFILES += README
117
118## Licensing.
119DISTFILES += COPYING
120
121## Debian.
122debpkg = noip uopen
123DISTFILES += debian/changelog debian/copyright
124DISTFILES += debian/control debian/rules debian/compat
125DISTFILES += debian/source/format
126DISTFILES += $(patsubst %, debian/%.install, $(debpkg))
127DISTFILES += $(patsubst %, debian/%.lintian-overrides, \
128 $(debpkg))
129
130###--------------------------------------------------------------------------
131### Building.
132
133all:: $(TARGETS)
134.PHONY: ALL
135
136CLEAN += $(TARGETS)
137CLEAN += *.o *.d
138clean::
139 rm -f $(CLEAN)
140.PHONY: clean
141
142## Building sources.
143%.o: %.c
144 $(call v_tag,CC)$(CC) -c $(REAL_CFLAGS) $< -o $@
145
146## Constructing preload hacks.
147$(addsuffix .so,$(HACKS)): %.so: $$(patsubst %.c,%.o,$$($$*_SOURCES))
148 $(call v_tag,LD)$(LD) $(REAL_LDFLAGS) $< $(LDLIBS) -o $@
149
150## Constructing the scripts.
151$(SCRIPTS): %: withlib.in
152 $(call v_tag,GEN)sed "s/@lib@/$@/" withlib.in >$@.new && \
153 chmod +x $@.new && mv $@.new $@
154
155-include $(patsubst %.c,%d,$(ALL_SOURCES))
156
157###--------------------------------------------------------------------------
158### Installation.
159
160install: all
161 $(MKDIRS) $(DESTDIR)$(bindir)
162 $(INST_BIN) $(SCRIPTS) $(DESTDIR)$(bindir)
163 $(MKDIRS) $(DESTDIR)$(libdir)
164 $(INST_BIN) $(LIBS) $(DESTDIR)$(libdir)
165 $(MKDIRS) $(DESTDIR)$(man1dir)
166 $(INST_MAN) $(MAN1) $(DESTDIR)$(man1dir)
167.PHONY: install
168
169uninstall:
170 rm -f $(addprefix $(DESTDIR)$(libdir)/, $(LIBS))
171 rm -f $(addprefix $(DESTDIR)$(bindir)/, $(SCRIPTS))
172 rm -f $(addprefix $(DESTDIR)$(man1dir)/, $(MAN1))
173.PHONY: uninstall
174
175###--------------------------------------------------------------------------
176### Distribution.
177
178distdir:
179 rm -rf $(distdir)
180 mkdir $(distdir)
181 echo $(VERSION) >$(distdir)/RELEASE
182 for i in $(DISTFILES); do \
183 case "$$i" in \
184 */*) \
185 d=$${i%/*} && $(MKDIRS) $(distdir)/$$d || exit 1 \
186 ;; \
187 esac; \
188 ln $$i $(distdir)/$$i || exit 1; \
189 done
190.PHONY: distdir
191
192dist: distdir
193 tar chozf $(DISTTAR) $(distdir)
194 rm -rf $(distdir)
195.PHONY: dist
196
197distcheck: dist
198 rm -rf _distcheck
199 mkdir _distcheck
200 cd _distcheck && \
201 tar xvfz ../$(DISTTAR) && \
202 cd $(distdir) && \
203 make && \
204 make install DESTDIR=../_install && \
205 make dist
206 rm -rf _distcheck
207
208###----- That's all, folks --------------------------------------------------