3 # Highlevel configuration options for all
7 # activate debugging with 1 or deactivate with 0
10 # set NOSTRIP to non-zero to inhibit stripping the binaries
13 # compile OLSR_PRINTF out
14 NO_DEBUG_MESSAGES ?= 0
16 # the optimize option to be set for gcc
19 # enable mudflap with 1 or deactivate with 0
20 # you need a recent enough gcc and the libmudflap installed
23 # shows full compiler/linker calls if activated
35 ifeq ($(OS),Windows_NT)
39 OS := $(shell sh $(TOPDIR)/make/guess_os.sh)
42 ######################
44 # Lowlevel options and rules
48 CCACHE ?= $(shell IFS=:; for i in $$PATH;do test -x "$$i/ccache" && echo "$$i/ccache" && break; done)
49 ifeq ($(origin CC),default)
67 # target directories and names
69 ETCDIR ?= $(DESTDIR)/etc/olsrd
70 USRDIR ?= $(DESTDIR)/usr
71 INCLUDEDIR ?= $(DESTDIR)/usr/include
72 LIBDIR ?= $(USRDIR)/lib
73 SBINDIR ?= $(USRDIR)/sbin
74 SHAREDIR ?= $(USRDIR)/share
75 DOCDIR ?= $(SHAREDIR)/doc
76 MANDIR ?= $(SHAREDIR)/man
78 CFGNAME ?= $(EXENAME).conf
79 CFGFILE ?= $(ETCDIR)/$(CFGNAME)
80 SGW_POLICY_SCRIPT ?= sgw_policy_routing_setup.sh
82 DOCDIR_OLSRD ?= $(DOCDIR)/$(EXENAME)
87 CPPFLAGS += -I$(TOPDIR)/src
93 # include OS specifics
95 include $(TOPDIR)/make/Makefile.$(OS)
98 # add gcc warnings and optimizations if CFLAGS not set
103 WARNINGS += -Wold-style-definition
104 WARNINGS += -Wdeclaration-after-statement
105 WARNINGS += -Wmissing-prototypes
106 WARNINGS += -Wstrict-prototypes
107 WARNINGS += -Wmissing-declarations
108 WARNINGS += -Wsign-compare
109 WARNINGS += -Waggregate-return
110 WARNINGS += -Wmissing-noreturn
111 WARNINGS += -Wmissing-format-attribute
112 WARNINGS += -Wno-multichar
113 WARNINGS += -Wno-deprecated-declarations
114 WARNINGS += -Wendif-labels
115 WARNINGS += -Wwrite-strings
116 WARNINGS += -Wbad-function-cast
117 WARNINGS += -Wpointer-arith
119 WARNINGS += -Wcast-qual
123 WARNINGS += -Wsequence-point
124 WARNINGS += -Wcast-align
125 WARNINGS += -Wformat-security
126 WARNINGS += -Wformat-y2k
127 WARNINGS += -Werror=format-security
128 WARNINGS += -Winit-self
129 WARNINGS += -Wswitch-default
132 WARNINGS += -Wsync-nand
133 WARNINGS += -Wlogical-op
135 ifneq ($(OS),android)
137 WARNINGS += -Wdouble-promotion
138 WARNINGS += -Wjump-misses-init
139 WARNINGS += -Wtrampolines
142 WARNINGS += -Wunused-parameter
143 # the following 2 do not work yet and need more work on it
144 #WARNINGS += -Wconversion
145 #WARNINGS += -Wredundant-decls
147 # work around a bug in gcc-4.*
148 WARNINGS += -Wnested-externs
150 # Alas, htons() triggers this so we can't seriously activate it.
151 #WARNINGS += -Wunreachable-code
153 WARNINGS += -Wdisabled-optimization
154 # WARNINGS += -Werror
155 WARNINGS += -funit-at-a-time
157 WARNINGS += -finline-functions-called-once
158 WARNINGS += -fearly-inlining
161 WARNINGS += -fomit-frame-pointer
163 # we have small inline functions in src/lq_route.h which should always be inlined
165 WARNINGS += -finline-limit=350
167 # These tell gcc to put each function and global variable in a separate section.
168 # The linker can than remove all unreferenced section. But in the olsrd binary
169 # unused doesn't imply unused at all since the function may be used by plugins,
170 # e.g. the ones in src/plugin_utils.c.
171 # So we can use that featuer at most to identify unused functions and remove them
172 # from the source by hand.
173 #WARNINGS += -ffunction-sections
174 #WARNINGS += -fdata-sections
175 WARNINGS := $(shell CC="$(CC)" "$(TOPDIR)/gcc-warnings" $(WARNINGS))
177 CFLAGS += $(WARNINGS)
178 CFLAGS += $(OPTIMIZE)
179 CFLAGS += $(EXTRA_CFLAGS)
183 CFLAGS += -fmudflapth
187 # c and ld flags for libraries (plugins)
188 CPPFLAGS += -DOLSR_PLUGIN
190 LDFLAGS += -Wl,-export-all-symbols,--enable-auto-import
193 LDFLAGS += -Wl,-soname,$(PLUGIN_SONAME)
194 LDFLAGS += -Wl,--version-script=version-script.txt
196 # c and ld flags for main
198 LDFLAGS += -Wl,-export-all-symbols
200 LDFLAGS += -Wl,-export-dynamic
202 LDFLAGS += -Wl,-rpath,$(LIBDIR)
205 LDFLAGS += -Wl,--warn-common
206 # See above at "-ffunction-sections" for an explanation (and why it is disabled).
207 #LDOPTS += -Wl,--gc-sections
208 #LDOPTS += -Wl,--print-gc-sections
209 #LDFLAGS += $(shell CC="$(CC)" $(TOPDIR)/ld-warnings $(LDOPTS))
215 ifneq ($(SANITIZE_ADDRESS),0)
216 CFLAGS += -fsanitize=address -fno-omit-frame-pointer
217 LDFLAGS += -fsanitize=address -static-libasan
221 # extra options from the outside
222 CPPFLAGS += $(EXTRA_CPPFLAGS)
225 # 32/64 cross compilation
236 ###################################
238 # options to save space on small systems
240 # we have plugins with the old interface
241 #CPPFLAGS += -DSUPPORT_OLD_PLUGIN_VERSIONS=1
243 # use the new fixed point math stuff
244 CPPFLAGS += -DUSE_FPM
246 # search sources and headers in current dir and in src/
247 SRCS += $(wildcard src/common/*.c src/*.c *.c)
248 HDRS += $(wildcard src/common/*.h src/*.h *.h)
250 # one object for each source file
251 OBJS += $(SRCS:%.c=%.o)
253 # debugging or non-debugging flags
263 OPTIMIZE += -O2 -D_FORTIFY_SOURCE=2
266 ifeq ($(NO_DEBUG_MESSAGES),1)
267 CPPFLAGS += -DNODEBUG
270 # preserve debugging info when NOSTRIP is set
276 CPPFLAGS+=-DHTTPINFO_PUD -I$(TOPDIR)/lib -I$(TOPDIR)/lib/pud/nmealib/include -I$(TOPDIR)/lib/pud/wireformat/include
279 # a make function to quote "/" and "."
280 quote = $(subst .,\.,$(subst /,\/,$1))
282 # fully automatic and working dependency generation
284 $(MAKECMDPREFIX)$(filter-out $(CCACHE),$(CC)) -M $(strip $(CPPFLAGS)) "$<" | sed -e '1s/\($(call quote,$(*F))\.o\)[ :]*/$(call quote,$(*D)/\1 $@: Makefile $(TOPDIR)$(if $(TOPDIR),/)Makefile.inc) /g' >"$@"
290 $(MAKECMDPREFIX)$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
292 # we always need the includes and defines
293 # for legacy since now
294 CPPFLAGS += $(INCLUDES) $(DEFINES)
296 $(warning Use CPPFLAGS instead of INCLUDES for -I)
299 $(warning Use CPPFLAGS instead of DEFINES for -D)
306 @echo '***** olsr.org olsr daemon Make ****'
307 @echo ' Automatic detection of your OS '
309 @echo ' You can provide a valid target OS '
310 @echo ' by setting the OS variable! Valid '
311 @echo ' target OSes are: '
312 @echo ' --------------------------------- '
313 @echo ' linux - GNU/Linux '
314 @echo ' win32 - MS Windows '
315 @echo ' fbsd - FreeBSD '
316 @echo ' nbsd - NetBSD '
317 @echo ' obsd - OpenBSD '
318 @echo ' osx - Mac OS X '
319 @echo ' android - Android '
320 @echo ' --------------------------------- '
321 @echo ' Example - build for windows: '
322 @echo ' make OS=win32 '
323 @echo ' If you are developing olsrd code, '
324 @echo ' exporting the OS variable might '
325 @echo ' be a good idea :-) Have fun! '
326 @echo '************************************'
329 ifeq ($(filter clean% %clean, $(MAKECMDGOALS)),)
330 # include dependencies - we don't need any dependency for a everytime generated files
331 -include $(filter-out src/builddata.%,$(SRCS:%.c=%.d))