chiark / gitweb /
noip.c (encode_single_inet_addr): Make the logic less weird.
[preload-hacks] / Make.rules
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 srcdir                  ?= .
27 PACKAGE                  = preload-hacks
28 VERSION                 := $(shell cd $(srcdir) && ./auto-version)
29
30 VPATH                    = $(srcdir)
31 .SECONDEXPANSION: #sorry
32
33 ###--------------------------------------------------------------------------
34 ### Configuration.
35
36 ## Where to install things.
37 prefix                   = /usr/local
38 exec_prefix              = ${prefix}
39 bindir                   = ${exec_prefix}/bin
40 libdir                   = ${exec_prefix}/lib
41 datadir                  = ${prefix}/share
42 mandir                   = ${datadir}/man
43 man1dir                  = ${mandir}/man1
44
45 ## Private installation tree for packagers.
46 DESTDIR                  =
47
48 ###--------------------------------------------------------------------------
49 ### Build parameters.
50
51 ## Mess with these if you like.
52 CC                       = gcc
53 LD                       = gcc
54 CFLAGS                   = -O2 -g -Wall
55 LDFLAGS                  =
56 LDLIBS                   = -ldl
57 INSTALL                  = install
58 INST_BIN                 = $(INSTALL) -c -m755
59 INST_LIB                 = $(INSTALL) -c -m644
60 INST_MAN                 = $(INSTALL) -c -m644
61 INST_BIN                 = $(INSTALL) -c -m755
62 MKDIRS                   = $(INSTALL) -d -m755
63
64 ## Probably best if you leave these alone.
65 REAL_CFLAGS              = $(CFLAGS) -fPIC -MD
66 REAL_LDFLAGS             = $(LDFLAGS) -shared
67
68 ## Allow user overrides for this stuff.
69 -include config.mk
70
71 ###--------------------------------------------------------------------------
72 ### Quiet building.
73
74 ## Verbosity.
75 V                        = 0
76 v_tag                    = $(call v_tag_$V,$1)
77 v_tag_0                  = @printf "  %-8s %s\n" "$1" "$@";
78 V_AT                     = $(V_AT_$V)
79 V_AT_0                   = @
80
81 ###--------------------------------------------------------------------------
82 ### Main targets.
83
84 ## noip
85 HACKS                   += noip
86 noip_SOURCES             = noip.c
87
88 ## uopen
89 HACKS                   += uopen
90 uopen_SOURCES            = uopen.c
91
92 ## Sources.
93 ALL_SOURCES              = $(foreach h,$(HACKS),$($h_SOURCES))
94 DISTFILES               += $(ALL_SOURCES)
95
96 ## Libraries.
97 LIBS                    += $(addsuffix .so, $(HACKS))
98 TARGETS                 += $(LIBS)
99
100 ## Scripts.
101 SCRIPTS                  = $(HACKS)
102 TARGETS                 += $(SCRIPTS)
103 DISTFILES               += withlib.in
104
105 ## Manual pages.
106 MAN1                    += $(addsuffix .1, $(HACKS))
107 DISTFILES               += $(MAN1)
108
109 ###--------------------------------------------------------------------------
110 ### Distribution arrangements.
111
112 ## Names.
113 distdir                  = $(PACKAGE)-$(VERSION)
114 DISTTAR                  = $(distdir).tar.gz
115
116 ## Distribute the build utilities.
117 DISTFILES               += Make.rules
118 DISTFILES               += configure
119 DISTFILES               += auto-version
120
121 ## Documentation.
122 DISTFILES               += README
123
124 ## Licensing.
125 DISTFILES               += COPYING
126
127 ## Debian.
128 debpkg                   = noip uopen
129 DISTFILES               += debian/changelog debian/copyright
130 DISTFILES               += debian/control debian/rules debian/compat
131 DISTFILES               += debian/source/format
132 DISTFILES               += $(patsubst %, debian/%.install, $(debpkg))
133 DISTFILES               += $(patsubst %, debian/%.lintian-overrides, \
134                                 $(debpkg))
135
136 ###--------------------------------------------------------------------------
137 ### Building.
138
139 all:: $(TARGETS)
140 .PHONY: ALL
141
142 CLEAN                   += $(TARGETS)
143 CLEAN                   += *.o *.d
144 clean::
145         rm -f $(CLEAN)
146 .PHONY: clean
147
148 ## Building sources.
149 %.o: %.c
150         $(call v_tag,CC)$(CC) -c $(REAL_CFLAGS) $< -o $@
151
152 ## Constructing preload hacks.
153 $(addsuffix .so,$(HACKS)): %.so: $$(patsubst %.c,%.o,$$($$*_SOURCES))
154         $(call v_tag,LD)$(LD) $(REAL_LDFLAGS) $< $(LDLIBS) -o $@
155
156 ## Constructing the scripts.
157 $(SCRIPTS): %: withlib.in
158         $(call v_tag,GEN)sed "s/@lib@/$@/" $(srcdir)/withlib.in >$@.new && \
159                 chmod +x $@.new && mv $@.new $@
160
161 -include $(patsubst %.c,%d,$(ALL_SOURCES))
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) $(addprefix $(srcdir)/,$(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           cp $(srcdir)/$$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         mkdir _build && cd _build && \
209         ../$(distdir)/configure && \
210         make && \
211         make install DESTDIR=../_install && \
212         make dist
213         rm -rf _distcheck
214
215 ###----- That's all, folks --------------------------------------------------