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