Use a proper rcode for no more rows
[freeradius.git] / Makefile
1 #
2 # Makefile
3 #
4 #               NOTE: This top-level Makefile must not
5 #               use GNU-make extensions. The lower ones can.
6 #
7 # Version:      $Id$
8 #
9
10 #
11 #  The default rule is "all".
12 #
13 all:
14
15 $(if $(wildcard Make.inc),,$(error Missing 'Make.inc' Run './configure [options]' and retry))
16
17 include Make.inc
18
19 MFLAGS += --no-print-directory
20
21 # The version of GNU Make is too old, don't use it (.FEATURES variable was
22 # wad added in 3.81)
23 ifndef .FEATURES
24 $(error The build system requires GNU Make 3.81 or later.)
25 endif
26
27 export DESTDIR := $(R)
28
29 # And over-ride all of the other magic.
30 include scripts/boiler.mk
31
32 #
33 #  To work around OpenSSL issues with travis.
34 #
35 .PHONY:
36 raddb/test.conf:
37         @echo 'security {' >> $@
38         @echo '        allow_vulnerable_openssl = yes' >> $@
39         @echo '}' >> $@
40         @echo '$$INCLUDE radiusd.conf' >> $@
41
42 #
43 #  Run "radiusd -C", looking for errors.
44 #
45 # Only redirect STDOUT, which should contain details of why the test failed.
46 # Don't molest STDERR as this may be used to receive output from a debugger.
47 $(BUILD_DIR)/tests/radiusd-c: raddb/test.conf ${BUILD_DIR}/bin/radiusd | build.raddb
48         @$(MAKE) -C raddb/certs
49         @printf "radiusd -C... "
50         @if ! FR_LIBRARY_PATH=./build/lib/local/.libs/ ./build/make/jlibtool --mode=execute ./build/bin/radiusd -XCMd ./raddb -D ./share -n test > $(BUILD_DIR)/tests/radiusd.config.log; then \
51                 rm -f raddb/test.conf; \
52                 cat $(BUILD_DIR)/tests/radiusd.config.log; \
53                 echo "fail"; \
54                 exit 1; \
55         fi
56         @rm -f raddb/test.conf
57         @echo "ok"
58         @touch $@
59
60 test: ${BUILD_DIR}/bin/radiusd ${BUILD_DIR}/bin/radclient tests.unit tests.xlat tests.keywords tests.auth tests.modules $(BUILD_DIR)/tests/radiusd-c | build.raddb
61         @$(MAKE) -C src/tests tests
62
63 #  Tests specifically for Travis.  We do a LOT more than just
64 #  the above tests
65 ifneq "$(findstring travis,${prefix})" ""
66 travis-test: raddb/test.conf test
67         @FR_LIBRARY_PATH=./build/lib/local/.libs/ ./build/make/jlibtool --mode=execute ./build/bin/radiusd -xxxv -n test
68         @rm -f raddb/test.conf
69         @$(MAKE) install
70         @perl -p -i -e 's/allow_vulnerable_openssl = no/allow_vulnerable_openssl = yes/' ${raddbdir}/radiusd.conf
71         @${sbindir}/radiusd -XC
72 endif
73
74 #
75 # The $(R) is a magic variable not defined anywhere in this source.
76 # It's purpose is to allow an admin to create an installation 'tar'
77 # file *without* actually installing it.  e.g.:
78 #
79 #  $ R=/home/root/tmp make install
80 #  $ cd /home/root/tmp
81 #  $ tar -cf ~/freeradius-package.tar *
82 #
83 # The 'tar' file can then be un-tar'd on any similar machine.  It's a
84 # cheap way of creating packages, without using a package manager.
85 # Many of the platform-specific packaging tools use the $(R) variable
86 # when creating their packages.
87 #
88 # For compatibility with typical GNU packages (e.g. as seen in libltdl),
89 # we make sure DESTDIR is defined.
90 #
91 export DESTDIR := $(R)
92
93 DICTIONARIES := $(wildcard share/dictionary*)
94 install.share: $(addprefix $(R)$(dictdir)/,$(notdir $(DICTIONARIES)))
95
96 $(R)$(dictdir)/%: share/%
97         @echo INSTALL $(notdir $<)
98         @$(INSTALL) -m 644 $< $@
99
100 MANFILES := $(wildcard man/man*/*.?)
101 install.man: $(subst man/,$(R)$(mandir)/,$(MANFILES))
102
103 $(R)$(mandir)/%: man/%
104         @echo INSTALL $(notdir $<)
105         @sed -e "s,/etc/raddb,$(raddbdir),g" \
106                 -e "s,/usr/local/share,$(datarootdir),g" \
107                 $< > $<.subst
108         @$(INSTALL) -m 644 $<.subst $@
109         @rm $<.subst
110
111 #
112 #  Don't install rlm_test
113 #
114 ALL_INSTALL := $(patsubst %rlm_test.la,,$(ALL_INSTALL))
115
116 install: install.share install.man
117         @$(INSTALL) -d -m 700   $(R)$(logdir)
118         @$(INSTALL) -d -m 700   $(R)$(radacctdir)
119
120 ifneq ($(RADMIN),)
121 ifneq ($(RGROUP),)
122 .PHONY: install-chown
123 install-chown:
124         chown -R $(RADMIN)   $(R)$(raddbdir)
125         chgrp -R $(RGROUP)   $(R)$(raddbdir)
126         chmod u=rwx,g=rx,o=  `find $(R)$(raddbdir) -type d -print`
127         chmod u=rw,g=r,o=    `find $(R)$(raddbdir) -type f -print`
128         chown -R $(RADMIN)   $(R)$(logdir)
129         chgrp -R $(RGROUP)   $(R)$(logdir)
130         find $(R)$(logdir) -type d -exec chmod u=rwx,g=rwx,o= {} \;
131         find $(R)$(logdir) -type d -exec chmod g+s {} \;
132         find $(R)$(logdir) -type f -exec chmod u=rw,g=rw,o= {} \;
133         chown -R $(RADMIN)   $(R)$(RUNDIR)
134         chgrp -R $(RGROUP)   $(R)$(RUNDIR)
135         find $(R)$(RUNDIR) -type d -exec chmod u=rwx,g=rwx,o= {} \;
136         find $(R)$(RUNDIR) -type d -exec chmod g+s {} \;
137         find $(R)$(RUNDIR) -type f -exec chmod u=rw,g=rw,o= {} \;
138 endif
139 endif
140
141 distclean: clean
142         @-find src/modules -regex .\*/config[.][^.]*\$$ -delete
143         @-find src/modules -name autom4te.cache -exec rm -rf '{}' \;
144         @rm -rf config.cache config.log config.status libtool \
145                 src/include/radpaths.h src/include/stamp-h \
146                 libltdl/config.log libltdl/config.status \
147                 libltdl/libtool autom4te.cache build
148         @-find . ! -name configure.ac -name \*.in -print | \
149                 sed 's/\.in$$//' | \
150                 while read file; do rm -f $$file; done
151
152 ######################################################################
153 #
154 #  Automatic remaking rules suggested by info:autoconf#Automatic_Remaking
155 #
156 ######################################################################
157 #
158 #  Do these checks ONLY if we're re-building the "configure"
159 #  scripts, and ONLY the "configure" scripts.  If we leave
160 #  these rules enabled by default, then they're run too often.
161 #
162 ifeq "$(MAKECMDGOALS)" "reconfig"
163
164 CONFIGURE_AC_FILES := $(shell find . -name configure.ac -print)
165 CONFIGURE_FILES    := $(patsubst %.ac,%,$(CONFIGURE_AC_FILES))
166
167 #
168 #  The GNU tools make autoconf=="missing autoconf", which then returns
169 #  0, even when autoconf doesn't exist.  This check is to ensure that
170 #  we run AUTOCONF only when it exists.
171 #
172 AUTOCONF_EXISTS := $(shell autoconf --version 2>/dev/null)
173
174 ifeq "$(AUTOCONF_EXISTS)" ""
175 $(error You need to install autoconf to re-build the "configure" scripts)
176 endif
177
178 # Configure files depend on "in" files, and on the top-level macro files
179 # If there are headers, run auto-header, too.
180 src/%configure: src/%configure.ac acinclude.m4 aclocal.m4 $(wildcard $(dir $@)m4/*m4) | src/freeradius-devel
181         @echo AUTOCONF $(dir $@)
182         cd $(dir $@) && $(AUTOCONF) -I $(top_builddir) -I $(top_builddir)/m4 -I $(top_builddir)/$(dir $@)m4
183         @if grep AC_CONFIG_HEADERS $@ >/dev/null; then\
184                 echo AUTOHEADER $@ \
185                 cd $(dir $@) && $(AUTOHEADER); \
186          fi
187
188 # "%configure" doesn't match "configure"
189 configure: configure.ac $(wildcard ac*.m4) $(wildcard m4/*.m4)
190         @echo AUTOCONF $@
191         @$(AUTOCONF)
192
193 src/include/autoconf.h.in: configure.ac
194         @echo AUTOHEADER $@
195         @$(AUTOHEADER)
196
197 reconfig: $(CONFIGURE_FILES) src/include/autoconf.h.in
198
199 config.status: configure
200         ./config.status --recheck
201
202 # target is "configure"
203 endif
204
205 #  If we've already run configure, then add rules which cause the
206 #  module-specific "all.mk" files to depend on the mk.in files, and on
207 #  the configure script.
208 #
209 ifneq "$(wildcard config.log)" ""
210 CONFIGURE_ARGS     := $(shell head -10 config.log | grep '^  \$$' | sed 's/^....//;s:.*configure ::')
211
212 src/%all.mk: src/%all.mk.in src/%configure
213         @echo CONFIGURE $(dir $@)
214         @rm -f ./config.cache $(dir $<)/config.cache
215         @cd $(dir $<) && ./configure $(CONFIGURE_ARGS)
216 endif
217
218 .PHONY: check-includes
219 check-includes:
220         scripts/min-includes.pl `find . -name "*.c" -print`
221
222 .PHONY: TAGS
223 TAGS:
224         etags `find src -type f -name '*.[ch]' -print` > $@
225
226 #
227 #  Make test certificates.
228 #
229 .PHONY: certs
230 certs:
231         @$(MAKE) -C raddb/certs
232
233 ######################################################################
234 #
235 #  Make a release.
236 #
237 #  Note that "Make.inc" has to be updated with the release number
238 #  BEFORE running this command!
239 #
240 ######################################################################
241 BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
242
243 freeradius-server-$(RADIUSD_VERSION_STRING).tar.gz: .git
244         git archive --format=tar --prefix=freeradius-server-$(RADIUSD_VERSION_STRING)/ $(BRANCH) | gzip > $@
245
246 freeradius-server-$(RADIUSD_VERSION_STRING).tar.bz2: .git
247         git archive --format=tar --prefix=freeradius-server-$(RADIUSD_VERSION_STRING)/ $(BRANCH) | bzip2 > $@
248
249 %.sig: %
250         gpg --default-key packages@freeradius.org -b $<
251
252 # high-level targets
253 .PHONY: dist-check
254 dist-check: redhat/freeradius.spec suse/freeradius.spec debian/changelog
255         @if [ `grep ^Version: redhat/freeradius.spec | sed 's/.*://;s/ //'` != "$(RADIUSD_VERSION_STRING)" ]; then \
256                 cat redhat/freeradius.spec | sed 's/^Version: .*/Version: $(RADIUSD_VERSION_STRING)/' > redhat/.foo; \
257                 mv redhat/.foo redhat/freeradius.spec; \
258                 echo redhat/freeradius.spec 'Version' needs to be updated; \
259                 exit 1; \
260         fi
261         @if [ `grep ^Version: suse/freeradius.spec | sed 's/.*://;s/ //'` != "$(RADIUSD_VERSION_STRING)" ]; then \
262                 cat suse/freeradius.spec | sed 's/^Version: .*/Version: $(RADIUSD_VERSION_STRING)/' > suse/.foo; \
263                 mv suse/.foo suse/freeradius.spec; \
264                 echo suse/freeradius.spec 'Version' needs to be updated; \
265                 exit 1; \
266         fi
267         @if [ `head -n 1 debian/changelog | sed 's/.*(//;s/-0).*//;s/-1).*//;s/\+.*//'`  != "$(RADIUSD_VERSION_STRING)" ]; then \
268                 echo debian/changelog needs to be updated; \
269                 exit 1; \
270         fi
271
272 dist: dist-check freeradius-server-$(RADIUSD_VERSION_STRING).tar.gz freeradius-server-$(RADIUSD_VERSION_STRING).tar.bz2
273
274 dist-sign: freeradius-server-$(RADIUSD_VERSION_STRING).tar.gz.sig freeradius-server-$(RADIUSD_VERSION_STRING).tar.bz2.sig
275
276 dist-publish: freeradius-server-$(RADIUSD_VERSION_STRING).tar.gz.sig freeradius-server-$(RADIUSD_VERSION_STRING).tar.gz freeradius-server-$(RADIUSD_VERSION_STRING).tar.gz.sig freeradius-server-$(RADIUSD_VERSION_STRING).tar.bz2 freeradius-server-$(RADIUSD_VERSION_STRING).tar.gz.sig freeradius-server-$(RADIUSD_VERSION_STRING).tar.bz2.sig
277         scp $^ freeradius.org@ftp.freeradius.org:public_ftp
278
279 #
280 #  Note that we do NOT do the tagging here!  We just print out what
281 #  to do!
282 #
283 dist-tag: freeradius-server-$(RADIUSD_VERSION_STRING).tar.gz freeradius-server-$(RADIUSD_VERSION_STRING).tar.bz2
284         @echo "git tag release_`echo $(RADIUSD_VERSION_STRING) | tr .- __`"
285
286 #
287 #       Build a debian package
288 #
289 .PHONY: deb
290 deb:
291         fakeroot dpkg-buildpackage -b -uc
292
293 # Developer checks
294 .PHONY: warnings
295 warnings:
296         @(make clean all 2>&1) | egrep -v '^/|deprecated|^In file included|: In function|   from |^HEADER|^CC|^LINK' > warnings.txt
297         @wc -l warnings.txt
298
299 #
300 #  Ensure we're using tabs in the configuration files,
301 #  and remove trailing whitespace in source files.
302 #
303 .PHONY: whitespace
304 whitespace:
305         @for x in $$(git ls-files raddb/ src/); do unexpand $$x > $$x.bak; cp $$x.bak $$x; rm -f $$x.bak;done
306         @perl -p -i -e 'trim' $$(git ls-files src/)