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
30 ifeq ($(OS),Windows_NT)
34 OS := $(shell sh $(TOPDIR)/make/guess_os.sh)
37 ######################
39 # Lowlevel options and rules
43 CCACHE ?= $(shell IFS=:; for i in $$PATH;do test -x "$$i/ccache" && echo "$$i/ccache" && break; done)
44 ifeq ($(origin CC),default)
58 # target directories and names
60 ETCDIR ?= $(DESTDIR)/etc
61 USRDIR ?= $(DESTDIR)/usr
62 INCLUDEDIR ?= $(DESTDIR)/usr/include
63 LIBDIR ?= $(USRDIR)/lib
64 SBINDIR ?= $(USRDIR)/sbin
65 SHAREDIR ?= $(USRDIR)/share
66 DOCDIR ?= $(SHAREDIR)/doc
67 MANDIR ?= $(SHAREDIR)/man
69 CFGNAME ?= $(EXENAME).conf
70 CFGFILE ?= $(ETCDIR)/$(CFGNAME)
72 DOCDIR_OLSRD ?= $(DOCDIR)/$(EXENAME)
77 CPPFLAGS += -I$(TOPDIR)/src
80 # add gcc warnings and optimizations if CFLAGS not set
85 WARNINGS += -Wold-style-definition
86 WARNINGS += -Wdeclaration-after-statement
87 WARNINGS += -Wmissing-prototypes
88 WARNINGS += -Wstrict-prototypes
89 WARNINGS += -Wmissing-declarations
90 WARNINGS += -Wsign-compare
91 WARNINGS += -Waggregate-return
92 WARNINGS += -Wmissing-noreturn
93 WARNINGS += -Wmissing-format-attribute
94 WARNINGS += -Wno-multichar
95 WARNINGS += -Wno-deprecated-declarations
96 WARNINGS += -Wendif-labels
97 WARNINGS += -Wwrite-strings
98 WARNINGS += -Wbad-function-cast
99 WARNINGS += -Wpointer-arith
100 WARNINGS += -Wcast-qual
103 WARNINGS += -Wsequence-point
104 WARNINGS += -Wcast-align
105 WARNINGS += -Wformat-security
106 WARNINGS += -Wformat-y2k
107 WARNINGS += -Werror=format-security
108 WARNINGS += -Winit-self
109 WARNINGS += -Wswitch-default
110 WARNINGS += -Wsync-nand
112 WARNINGS += -Wlogical-op
113 ifneq ($(OS),android)
114 WARNINGS += -Wdouble-promotion
115 WARNINGS += -Wjump-misses-init
116 WARNINGS += -Wtrampolines
118 WARNINGS += -Wunused-parameter
119 # the following 2 do not work yet and need more work on it
120 #WARNINGS += -Wconversion
121 #WARNINGS += -Wredundant-decls
123 # work around a bug in gcc-4.*
124 WARNINGS += -Wnested-externs
126 # Alas, htons() triggers this so we can't seriously activate it.
127 #WARNINGS += -Wunreachable-code
129 WARNINGS += -Wdisabled-optimization
130 # WARNINGS += -Werror
131 WARNINGS += -finline-functions-called-once
132 WARNINGS += -funit-at-a-time
133 WARNINGS += -fearly-inlining
135 WARNINGS += -fomit-frame-pointer
137 # we have small inline functions in src/lq_route.h which should always be inlined
138 WARNINGS += -finline-limit=350
139 # These tell gcc to put each function and global variable in a separate section.
140 # The linker can than remove all unreferenced section. But in the olsrd binary
141 # unused doesn't imply unused at all since the function may be used by plugins,
142 # e.g. the ones in src/plugin_utils.c.
143 # So we can use that featuer at most to identify unused functions and remove them
144 # from the source by hand.
145 #WARNINGS += -ffunction-sections
146 #WARNINGS += -fdata-sections
147 WARNINGS := $(shell CC="$(CC)" "$(TOPDIR)/gcc-warnings" $(WARNINGS))
149 CFLAGS += $(WARNINGS)
150 CFLAGS += $(OPTIMIZE)
151 CFLAGS += $(EXTRA_CFLAGS)
153 # Must be specified along with -lpthread on linux
154 CPPFLAGS += $(OS_CFLAG_PTHREAD)
157 CFLAGS += -fmudflapth
161 # c and ld flags for libraries (plugins)
162 CPPFLAGS += -DOLSR_PLUGIN
164 LDFLAGS += -Wl,-export-all-symbols,--enable-auto-import
167 LDFLAGS += -Wl,-soname,$(PLUGIN_SONAME)
168 LDFLAGS += -Wl,--version-script=version-script.txt
170 # c and ld flags for main
172 LDFLAGS += -Wl,-export-all-symbols
174 LDFLAGS += -Wl,-export-dynamic
176 LDFLAGS += -Wl,-rpath,$(LIBDIR)
179 LDFLAGS += -Wl,--warn-common
180 # See above at "-ffunction-sections" for an explanation (and why it is disabled).
181 #LDOPTS += -Wl,--gc-sections
182 #LDOPTS += -Wl,--print-gc-sections
183 #LDFLAGS += $(shell CC="$(CC)" $(TOPDIR)/ld-warnings $(LDOPTS))
187 LIBS += $(OS_LIB_PTHREAD)
189 # extra options from the outside
190 CPPFLAGS += $(EXTRA_CPPFLAGS)
192 ###################################
194 # options to save space on small systems
196 # we have plugins with the old interface
197 #CPPFLAGS += -DSUPPORT_OLD_PLUGIN_VERSIONS=1
199 # use the new fixed point math stuff
200 CPPFLAGS += -DUSE_FPM
202 # search sources and headers in current dir and in src/
203 SRCS += $(wildcard src/common/*.c src/*.c *.c)
204 HDRS += $(wildcard src/common/*.h src/*.h *.h)
209 # include OS specifics
211 include $(TOPDIR)/make/Makefile.$(OS)
214 # one object for each source file
215 OBJS += $(SRCS:%.c=%.o)
217 # debugging or non-debugging flags
224 OPTIMIZE += -O2 -D_FORTIFY_SOURCE=2
227 ifeq ($(NO_DEBUG_MESSAGES),1)
228 CPPFLAGS += -DNODEBUG
232 CPPFLAGS+=-DHTTPINFO_PUD -I$(TOPDIR)/lib -I$(TOPDIR)/lib/pud/nmealib/include -I$(TOPDIR)/lib/pud/wireformat/include
235 # a make function to quote "/" and "."
236 quote = $(subst .,\.,$(subst /,\/,$1))
238 # fully automatic and working dependency generation
240 $(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' >"$@"
246 $(MAKECMDPREFIX)$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
248 # we always need the includes and defines
249 # for legacy since now
250 CPPFLAGS += $(INCLUDES) $(DEFINES)
252 $(warning Use CPPFLAGS instead of INCLUDES for -I)
255 $(warning Use CPPFLAGS instead of DEFINES for -D)
262 @echo '***** olsr.org olsr daemon Make ****'
263 @echo ' Automatic detection of your OS '
265 @echo ' You can provide a valid target OS '
266 @echo ' by setting the OS variable! Valid '
267 @echo ' target OSes are: '
268 @echo ' --------------------------------- '
269 @echo ' linux - GNU/Linux '
270 @echo ' win32 - MS Windows '
271 @echo ' fbsd - FreeBSD '
272 @echo ' nbsd - NetBSD '
273 @echo ' obsd - OpenBSD '
274 @echo ' osx - Mac OS X '
275 @echo ' android - Android '
276 @echo ' --------------------------------- '
277 @echo ' Example - build for windows: '
278 @echo ' make OS=win32 '
279 @echo ' If you are developing olsrd code, '
280 @echo ' exporting the OS variable might '
281 @echo ' be a good idea :-) Have fun! '
282 @echo '************************************'
285 ifeq ($(filter clean% %clean, $(MAKECMDGOALS)),)
286 # include dependencies - we don't need any dependency for a everytime generated files
287 -include $(filter-out src/builddata.%,$(SRCS:%.c=%.d))