forked from lalithsuresh/click
-
Notifications
You must be signed in to change notification settings - Fork 0
/
click-compile.in
305 lines (289 loc) · 11 KB
/
click-compile.in
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
#! /bin/sh
# click-compile.in -- script compiles Click elements
# Eddie Kohler
#
# Copyright (c) 1999 Massachusetts Institute of Technology
# Copyright (c) 2001 International Computer Science Institute
# Copyright (c) 2005 Regents of the University of California
# Copyright (c) 2008 Meraki, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, subject to the conditions
# listed in the Click LICENSE file. These conditions include: you must
# preserve this copyright notice, and you cannot mention the copyright
# holders in advertising related to the Software without their permission.
# The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
# notice is a summary of the Click LICENSE file; the license in that file is
# legally binding.
prefix=@prefix@
exec_prefix=@exec_prefix@
includedir=@includedir@
libdir=@libdir@
datarootdir=@datarootdir@
datadir=@datadir@
srcdir=${datadir}/click/src
freebsd_includedir=@freebsd_includedir@
CLICK_VERSION=@CLICK_VERSION@
# determine mode
directory=.
driver=
package=NONE
cflags=
compileflag=-c
quiet=
gpl=y
exit=
while true; do
bad=x
case $1 in
-t|--dr|--dri|--driv|--drive|--driver)
driver=$2; shift 2;;
-t*)
driver=`echo "$1" | sed 's/^-t//'`; shift 1;;
--dr=*|--dri=*|--driv=*|--drive=*|--driver=*)
driver=`echo "$1" | sed 's/[-a-z]*=//'`; shift 1;;
--c|--cf|--cfl|--cfla|--cflag|--cflags|--de|--def|--defs)
echo @PROPER_INCLUDES@ @PCAP_INCLUDES@ @NETMAP_INCLUDES@ -I$includedir
exit=y; shift 1;;
--l|--li|--lib|--libs)
echo -L$libdir -lclick @PROPER_LIBS@ @PCAP_LIBS@ @DL_LIBS@ @SOCKET_LIBS@ @PTHREAD_LIBS@ @POSIX_CLOCK_LIBS@
exit=y; shift 1;;
--toolc|--toolcf|--toolcfl|--toolcfla|--toolcflag|--toolcflags)
echo -DCLICK_TOOL -I$includedir
exit=y; shift 1;;
--tooll|--toolli|--toollib|--toollibs)
echo -L$libdir -lclicktool @DL_LIBS@ @SOCKET_LIBS@ @POSIX_CLOCK_LIBS@
exit=y; shift 1;;
--o|--ot|--oth|--othe|--other|--otherl|--otherli|--otherlib|--otherlibs)
echo @PROPER_LIBS@ @PCAP_LIBS@ @DL_LIBS@ @SOCKET_LIBS@ @PTHREAD_LIBS@ @POSIX_CLOCK_LIBS@
exit=y; shift 1;;
-d|--di|--dir|--dire|--direc|--direct|--directo|--director|--directory)
directory=$2; shift 2;;
-d*)
directory=`echo "$1" | sed 's/^-d//'`; shift 1;;
--di=*|--dir=*|--dire=*|--direc=*|--direct=*|--directo=*|--director=*|--directory=*)
directory=`echo "$1" | sed 's/^[^=]*=//'`; shift 1;;
--t|--ta|--tar|--targ|--targe|--target)
echo "click-compile: '--target' is obsolete; change your script to use '--driver'" 1>&2
driver=$2; shift 2;;
--t=*|--ta=*|--tar=*|--targ=*|--targe=*|--target=*)
echo "click-compile: '--target' is obsolete; change your script to use '--driver'" 1>&2
driver=`echo "$1" | sed 's/[-a-z]*=//'`; shift 1;;
-p|--p|--pa|--pac|--pack|--packa|--packag|--package)
package=$2; shift 2;;
-p*)
package=`echo "$1" | sed 's/^-p//'`; shift 1;;
--p=*|--pa=*|--pac=*|--pack=*|--packa=*|--packag=*|--package=*)
package=`echo "$1" | sed 's/[-a-z]*=//'`; shift 1;;
-q|--q|--qu|--qui|--quie|--quiet)
quiet=y; shift 1;;
--no-g|--no-gp|--no-gpl)
gpl=n; shift 1;;
-h|--h|--he|--hel|--help)
cat <<'EOF'
'Click-compile' compiles a Click source file, or outputs any compiler options
relevant for userlevel Click drivers.
Usage: click-compile -t DRIVER [OPTIONS] SOURCEFILE...
Options:
--defs Outputs preprocessor options for userlevel drivers.
--libs Outputs link options for userlevel drivers.
--otherlibs Like '--libs' minus the Click library.
--toolcflags Outputs C/C++ flags options for tools.
--toollibs Outputs link options for tools.
-t, --driver DRIVER Sets target driver to 'bsdmodule', 'linuxmodule',
'userlevel', 'ns', or 'tool'.
-p, --package PACKAGE Build a dynamically loadable package named PACKAGE.
-d, --directory DIR Change to directory DIR.
-q, --quiet Be quiet (don't echo commands or print warnings).
--no-gpl Omit "BSD/GPL" declaration from kernel package.
-h, --help Print this message and exit.
-v, --version Print version number and exit.
Other options are passed to the compiler unchanged.
Report bugs to <[email protected]>.
EOF
exit 0;;
-v|--v|--ve|--ver|--vers|--versi|--versio|--version)
echo click-compile '(Click)' $CLICK_VERSION
cat <<"EOF"
Copyright (C) 1999-2001 Massachusetts Institute of Technology
Copyright (C) 2002 International Computer Science Institute
Copyright (C) 2004 Regents of the University of California
This is free software; see the source for copying conditions.
There is NO warranty, not even for merchantability or fitness for any
particular purpose.
EOF
exit 0;;
-*)
if test "$1" = -E -o "$1" = -c -o "$1" = -S; then
compileflag=$1
else
cflags="$cflags '$1'"
fi
shift 1;;
*)
bad=;;
esac
if test -z "$bad"; then break; fi
done
if test -n "$exit"; then exit 0; fi
cd $directory
# test directory function
test_dir () {
test -d "$1" -a -d "$1/elements" -a -d "$1/lib"
}
# analyze CLICKPATH to find sources
path=${CLICKPATH-:}
tried_defaults=
include_source=
while true; do
case $path in
:*)
if test -z "$tried_defaults" && test_dir "$srcdir"; then
include_source="-I$srcdir"
else
tried_defaults=y
fi
path=`echo "$path" | sed 's/://'`
;;
*:*)
dir=`echo "$path" | sed 's/:.*//'`
if test_dir "$dir"; then include_source="-I$dir"; fi
path=`echo "$path" | sed 's/[^:]*://'`
;;
*:)
dir=`echo "$path" | sed 's/:.*//'`
if test_dir "$dir"; then include_source="-I$dir"; fi
path=":"
;;
*)
if test_dir "$path"; then include_source="-I$path"; fi
path=""
;;
esac
if test -z "$path" -o -n "$include_source"; then break; fi
done
if test ! -d "$includedir"; then
echo "click-compile: Cannot find Click include directory!" 1>&2
echo " (Have you installed Click yet?)" 1>&2
exit 1
elif test -z "$include_source"; then
if test -z "$quiet"; then
echo "click-compile: warning: cannot find full Click source" 1>&2
fi
fi
case $driver in
u|us|use|user|userl|userle|userlev|userleve|userlevel)
idefs="@DEFS@ -DCLICK_USERLEVEL"
iincludes="${include_source} -I${includedir}"
icppflags="@CPPFLAGS@"
icxxflags="-fPIC @CXXFLAGS@ @DEPCFLAGS@"
icflags="-fPIC @CFLAGS@ @DEPCFLAGS@"
command="${CXX-@CXX@} ${DEFS-$idefs} ${INCLUDES-$iincludes} ${CPPFLAGS-$icppflags} ${CXXFLAGS-$icxxflags} $cflags $compileflag"
c_command="${CC-@CC@} ${DEFS-$idefs} ${INCLUDES-$iincludes} ${CPPFLAGS-$icppflags} ${CFLAGS-$icflags} $cflags $compileflag"
driver=userlevel;;
k|ke|ker|kern|kerne|kernel|l|li|lin|linu|linux|linuxm|linuxmo|linuxmod|linuxmodu|linuxmodul|linuxmodule)
idefs="@DEFS@ -DCLICK_LINUXMODULE"
iincludes="${include_source} -I${includedir}"
icppflags="@CPPFLAGS@"
icxxflags="@KERNEL_CXXFLAGS@ @DEPCFLAGS@"
icflags="@KERNEL_CFLAGS@ @DEPCFLAGS@"
command="${CXX-@KERNEL_CXX@} ${DEFS-$idefs} ${INCLUDES-$iincludes} ${CPPFLAGS-$icppflags} ${CXXFLAGS-$icxxflags} $cflags $compileflag"
c_command="${CC-@CC@} ${DEFS-$idefs} ${INCLUDES-$iincludes} ${CPPFLAGS-$icppflags} ${CFLAGS-$icflags} $cflags $compileflag"
driver=linuxmodule;;
b|bs|bsd|bsdm|bsdmo|bsdmod|bsdmodu|bsdmodul|bsdmodule)
idefs="@DEFS@ -DCLICK_BSDMODULE"
iincludes="-nostdinc ${include_source} -I${includedir}"
icppflags="@CPPFLAGS@"
icxxflags="-fPIC @KERNEL_CXXFLAGS@ @DEPCFLAGS@"
icflags="-fPIC @KERNEL_CFLAGS@ @DEPCFLAGS@"
command="${CXX-@KERNEL_CXX@} ${DEFS-$idefs} ${INCLUDES-$iincludes} ${CPPFLAGS-$icppflags} ${CXXFLAGS-$icxxflags} $cflags $compileflag"
c_command="${CC-@CC@} ${DEFS-$idefs} ${INCLUDES-$iincludes} ${CPPFLAGS-$icppflags} ${CFLAGS-$icflags} $cflags $compileflag"
driver=bsdmodule;;
ns|nsm|nsmo|nsmod|nsmodu|nsmodul|nsmodule)
idefs="@DEFS@ -DCLICK_NS"
iincludes="${include_source} -I${includedir}"
icppflags="@CPPFLAGS@"
icxxflags="-fPIC -fno-builtin @CXXFLAGS@ @DEPCFLAGS@"
icflags="-fPIC -fno-builtin @CFLAGS@ @DEPCFLAGS@"
command="${CXX-@CXX@} ${DEFS-$idefs} ${INCLUDES-$iincludes} ${CPPFLAGS-$icppflags} ${CXXFLAGS-$icxxflags} $cflags $compileflag"
c_command="${CC-@CC@} ${DEFS-$idefs} ${INCLUDES-$iincludes} ${CPPFLAGS-$icppflags} ${CFLAGS-$icflags} $cflags $compileflag"
driver=ns;;
t|to|too|tool)
idefs="@DEFS@ -DCLICK_TOOL"
iincludes="${include_source} -I${includedir}"
icppflags="@CPPFLAGS@"
icxxflags="-fPIC @CXXFLAGS@ @DEPCFLAGS@"
icflags="-fPIC @CFLAGS@ @DEPCFLAGS@"
command="${CXX-@CXX@} ${DEFS-$idefs} ${INCLUDES-$iincludes} ${CPPFLAGS-$icppflags} ${CXXFLAGS-$icxxflags} $cflags $compileflag"
c_command="${CC-@CC@} ${DEFS-$idefs} ${INCLUDES-$iincludes} ${CPPFLAGS-$icppflags} ${CFLAGS-$icflags} $cflags $compileflag"
driver=tool;;
"")
echo "click-compile: you must specify a driver" 1>&2; exit 1;;
*)
echo "click-compile: acceptable drivers are 'userlevel', 'linuxmodule'," 1>&2
echo "click-compile: 'bsdmodule', and 'tool'" 1>&2; exit 1;;
esac
exec_command () {
if test -z "$quiet"; then
echo "$@" 1>&2
fi
eval "$@" || exit 1
}
compile_file () {
option=
source="$1"; shift
if test -r "$source"; then
option=`head -n 5 $source | grep '^/\*\* click-compile:' | sed -e 's/\/\*\* click-compile://g' -e 's/\*\///g'`
fi
exec_command $command $option $source "$@"
}
# do stuff
if test "x$package" != "xNONE"; then
command="$command -DCLICK_PACKAGE"
files=; rmfiles=
trap 'rm -f $rmfiles' 0
trap 'rm -f $rmfiles; exit 1' 1 2 15
for file; do
if echo "$file" | grep '\.cc*$' >/dev/null 2>&1; then
objfile=`echo "$file" | sed 's/\.c*$/'"$$"'\.o/;s/^.*\///'`
compile_file $file -o $objfile
rmfiles="$rmfiles $objfile "`echo $objfile | sed 's/\.o/\.d/'`
else
objfile="$file"
fi
files="$files $objfile"
done
if test $driver = linuxmodule; then
vfile=kernelversion$$
test -f $vfile.c && echo "click-compile: A file '$vfile.c' already exists in this directory!" 1>&2 && echo "click-compile: You must remove it, or run me somewhere else." 1>&2 && exit 1
files="$files $vfile.o"
rmfiles="$rmfiles $vfile.o $vfile.c $vfile.d"
cat > $vfile.c <<EOF
#include <click/config.h>
#include <linux/module.h>
/* a new version of EXPORT_NO_SYMBOLS that works */
const int __ksymtab_nothing[0] __attribute__((section("__ksymtab"))) = { };
EOF
if test $gpl = y; then
cat >> $vfile.c <<EOF
#ifdef MODULE_LICENSE
MODULE_LICENSE("Dual BSD/GPL");
#endif
EOF
fi
c_command_nowarn=`echo $c_command | sed 's/-W[-a-z]*//g'`
exec_command $c_command_nowarn $vfile.c
exec_command "ld -r -o $package $cflags $files"
exit 0
elif test $driver = userlevel -o $driver = tool -o $driver = ns; then
exec_command "${CXX-@CXX@} ${CXXFLAGS-$icxxflags} @LDMODULEFLAGS@ -o $package $cflags $files"
exit 0
elif test $driver = bsdmodule; then
exec_command "ld -Bshareable -o $package $cflags $files"
exit 0
fi
else
exec_command "$command $@"
exit 0
fi