forked from massar/sixxsd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·307 lines (262 loc) · 8.41 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# /*********************************************************
# SixXSd - SixXS Daemon
# by Jeroen Massar <[email protected]>
# (C) Copyright SixXS 2000-2014 All Rights Reserved
# *********************************************************/
#
# Toplevel Makefile allowing easy distribution.
# Use this makefile for doing almost anything
# 'make help' shows the possibilities
# The name of the application
SIXXSD_NAME:=SixXSd
SIXXSD_DESC:="SixXSd - SixXS Daemon"
SIXXSD_COPYRIGHT:="(C) Copyright SixXS 2000-2015 All Rights Reserved"
# The version of SixXSd
SIXXSD_VERSION=4.0
# The version of SixXSd
SIXXSD_RELEASE:=2015.10.12
# Enable extra debugging operation + enables symbols (don't distribute with it enabled!)
#SIXXSD_OPTIONS+=-DDEBUG
#SIXXSD_OPTIONS+=-DSYMBOLS
# Debug Stack (Stackdump functions)
#SIXXSD_OPTIONS+=-DDEBUG_STACK
# Enable profiling?
#SIXXSD_OPTIONS+=-DPROFILE
#SIXXSD_OPTIONS+=-DCALLGRIND
#####################################################################
# No more settings to change any more below this block
#####################################################################
# HAS_IFHEAD -> Tunnel Device produces packets with a tun_pi in the front
# NEED_IFHEAD -> Tunnel Device produces packets with a tun_pi in the front,
# but it is not active per default
#####################################################################
ifeq ($(OS_NAME),)
OS_NAME=$(shell uname -s)
endif
ifeq ($(OS_RELEASE),)
OS_RELEASE=$(shell uname -r)
endif
ifeq ($(OS_BITS),)
OS_BITS=64
OS_PROC=x86_64
else
ifeq ($(OS_PROC),)
ifeq ($(OS_BITS),64)
OS_BITS=64
OS_PROC=x86_64
else
OS_BITS=32
OS_PROC=i586
endif
endif
endif
ifeq ($(OS_PROC),unknown)
OS_PROC=$(shell uname -m)
endif
# Try to get the Compiler version (currently we assume gcc)
CC_VERSION=$(shell $(CC) -v 2>&1 | grep "gcc version" | cut -f3 -d' ')
ifeq ($(CC_VERSION),)
ifeq ($(OS_NAME),Darwin)
# OSX 10.6 Snow Leopard
# gcc version 4.2.1 (Apple Inc. build 5666) (dot 3)
#
# OSX 10.7 Lion (Xcode 3.1)
# Apple clang version 3.1 (tags/Apple/clang-318.0.58) (based on LLVM 3.1svn)
#
# OSX 10.8 Mountain Lion (Xcode 4.2)
# Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
#
# OSX 10.9 Mavericks (XCode 5)
# Apple LLVM version 5.0 (clang-500.1.69) (based on LLVM 3.3svn)
CC_VERSION=$(shell $(CC) -v 2>&1 | head -n1 | cut -f4 -d' ')
CC_TYPE=clang
# Don't report unused arguments
CFLAGS+=-Qunused-arguments
endif
endif
ifeq ($(CC_VERSION),)
error "We don't have a compiler?"
endif
CC_VER=$(shell echo $(CC_VERSION) | cut -c1)
# Misc bins, making it easy to quiet/change them :)
RM=@rm -f
MV=@mv
MAKE:=${MAKE}
CP=@echo [Copy]; cp
RPMBUILD=@echo [RPMBUILD]; rpmbuild
RPMBUILD_SILENCE=>/dev/null 2>/dev/null
# Alias the Project Options, so we can show it without our own ugly
# internal Makefile addons ;)
SIXXSD_OPTS:=$(SIXXSD_OPTIONS)
# Our very *bliep* set of options to make sure that these things can't cause any issues
CFLAGS += -ansi -pedantic -std=c99
CFLAGS += -W -Wall -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return
CFLAGS += -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls
CFLAGS += -Wnested-externs -Winline -Wbad-function-cast
CFLAGS += -fshort-enums -fstrict-aliasing -fno-common
CFLAGS += -Wno-packed -Wpadded -Wswitch-default -Wno-variadic-macros
CFLAGS += -Wformat=2 -Wformat-security -Wmissing-format-attribute
CFLAGS += -D_REENTRANT -D_THREAD_SAFE
CFLAGS += -pipe
CFLAGS += -Wunused -Winit-self -Wextra -Wno-long-long -Wmissing-include-dirs
# For a rainy day, get rid of all warnings caused by:
#CFLAGS += -Wconversion
# Compile 'sixxsd' (which resides in 'src')
TARGETS+=src
# http://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html
# Describes the various standard toggles (_LARGEFILE_SOURCE, _LARGEFILE64_SOURCE, _FILE_OFFSET_BITS=64)
# See also http://www.suse.de/~aj/linux_lfs.html for Long File Support (LFS) / 64bit support documentation
ifeq ($(OS_NAME),Linux)
LDFLAGS += -lpthread -lm -lrt
CFLAGS += -DHAS_IFHEAD=1
CFLAGS += -D_XOPEN_SOURCE=600 -D_BSD_SOURCE
CFLAGS += -D_LINUX -pthread -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
endif
ifeq ($(OS_NAME),FreeBSD)
LDFLAGS += -lpthread -lm -lrt
CFLAGS += -DNEED_IFHEAD=1 -DNEED_RAWSOCKETS
CFLAGS += -D_FREEBSD -pthread
endif
# Darwin
ifeq ($(OS_NAME),Darwin)
CFLAGS += -DNEED_IFHEAD -DNEED_RAWSOCKETS
CFLAGS += -D_DARWIN
endif
ifeq ($(OS_BITS),64)
CFLAGS += -D_64BIT
SIXXSD_OPTIONS += -m64
else
SIXXSD_OPTIONS += -m32
endif
# When not debugging and not profiling: Optimize even more
ifeq ($(shell echo ${SIXXSD_OPTIONS} | grep -c "DEBUG"),0)
ifeq ($(shell echo ${SIXXSD_OPTIONS} | grep -c "PROFILE"),0)
CFLAGS += -O3 -fno-trapping-math
ifeq ($(OS_BITS),64)
CFLAGS += -fprefetch-loop-arrays
endif
CFLAGS += -ftracer -ffast-math -DNDEBUG
CFLAGS += -maccumulate-outgoing-args -minline-all-stringops
# Note that this was optimized
SIXXSD_OPTIONS += -DOPTIMIZE
SIXXSD_OPTS += -DOPTIMIZE
endif
endif
# Add profiling information
ifeq ($(shell echo ${SIXXSD_OPTIONS} | grep -c "PROFILE"),1)
CFLAGS += -pg
endif
# Not optimizing? -> Add symbols
ifeq ($(shell echo ${SIXXSD_OPTIONS} | grep -c "OPTIMIZE"),0)
# Make sure that we keep symbols (don't strip)
ifeq ($(shell echo ${SIXXSD_OPTIONS} | grep -c "SYMBOLS"),0)
SIXXSD_OPTIONS += -DSYMBOLS
endif
endif
# Add symbols?
ifeq ($(shell echo ${SIXXSD_OPTIONS} | grep -c "SYMBOLS"),1)
CFLAGS += -g -ggdb3
ifeq ($(OS_NAME),Linux)
CFLAGS += -rdynamic
endif
endif
ifeq ($(shell uname | grep -c "Linux"),1)
HOSTNAME:=$(shell hostname -f 2>/dev/null)
else
HOSTNAME:=$(shell hostname)
endif
# Pass the buildinfo so we can show that in the executable
SIXXSD_OPTIONS+=-D'BUILDINFO="$(SIXXSD_NAME) $(SIXXSD_VERSION) $(SIXXSD_RELEASE)/r$(shell svnversion -n) ($(shell id | cut -f2 -d'(' | cut -f1 -d')')@$(HOSTNAME) ($(shell $(CC) -v 2>&1 | grep "gcc version" | tr -d \')) \#1 $(shell date)"'
# Do not print "Entering directory ..."
MAKEFLAGS += --no-print-directory
# Tag it with debug when it is run with debug set
ifeq ($(shell echo $(SIXXSD_OPTIONS) | grep -c "DEBUG"),1)
SIXXSD_RELEASE:=$(SIXXSD_RELEASE)-debug
else
ifeq ($(shell echo $(SIXXSD_OPTIONS) | grep -c "SYMBOLS"),1)
SIXXSD_RELEASE:=$(SIXXSD_RELEASE)-symbols
endif
endif
# Change this if you want to install into another dirtree
# Required for eg the Debian Package builder
DESTDIR=
# Configure a default RPMDIR
ifeq ($(shell echo "${RPMDIR}/" | grep -c "/"),1)
RPMDIR=/usr/src/redhat/
endif
# Get the source dir, needed for eg debsrc
SOURCEDIR := $(shell pwd)
SOURCEDIRNAME := $(shell basename "`pwd`")
# Destination Paths (relative to DESTDIR)
dirsbin=/usr/sbin/
dirbin=/usr/bin/
diretc=/etc/
dirdoc=/usr/share/doc/${SIXXSD_NAME}/
# Make sure the lower makefile also knows these
export SIXXSD_NAME
export SIXXSD_DESC
export SIXXSD_OPTIONS
export SIXXSD_OPTS
export SIXXSD_VERSION
export SIXXSD_RELEASE
export SIXXSD_COPYRIGHT
export DESTDIR
export SOURCEDIR
export MAKEFLAGS
export CFLAGS
export LDFLAGS
export RM
export MV
export CC
export CC_VERSION
export CP
export MAKE
export dirsbin
export dirbin
export diretc
export dirdoc
export OS_NAME
export OS_PROC
export OS_BITS
#####################################################################
# The Targets
#####################################################################
all: Makefile $(TARGETS)
@echo "==== "$(SIXXSD_DESC)" ===="
@echo "Building : "$(SIXXSD_NAME)
@echo "Copyright : "$(SIXXSD_COPYRIGHT)
@echo "Version : "$(SIXXSD_VERSION)
@echo "Release : "$(SIXXSD_RELEASE)
@echo "Options : "$(SIXXSD_OPTS)
@echo "OS : "$(OS_NAME) $(OS_BITS)-bit
@echo "Compiler : $(CC) $(CC_VERSION)"
@echo "CFLAGS : $(CFLAGS)" >/dev/null
ifeq ($(CC_VERSION),)
echo "NO COMPILER VERSION!?"
exit
endif
@for dir in $(TARGETS); do $(MAKE) -C $${dir} all; done
@echo "Building done"
ifeq ($(OS_BITS),32)
ifeq ($(OS_NAME),Linux)
@echo "Note: We only build popstatd for 64bits platforms as that is what our backends are (thus use OS_BITS=64)"
endif
endif
help:
@echo "$(SIXXSD_NAME) - $(SIXXSD_DESC)"
@echo
@echo "Makefile targets:"
@echo "all : Build everything"
@echo "help : This little text"
@echo "clean : Clean the dirs to be pristine in bondage"
@echo ""
@echo "OS_BITS=32 clean all : build 32bit binary"
@echo "OS_BITS=64 clean all : build 64bit binary"
@echo ""
@echo "Note that gcc-multilib is needed for cross-compiles on 64bit to 32bit Debian hosts"
depend:
@${MAKE} -C src depend
clean:
@${MAKE} -C src clean
# Mark targets as phony
.PHONY: all help clean depend