chiark / gitweb /
Makefile: Refactor the silent-rules machinery.
[preload-hacks] / Makefile
CommitLineData
bfa74564
MW
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###
de6df72d
MW
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.
bfa74564
MW
21###
22### You should have received a copy of the GNU General Public License along
de6df72d
MW
23### with preload-hacks; if not, write to the Free Software Foundation, Inc.,
24### 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
bfa74564
MW
25
26PACKAGE = preload-hacks
27VERSION := $(shell ./auto-version)
28
bc432a48
MW
29.SECONDEXPANSION: #sorry
30
bfa74564
MW
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
7a863a39
MW
46###--------------------------------------------------------------------------
47### Quiet building.
48
49## Verbosity.
3c098848
MW
50V ?= 0
51v_tag = $(call v_tag_$V,$1)
52v_tag_0 = @printf " %-8s %s\n" "$1" "$@";
53V_AT = $(V_AT_$V)
54V_AT_0 = @
7a863a39 55
bfa74564
MW
56###--------------------------------------------------------------------------
57### Build parameters.
58
59## Mess with these if you like.
60CC = gcc
61LD = gcc
62CFLAGS = -O2 -g -Wall
63LDFLAGS =
64LDLIBS = -ldl
65INSTALL = install
66INST_BIN = $(INSTALL) -c -m755
67INST_LIB = $(INSTALL) -c -m644
68INST_MAN = $(INSTALL) -c -m644
69INST_BIN = $(INSTALL) -c -m755
70MKDIRS = $(INSTALL) -d -m755
71
72## Probably best if you leave these alone.
da261a68 73REAL_CFLAGS = $(CFLAGS) -fPIC -MD
bfa74564
MW
74REAL_LDFLAGS = $(LDFLAGS) -shared
75
76###--------------------------------------------------------------------------
77### Main targets.
78
79## noip
80HACKS += noip
bc432a48 81noip_SOURCES = noip.c
bfa74564
MW
82
83## uopen
84HACKS += uopen
bc432a48
MW
85uopen_SOURCES = uopen.c
86
87## Sources.
88ALL_SOURCES = $(foreach h,$(HACKS),$($h_SOURCES))
89DISTFILES += $(ALL_SOURCES)
bfa74564
MW
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
c2ca886a 124DISTFILES += debian/control debian/rules debian/compat
fd87e398 125DISTFILES += debian/source/format
bfa74564
MW
126DISTFILES += $(patsubst %, debian/%.install, $(debpkg))
127DISTFILES += $(patsubst %, debian/%.lintian-overrides, \
128 $(debpkg))
129
130###--------------------------------------------------------------------------
131### Building.
132
6e66bf29 133all:: $(TARGETS)
bfa74564
MW
134.PHONY: ALL
135
c71a0b56 136CLEAN += $(TARGETS)
da261a68 137CLEAN += *.o *.d
6e66bf29 138clean::
c71a0b56 139 rm -f $(CLEAN)
bfa74564
MW
140.PHONY: clean
141
142## Building sources.
e4976bb0 143%.o: %.c
3c098848 144 $(call v_tag,CC)$(CC) -c $(REAL_CFLAGS) $< -o $@
bfa74564
MW
145
146## Constructing preload hacks.
bc432a48 147$(addsuffix .so,$(HACKS)): %.so: $$(patsubst %.c,%.o,$$($$*_SOURCES))
3c098848 148 $(call v_tag,LD)$(LD) $(REAL_LDFLAGS) $< $(LDLIBS) -o $@
bfa74564
MW
149
150## Constructing the scripts.
7a863a39 151$(SCRIPTS): %: withlib.in
3c098848 152 $(call v_tag,GEN)sed "s/@lib@/$@/" withlib.in >$@.new && \
7a863a39 153 chmod +x $@.new && mv $@.new $@
bfa74564 154
da261a68
MW
155-include $(patsubst %.c,%d,$(ALL_SOURCES))
156
bfa74564
MW
157###--------------------------------------------------------------------------
158### Installation.
159
2906706d 160install: all
bfa74564 161 $(MKDIRS) $(DESTDIR)$(bindir)
2906706d 162 $(INST_BIN) $(SCRIPTS) $(DESTDIR)$(bindir)
bfa74564
MW
163 $(MKDIRS) $(DESTDIR)$(libdir)
164 $(INST_BIN) $(LIBS) $(DESTDIR)$(libdir)
165 $(MKDIRS) $(DESTDIR)$(man1dir)
2906706d 166 $(INST_MAN) $(MAN1) $(DESTDIR)$(man1dir)
bfa74564
MW
167.PHONY: install
168
2906706d 169uninstall:
170 rm -f $(addprefix $(DESTDIR)$(libdir)/, $(LIBS))
171 rm -f $(addprefix $(DESTDIR)$(bindir)/, $(SCRIPTS))
172 rm -f $(addprefix $(DESTDIR)$(man1dir)/, $(MAN1))
bfa74564
MW
173.PHONY: uninstall
174
175###--------------------------------------------------------------------------
176### Distribution.
177
2906706d 178distdir:
bfa74564
MW
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
2906706d 192dist: distdir
bfa74564
MW
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 --------------------------------------------------