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