formatting
[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 ! 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 \
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         @FR_LIBRARY_PATH=./build/lib/local/.libs/ ./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         @sed -e "s,/etc/raddb,$(raddbdir),g" \
118                 -e "s,/usr/local/share,$(datarootdir),g" \
119                 $< > $<.subst
120         @$(INSTALL) -m 644 $<.subst $@
121         @rm $<.subst
122
123 #
124 #  Don't install rlm_test
125 #
126 ALL_INSTALL := $(patsubst %rlm_test.la,,$(ALL_INSTALL))
127
128 install: install.dirs install.share install.man
129
130 ifneq ($(RADMIN),)
131 ifneq ($(RGROUP),)
132 .PHONY: install-chown
133 install-chown:
134         chown -R $(RADMIN)   $(R)$(raddbdir)
135         chgrp -R $(RGROUP)   $(R)$(raddbdir)
136         chmod u=rwx,g=rx,o=  `find $(R)$(raddbdir) -type d -print`
137         chmod u=rw,g=r,o=    `find $(R)$(raddbdir) -type f -print`
138         chown -R $(RADMIN)   $(R)$(logdir)
139         chgrp -R $(RGROUP)   $(R)$(logdir)
140         find $(R)$(logdir) -type d -exec chmod u=rwx,g=rwx,o= {} \;
141         find $(R)$(logdir) -type d -exec chmod g+s {} \;
142         find $(R)$(logdir) -type f -exec chmod u=rw,g=rw,o= {} \;
143         chown -R $(RADMIN)   $(R)$(RUNDIR)
144         chgrp -R $(RGROUP)   $(R)$(RUNDIR)
145         find $(R)$(RUNDIR) -type d -exec chmod u=rwx,g=rwx,o= {} \;
146         find $(R)$(RUNDIR) -type d -exec chmod g+s {} \;
147         find $(R)$(RUNDIR) -type f -exec chmod u=rw,g=rw,o= {} \;
148 endif
149 endif
150
151 distclean: clean
152         @-find src/modules -regex .\*/config[.][^.]*\$$ -delete
153         @-find src/modules -name autom4te.cache -exec rm -rf '{}' \;
154         @rm -rf config.cache config.log config.status libtool \
155                 src/include/radpaths.h src/include/stamp-h \
156                 libltdl/config.log libltdl/config.status \
157                 libltdl/libtool autom4te.cache build
158         @-find . ! -name configure.ac -name \*.in -print | \
159                 sed 's/\.in$$//' | \
160                 while read file; do rm -f $$file; done
161
162 ######################################################################
163 #
164 #  Automatic remaking rules suggested by info:autoconf#Automatic_Remaking
165 #
166 ######################################################################
167 #
168 #  Do these checks ONLY if we're re-building the "configure"
169 #  scripts, and ONLY the "configure" scripts.  If we leave
170 #  these rules enabled by default, then they're run too often.
171 #
172 ifeq "$(MAKECMDGOALS)" "reconfig"
173
174 CONFIGURE_AC_FILES := $(shell find . -name configure.ac -print)
175 CONFIGURE_FILES    := $(patsubst %.ac,%,$(CONFIGURE_AC_FILES))
176
177 #
178 #  The GNU tools make autoconf=="missing autoconf", which then returns
179 #  0, even when autoconf doesn't exist.  This check is to ensure that
180 #  we run AUTOCONF only when it exists.
181 #
182 AUTOCONF_EXISTS := $(shell autoconf --version 2>/dev/null)
183
184 ifeq "$(AUTOCONF_EXISTS)" ""
185 $(error You need to install autoconf to re-build the "configure" scripts)
186 endif
187
188 # Configure files depend on "in" files, and on the top-level macro files
189 # If there are headers, run auto-header, too.
190 src/%configure: src/%configure.ac acinclude.m4 aclocal.m4 $(wildcard $(dir $@)m4/*m4) | src/freeradius-devel
191         @echo AUTOCONF $(dir $@)
192         cd $(dir $@) && $(AUTOCONF) -I $(top_builddir) -I $(top_builddir)/m4 -I $(top_builddir)/$(dir $@)m4
193         @if grep AC_CONFIG_HEADERS $@ >/dev/null; then\
194                 echo AUTOHEADER $@ \
195                 cd $(dir $@) && $(AUTOHEADER); \
196          fi
197
198 # "%configure" doesn't match "configure"
199 configure: configure.ac $(wildcard ac*.m4) $(wildcard m4/*.m4)
200         @echo AUTOCONF $@
201         @$(AUTOCONF)
202
203 src/include/autoconf.h.in: configure.ac
204         @echo AUTOHEADER $@
205         @$(AUTOHEADER)
206
207 reconfig: $(CONFIGURE_FILES) src/include/autoconf.h.in
208
209 config.status: configure
210         ./config.status --recheck
211
212 # target is "configure"
213 endif
214
215 #  If we've already run configure, then add rules which cause the
216 #  module-specific "all.mk" files to depend on the mk.in files, and on
217 #  the configure script.
218 #
219 ifneq "$(wildcard config.log)" ""
220 CONFIGURE_ARGS     := $(shell head -10 config.log | grep '^  \$$' | sed 's/^....//;s:.*configure ::')
221
222 src/%all.mk: src/%all.mk.in src/%configure
223         @echo CONFIGURE $(dir $@)
224         @rm -f ./config.cache $(dir $<)/config.cache
225         @cd $(dir $<) && ./configure $(CONFIGURE_ARGS)
226 endif
227
228 .PHONY: check-includes
229 check-includes:
230         scripts/min-includes.pl `find . -name "*.c" -print`
231
232 .PHONY: TAGS
233 TAGS:
234         etags `find src -type f -name '*.[ch]' -print` > $@
235
236 #
237 #  Make test certificates.
238 #
239 .PHONY: certs
240 certs:
241         @$(MAKE) -C raddb/certs
242
243 ######################################################################
244 #
245 #  Make a release.
246 #
247 #  Note that "Make.inc" has to be updated with the release number
248 #  BEFORE running this command!
249 #
250 ######################################################################
251 BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
252
253 freeradius-server-$(RADIUSD_VERSION_STRING).tar.gz: .git
254         git archive --format=tar --prefix=freeradius-server-$(RADIUSD_VERSION_STRING)/ $(BRANCH) | gzip > $@
255
256 freeradius-server-$(RADIUSD_VERSION_STRING).tar.bz2: .git
257         git archive --format=tar --prefix=freeradius-server-$(RADIUSD_VERSION_STRING)/ $(BRANCH) | bzip2 > $@
258
259 %.sig: %
260         gpg --default-key packages@freeradius.org -b $<
261
262 # high-level targets
263 .PHONY: dist-check
264 dist-check: redhat/freeradius.spec suse/freeradius.spec debian/changelog
265         @if [ `grep ^Version: redhat/freeradius.spec | sed 's/.*://;s/ //'` != "$(RADIUSD_VERSION_STRING)" ]; then \
266                 cat redhat/freeradius.spec | sed 's/^Version: .*/Version: $(RADIUSD_VERSION_STRING)/' > redhat/.foo; \
267                 mv redhat/.foo redhat/freeradius.spec; \
268                 echo redhat/freeradius.spec 'Version' needs to be updated; \
269                 exit 1; \
270         fi
271         @if [ `grep ^Version: suse/freeradius.spec | sed 's/.*://;s/ //'` != "$(RADIUSD_VERSION_STRING)" ]; then \
272                 cat suse/freeradius.spec | sed 's/^Version: .*/Version: $(RADIUSD_VERSION_STRING)/' > suse/.foo; \
273                 mv suse/.foo suse/freeradius.spec; \
274                 echo suse/freeradius.spec 'Version' needs to be updated; \
275                 exit 1; \
276         fi
277         @if [ `head -n 1 debian/changelog | sed 's/.*(//;s/-0).*//;s/-1).*//;s/\+.*//'`  != "$(RADIUSD_VERSION_STRING)" ]; then \
278                 echo debian/changelog needs to be updated; \
279                 exit 1; \
280         fi
281
282 dist: dist-check freeradius-server-$(RADIUSD_VERSION_STRING).tar.gz freeradius-server-$(RADIUSD_VERSION_STRING).tar.bz2
283
284 dist-sign: freeradius-server-$(RADIUSD_VERSION_STRING).tar.gz.sig freeradius-server-$(RADIUSD_VERSION_STRING).tar.bz2.sig
285
286 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
287         scp $^ freeradius.org@ftp.freeradius.org:public_ftp
288
289 #
290 #  Note that we do NOT do the tagging here!  We just print out what
291 #  to do!
292 #
293 dist-tag: freeradius-server-$(RADIUSD_VERSION_STRING).tar.gz freeradius-server-$(RADIUSD_VERSION_STRING).tar.bz2
294         @echo "git tag release_`echo $(RADIUSD_VERSION_STRING) | tr .- __`"
295
296 #
297 #       Build a debian package
298 #
299 .PHONY: deb
300 deb:
301         fakeroot dpkg-buildpackage -b -uc
302
303 # Developer checks
304 .PHONY: warnings
305 warnings:
306         @(make clean all 2>&1) | egrep -v '^/|deprecated|^In file included|: In function|   from |^HEADER|^CC|^LINK' > warnings.txt
307         @wc -l warnings.txt
308
309 #
310 #  Ensure we're using tabs in the configuration files,
311 #  and remove trailing whitespace in source files.
312 #
313 .PHONY: whitespace
314 whitespace:
315         @for x in $$(git ls-files raddb/ src/); do unexpand $$x > $$x.bak; cp $$x.bak $$x; rm -f $$x.bak;done
316         @perl -p -i -e 'trim' $$(git ls-files src/)