3 # Highlevel configuration options for all
7 # activate debugging with 1 or deactivate with 0
10 # compile OLSR_PRINTF out
11 NO_DEBUG_MESSAGES ?= 0
13 # the optimize option to be set for gcc
16 # enable mudflap with 1 or deactivate with 0
17 # you need a recent enough gcc and the libmudflap installed
20 # shows full compiler/linker calls if activated
32 ifeq ($(OS),Windows_NT)
36 OS := $(shell sh $(TOPDIR)/make/guess_os.sh)
39 ######################
41 # Lowlevel options and rules
45 CCACHE ?= $(shell IFS=:; for i in $$PATH;do test -x "$$i/ccache" && echo "$$i/ccache" && break; done)
46 ifeq ($(origin CC),default)
60 # target directories and names
62 ETCDIR ?= $(DESTDIR)/etc/olsrd
63 USRDIR ?= $(DESTDIR)/usr
64 INCLUDEDIR ?= $(DESTDIR)/usr/include
65 LIBDIR ?= $(USRDIR)/lib
66 SBINDIR ?= $(USRDIR)/sbin
67 SHAREDIR ?= $(USRDIR)/share
68 DOCDIR ?= $(SHAREDIR)/doc
69 MANDIR ?= $(SHAREDIR)/man
71 CFGNAME ?= $(EXENAME).conf
72 CFGFILE ?= $(ETCDIR)/$(CFGNAME)
73 SGW_POLICY_SCRIPT ?= sgw_policy_routing_setup.sh
75 DOCDIR_OLSRD ?= $(DOCDIR)/$(EXENAME)
80 CPPFLAGS += -I$(TOPDIR)/src
83 # add gcc warnings and optimizations if CFLAGS not set
88 WARNINGS += -Wold-style-definition
89 WARNINGS += -Wdeclaration-after-statement
90 WARNINGS += -Wmissing-prototypes
91 WARNINGS += -Wstrict-prototypes
92 WARNINGS += -Wmissing-declarations
93 WARNINGS += -Wsign-compare
94 WARNINGS += -Waggregate-return
95 WARNINGS += -Wmissing-noreturn
96 WARNINGS += -Wmissing-format-attribute
97 WARNINGS += -Wno-multichar
98 WARNINGS += -Wno-deprecated-declarations
99 WARNINGS += -Wendif-labels
100 WARNINGS += -Wwrite-strings
101 WARNINGS += -Wbad-function-cast
102 WARNINGS += -Wpointer-arith
104 WARNINGS += -Wcast-qual
108 WARNINGS += -Wsequence-point
109 WARNINGS += -Wcast-align
110 WARNINGS += -Wformat-security
111 WARNINGS += -Wformat-y2k
112 WARNINGS += -Werror=format-security
113 WARNINGS += -Winit-self
114 WARNINGS += -Wswitch-default
115 WARNINGS += -Wsync-nand
117 WARNINGS += -Wlogical-op
118 ifneq ($(OS),android)
119 WARNINGS += -Wdouble-promotion
120 WARNINGS += -Wjump-misses-init
121 WARNINGS += -Wtrampolines
123 WARNINGS += -Wunused-parameter
124 # the following 2 do not work yet and need more work on it
125 #WARNINGS += -Wconversion
126 #WARNINGS += -Wredundant-decls
128 # work around a bug in gcc-4.*
129 WARNINGS += -Wnested-externs
131 # Alas, htons() triggers this so we can't seriously activate it.
132 #WARNINGS += -Wunreachable-code
134 WARNINGS += -Wdisabled-optimization
135 # WARNINGS += -Werror
136 WARNINGS += -finline-functions-called-once
137 WARNINGS += -funit-at-a-time
138 WARNINGS += -fearly-inlining
140 WARNINGS += -fomit-frame-pointer
142 # we have small inline functions in src/lq_route.h which should always be inlined
143 WARNINGS += -finline-limit=350
144 # These tell gcc to put each function and global variable in a separate section.
145 # The linker can than remove all unreferenced section. But in the olsrd binary
146 # unused doesn't imply unused at all since the function may be used by plugins,
147 # e.g. the ones in src/plugin_utils.c.
148 # So we can use that featuer at most to identify unused functions and remove them
149 # from the source by hand.
150 #WARNINGS += -ffunction-sections
151 #WARNINGS += -fdata-sections
152 WARNINGS := $(shell CC="$(CC)" "$(TOPDIR)/gcc-warnings" $(WARNINGS))
154 CFLAGS += $(WARNINGS)
155 CFLAGS += $(OPTIMIZE)
156 CFLAGS += $(EXTRA_CFLAGS)
160 CFLAGS += -fmudflapth
164 # c and ld flags for libraries (plugins)
165 CPPFLAGS += -DOLSR_PLUGIN
167 LDFLAGS += -Wl,-export-all-symbols,--enable-auto-import
170 LDFLAGS += -Wl,-soname,$(PLUGIN_SONAME)
171 LDFLAGS += -Wl,--version-script=version-script.txt
173 # c and ld flags for main
175 LDFLAGS += -Wl,-export-all-symbols
177 LDFLAGS += -Wl,-export-dynamic
179 LDFLAGS += -Wl,-rpath,$(LIBDIR)
182 LDFLAGS += -Wl,--warn-common
183 # See above at "-ffunction-sections" for an explanation (and why it is disabled).
184 #LDOPTS += -Wl,--gc-sections
185 #LDOPTS += -Wl,--print-gc-sections
186 #LDFLAGS += $(shell CC="$(CC)" $(TOPDIR)/ld-warnings $(LDOPTS))
192 ifneq ($(SANITIZE_ADDRESS),0)
193 CFLAGS += -fsanitize=address -fno-omit-frame-pointer
194 LDFLAGS += -fsanitize=address -static-libasan
198 # extra options from the outside
199 CPPFLAGS += $(EXTRA_CPPFLAGS)
202 # 32/64 cross compilation
213 ###################################
215 # options to save space on small systems
217 # we have plugins with the old interface
218 #CPPFLAGS += -DSUPPORT_OLD_PLUGIN_VERSIONS=1
220 # use the new fixed point math stuff
221 CPPFLAGS += -DUSE_FPM
223 # search sources and headers in current dir and in src/
224 SRCS += $(wildcard src/common/*.c src/*.c *.c)
225 HDRS += $(wildcard src/common/*.h src/*.h *.h)
230 # include OS specifics
232 include $(TOPDIR)/make/Makefile.$(OS)
235 # one object for each source file
236 OBJS += $(SRCS:%.c=%.o)
238 # debugging or non-debugging flags
248 OPTIMIZE += -O2 -D_FORTIFY_SOURCE=2
251 ifeq ($(NO_DEBUG_MESSAGES),1)
252 CPPFLAGS += -DNODEBUG
256 CPPFLAGS+=-DHTTPINFO_PUD -I$(TOPDIR)/lib -I$(TOPDIR)/lib/pud/nmealib/include -I$(TOPDIR)/lib/pud/wireformat/include
259 # a make function to quote "/" and "."
260 quote = $(subst .,\.,$(subst /,\/,$1))
262 # fully automatic and working dependency generation
264 $(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' >"$@"
270 $(MAKECMDPREFIX)$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
272 # we always need the includes and defines
273 # for legacy since now
274 CPPFLAGS += $(INCLUDES) $(DEFINES)
276 $(warning Use CPPFLAGS instead of INCLUDES for -I)
279 $(warning Use CPPFLAGS instead of DEFINES for -D)
286 @echo '***** olsr.org olsr daemon Make ****'
287 @echo ' Automatic detection of your OS '
289 @echo ' You can provide a valid target OS '
290 @echo ' by setting the OS variable! Valid '
291 @echo ' target OSes are: '
292 @echo ' --------------------------------- '
293 @echo ' linux - GNU/Linux '
294 @echo ' win32 - MS Windows '
295 @echo ' fbsd - FreeBSD '
296 @echo ' nbsd - NetBSD '
297 @echo ' obsd - OpenBSD '
298 @echo ' osx - Mac OS X '
299 @echo ' android - Android '
300 @echo ' --------------------------------- '
301 @echo ' Example - build for windows: '
302 @echo ' make OS=win32 '
303 @echo ' If you are developing olsrd code, '
304 @echo ' exporting the OS variable might '
305 @echo ' be a good idea :-) Have fun! '
306 @echo '************************************'
309 ifeq ($(filter clean% %clean, $(MAKECMDGOALS)),)
310 # include dependencies - we don't need any dependency for a everytime generated files
311 -include $(filter-out src/builddata.%,$(SRCS:%.c=%.d))