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