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