chiark / gitweb /
Makefile (clean): Have a variable for things to clean.
[preload-hacks] / Makefile
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
26 PACKAGE                  = preload-hacks
27 VERSION                 := $(shell ./auto-version)
28
29 .SECONDEXPANSION: #sorry
30
31 ###--------------------------------------------------------------------------
32 ### Configuration.
33
34 ## Where to install things.
35 prefix                   = /usr/local
36 exec_prefix              = ${prefix}
37 bindir                   = ${exec_prefix}/bin
38 libdir                   = ${exec_prefix}/lib
39 datadir                  = ${prefix}/share
40 mandir                   = ${datadir}/man
41 man1dir                  = ${mandir}/man1
42
43 ## Private installation tree for packagers.
44 DESTDIR                  =
45
46 ###--------------------------------------------------------------------------
47 ### Quiet building.
48
49 ## Verbosity.
50 V                        = 0
51
52 ## Compilation.
53 V_CC                     = $(V_CC_$(V))$(CC)
54 V_CC_0                   = @echo "  CC     $@";
55
56 ## Linking.
57 V_LD                     = $(V_LD_$(V))$(LD)
58 V_LD_0                   = @echo "  LD     $@";
59
60 ## Generation.
61 V_GEN                    = $(V_GEN_$(V))
62 V_GEN_0                  = @echo "  GEN    $@";
63
64 ###--------------------------------------------------------------------------
65 ### Build parameters.
66
67 ## Mess with these if you like.
68 CC                       = gcc
69 LD                       = gcc
70 CFLAGS                   = -O2 -g -Wall
71 LDFLAGS                  =
72 LDLIBS                   = -ldl
73 INSTALL                  = install
74 INST_BIN                 = $(INSTALL) -c -m755
75 INST_LIB                 = $(INSTALL) -c -m644
76 INST_MAN                 = $(INSTALL) -c -m644
77 INST_BIN                 = $(INSTALL) -c -m755
78 MKDIRS                   = $(INSTALL) -d -m755
79
80 ## Probably best if you leave these alone.
81 REAL_CFLAGS              = $(CFLAGS) -fPIC
82 REAL_LDFLAGS             = $(LDFLAGS) -shared
83
84 ###--------------------------------------------------------------------------
85 ### Main targets.
86
87 ## noip
88 HACKS                   += noip
89 noip_SOURCES             = noip.c
90
91 ## uopen
92 HACKS                   += uopen
93 uopen_SOURCES            = uopen.c
94
95 ## Sources.
96 ALL_SOURCES              = $(foreach h,$(HACKS),$($h_SOURCES))
97 DISTFILES               += $(ALL_SOURCES)
98
99 ## Libraries.
100 LIBS                    += $(addsuffix .so, $(HACKS))
101 TARGETS                 += $(LIBS)
102
103 ## Scripts.
104 SCRIPTS                  = $(HACKS)
105 TARGETS                 += $(SCRIPTS)
106 DISTFILES               += withlib.in
107
108 ## Manual pages.
109 MAN1                    += $(addsuffix .1, $(HACKS))
110 DISTFILES               += $(MAN1)
111
112 ###--------------------------------------------------------------------------
113 ### Distribution arrangements.
114
115 ## Names.
116 distdir                  = $(PACKAGE)-$(VERSION)
117 DISTTAR                  = $(distdir).tar.gz
118
119 ## Distribute the build utilities.
120 DISTFILES               += Makefile
121 DISTFILES               += auto-version
122
123 ## Documentation.
124 DISTFILES               += README
125
126 ## Licensing.
127 DISTFILES               += COPYING
128
129 ## Debian.
130 debpkg                   = noip uopen
131 DISTFILES               += debian/changelog debian/copyright
132 DISTFILES               += debian/control debian/rules debian/compat
133 DISTFILES               += debian/source/format
134 DISTFILES               += $(patsubst %, debian/%.install, $(debpkg))
135 DISTFILES               += $(patsubst %, debian/%.lintian-overrides, \
136                                 $(debpkg))
137
138 ###--------------------------------------------------------------------------
139 ### Building.
140
141 all: $(TARGETS)
142 .PHONY: ALL
143
144 CLEAN                   += $(TARGETS)
145 CLEAN                   += *.o
146 clean:
147         rm -f $(CLEAN)
148 .PHONY: clean
149
150 ## Building sources.
151 %.o: %.c
152         $(V_CC) -c $(REAL_CFLAGS) $< -o $@
153
154 ## Constructing preload hacks.
155 $(addsuffix .so,$(HACKS)): %.so: $$(patsubst %.c,%.o,$$($$*_SOURCES))
156         $(V_LD) $(REAL_LDFLAGS) $< $(LDLIBS) -o $@
157
158 ## Constructing the scripts.
159 $(SCRIPTS): %: withlib.in
160         $(V_GEN)sed "s/@lib@/$@/" withlib.in >$@.new && \
161                 chmod +x $@.new && mv $@.new $@
162
163 ###--------------------------------------------------------------------------
164 ### Installation.
165
166 install: all
167         $(MKDIRS) $(DESTDIR)$(bindir)
168         $(INST_BIN) $(SCRIPTS) $(DESTDIR)$(bindir)
169         $(MKDIRS) $(DESTDIR)$(libdir)
170         $(INST_BIN) $(LIBS) $(DESTDIR)$(libdir)
171         $(MKDIRS) $(DESTDIR)$(man1dir)
172         $(INST_MAN) $(MAN1) $(DESTDIR)$(man1dir)
173 .PHONY: install
174
175 uninstall:
176         rm -f $(addprefix $(DESTDIR)$(libdir)/, $(LIBS))
177         rm -f $(addprefix $(DESTDIR)$(bindir)/, $(SCRIPTS))
178         rm -f $(addprefix $(DESTDIR)$(man1dir)/, $(MAN1))
179 .PHONY: uninstall
180
181 ###--------------------------------------------------------------------------
182 ### Distribution.
183
184 distdir:
185         rm -rf $(distdir)
186         mkdir $(distdir)
187         echo $(VERSION) >$(distdir)/RELEASE
188         for i in $(DISTFILES); do \
189           case "$$i" in \
190             */*) \
191               d=$${i%/*} && $(MKDIRS) $(distdir)/$$d || exit 1 \
192               ;; \
193           esac; \
194           ln $$i $(distdir)/$$i || exit 1; \
195         done
196 .PHONY: distdir
197
198 dist: distdir
199         tar chozf $(DISTTAR) $(distdir)
200         rm -rf $(distdir)
201 .PHONY: dist
202
203 distcheck: dist
204         rm -rf _distcheck
205         mkdir _distcheck
206         cd _distcheck && \
207         tar xvfz ../$(DISTTAR) && \
208         cd $(distdir) && \
209         make && \
210         make install DESTDIR=../_install && \
211         make dist
212         rm -rf _distcheck
213
214 ###----- That's all, folks --------------------------------------------------