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