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