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