Merge tag 'release_3_0_12' into branch moonshot-fr-3.0.12-upgrade.
[freeradius.git] / src / include / all.mk
1 #
2 # Version:      $Id$
3 #
4
5 #
6 #  Build dynamic headers by substituting various values from autoconf.h, these
7 #  get installed with the library files, so external programs can tell what
8 #  the server library was built with.
9 #
10 #  The RFC headers are dynamic, too.
11 #
12 #  The rest of the headers are static.
13 #
14
15 HEADERS_DY = attributes.h features.h missing.h radpaths.h tls.h
16
17 HEADERS = \
18         build.h \
19         conf.h \
20         conffile.h \
21         detail.h \
22         event.h \
23         hash.h \
24         heap.h \
25         libradius.h \
26         md4.h \
27         md5.h \
28         modcall.h \
29         modules.h \
30         packet.h \
31         rad_assert.h \
32         radius.h \
33         radiusd.h \
34         radutmp.h \
35         realms.h \
36         sha1.h \
37         stats.h \
38         sysutmp.h \
39         token.h \
40         udpfromto.h \
41         base64.h \
42         map.h \
43         $(HEADERS_DY)
44
45 #
46 #  Solaris awk doesn't recognise [[:blank:]] hence [\t ]
47 #
48 src/include/autoconf.sed: src/include/autoconf.h
49         @grep ^#define $< | sed 's,/\*\*/,1,;' | awk '{print "'\
50         's,#[\\t ]*ifdef[\\t ]*" $$2 "$$,#if "$$3 ",g;'\
51         's,#[\\t ]*ifndef[\\t ]*" $$2 "$$,#if !"$$3 ",g;'\
52         's,defined(" $$2 ")," $$3 ",g;"}' > $@
53         @grep -o '#undef [^ ]*' $< | sed 's,/#undef /,,;' | awk '{print "'\
54         's,#[\\t ]*ifdef[\\t ]*" $$2 "$$,#if 0,g;'\
55         's,#[\\t ]*ifndef[\\t ]*" $$2 "$$,#if 1,g;'\
56         's,defined(" $$2 "),0,g;"}' >> $@
57
58
59 ######################################################################
60 #
61 #  Create the header files from the dictionaries.
62 #
63
64 RFC_DICTS := $(filter-out %~,$(wildcard share/dictionary.rfc*)) share/dictionary.vqp share/dictionary.freeradius
65 HEADERS_RFC := $(patsubst share/dictionary.%,src/include/%.h,$(RFC_DICTS))
66 HEADERS += $(notdir ${HEADERS_RFC})
67
68 .PRECIOUS: $(HEADERS_RFC)
69
70 src/include/attributes.h: share/dictionary.freeradius.internal
71         @$(ECHO) HEADER $@
72         @echo "/* AUTO-GENERATED HEADER FILE.  DO NOT EDIT. */" > $@
73         @grep ^ATTRIBUTE $<  | awk '{print "PW_"$$2 " " $$3 }' | tr '[:lower:]' '[:upper:]' | tr -- - _ | sed 's/^/#define /' >> $@
74         @echo " " >> $@
75         @grep -- 'Auth-Type' $< | grep ^VALUE | awk '{print "PW_"$$2 "_" $$3 " " $$4 }' | tr '[:lower:]' '[:upper:]' | tr -- - _ | sed 's/^/#define /' >> $@
76
77 src/include/%.h: share/dictionary.% share/dictionary.vqp
78         @$(ECHO) HEADER $@
79         @echo "/* AUTO-GENERATED HEADER FILE.  DO NOT EDIT. */" > $@
80         @grep ^ATTRIBUTE $<  | awk '{print "PW_"$$2 " " $$3 } ' | tr '[:lower:]' '[:upper:]' | tr -- - _ | sed 's/^/#define /' >> $@
81
82 #
83 #  Build features.h by copying over WITH_* and RADIUSD_VERSION_*
84 #  preprocessor macros from autoconf.h
85 #  This means we don't need to include autoconf.h in installed headers.
86 #
87 #  We use simple patterns here to work with the lowest common
88 #  denominator's grep (Solaris).
89 #
90 src/include/features.h: src/include/features-h src/include/autoconf.h
91         @$(ECHO) HEADER $@
92         @cp $< $@
93         @grep "^#define[ ]*WITH_" src/include/autoconf.h >> $@
94         @grep "^#define[ ]*RADIUSD_VERSION" src/include/autoconf.h >> $@
95
96 #
97 #  Use the SED script we built earlier to make permanent substitutions
98 #  of definitions in missing-h to build missing.h
99 #
100 src/include/missing.h: src/include/missing-h src/include/autoconf.sed
101         @$(ECHO) HEADER $@
102         @sed -f src/include/autoconf.sed < $< > $@
103
104 src/include/tls.h: src/include/tls-h src/include/autoconf.sed
105         @$(ECHO) HEADER $@
106         @sed -f src/include/autoconf.sed < $< > $@
107
108 src/include/radpaths.h: src/include/build-radpaths-h
109         @$(ECHO) HEADER $@
110         @cd src/include && /bin/sh build-radpaths-h
111
112 #
113 #  Create the soft link for the fake include file path.
114 #
115 src/freeradius-devel:
116         @[ -e $@ ] || ln -s include $@
117
118 #
119 #  Ensure we set up the build environment
120 #
121 BOOTSTRAP_BUILD += src/freeradius-devel $(addprefix src/include/,$(HEADERS_DY)) $(HEADERS_RFC)
122 scan: $(BOOTSTRAP_BUILD)
123
124 ######################################################################
125 #
126 #  Installation
127 #
128 # define the installation directory
129 SRC_INCLUDE_DIR := ${R}${includedir}/freeradius
130
131 $(SRC_INCLUDE_DIR):
132         @$(INSTALL) -d -m 755 ${SRC_INCLUDE_DIR}
133
134 #
135 #  install the headers by re-writing the local files
136 #
137 #  install-sh function for creating directories gets confused
138 #  if there's a trailing slash, tries to create a directory
139 #  it already created, and fails...
140 #
141 ${SRC_INCLUDE_DIR}/%.h: src/include/%.h | $(SRC_INCLUDE_DIR)
142         @echo INSTALL $(notdir $<)
143         @$(INSTALL) -d -m 755 `echo $(dir $@) | sed 's/\/$$//'`
144 # Expression must deal with indentation after the hash and copy it to the substitution string.
145 # Hash not anchored to allow substitution in function documentation.
146         @sed -e 's/#\([\\t ]*\)include <freeradius-devel\/\([^>]*\)>/#\1include <freeradius\/\2>/g' < $< > $@
147         @chmod 644 $@
148
149 install.src.include: $(addprefix ${SRC_INCLUDE_DIR}/,${HEADERS})
150 install: install.src.include
151
152 #
153 #  Cleaning
154 #
155 .PHONY: clean.src.include distclean.src.include
156 clean.src.include:
157         @rm -f $(addprefix src/include/,$(HEADERS_DY)) $(HEADERS_RFC)
158
159 clean: clean.src.include
160
161 distclean.src.include: clean.src.include
162         @rm -f autoconf.sed
163
164 distclean: distclean.src.include