-
Notifications
You must be signed in to change notification settings - Fork 533
/
configure
executable file
·2583 lines (2168 loc) · 56.1 KB
/
configure
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
BUILDDIR=$PWD
SRCDIR=$(cd $(dirname $0); pwd)
MODNAME=netmap
DEBUG=1
UTILS=1
DRVERRFAIL=
DMASYNC=1
# setelem2n <set> <elem>
setelem2n()
{
local i=1
local n
for n in $(eval echo \$$1_avail); do
if [ $n = $2 ]; then
echo $i
return
fi
i=$((2 * i))
done
}
# setop <set> <op> [<elem>]
setop()
{
local w
local n
local s
local e
case "$2" in
new)
eval "$1_avail=\$$3_avail; $1="
return
;;
copy)
eval "$1=\$$3"
return
;;
intersect)
eval "$1=\$(($1 & $3))"
return
;;
subtract)
eval "$1=\$(($1 & ~$3))"
return
;;
esac
if [ -n "$3" ]; then
w=$(setelem2n $1 $3)
[ -n "$w" ] || {
echo "unknown $1: $3" | warning
return
}
fi
case "$2" in
is-empty)
[ $(eval echo \$$1) -eq 0 ]
;;
disable-all)
eval "$1=0"
;;
enable-all)
eval "$1=0"
s=$(eval echo \$$1_avail)
for n in $s; do
eval "$1=\$(( ($1 << 1) | 1))"
done
;;
enable)
eval "$1=\$(($1 | $w))"
;;
disable)
eval "$1=\$(($1 & ~$w))"
;;
enabled)
eval "w=\$(($1 & $w))"
[ $w -ne 0 ]
;;
print)
s=$(eval echo \$$1_avail)
e=
for n in $s; do
w=$(setelem2n $1 $n)
eval "w=\$(($1 & $w))"
[ $w -ne 0 ] && e="$n $e"
done
echo $e
;;
esac
}
# available subsystems
subsystem_avail="vale pipe monitor generic ptnetmap sink \
extmem null"
#enabled subsystems (bitfield)
subsystem=0
subsys()
{
setop subsystem "$@"
}
subsys enable vale
subsys enable pipe
subsys enable monitor
subsys enable generic
subsys enable null
subsys enable ptnetmap
# available drivers
driver_avail="stmmac r8169.c virtio_net.c forcedeth.c veth.c \
e1000 e1000e igb igc ixgbe ixgbevf ice i40e vmxnet3 mlx5"
# enabled drivers (bitfield)
driver=
drv()
{
setop driver "$@"
}
drv enable-all
# drivers built by external commands (subset of driver)
setop external_driver new driver
edrv()
{
setop external_driver "$@"
}
edrv enable e1000e
edrv enable igb
edrv enable ixgbe
edrv enable ixgbevf
edrv enable i40e
edrv enable ice
edrv enable mlx5
edrv enable virtio_net.c
# drivers built by patching the system drivers
setop internal_driver new driver
idrv()
{
setop internal_driver "$@"
}
# external drivers that don't need the pre-patch test
setop custom_driver new driver
cdrv()
{
setop custom_driver "$@"
}
cdrv enable virtio_net.c
update_drivers() {
edrv intersect driver
idrv copy driver
idrv subtract external_driver
}
update_drivers
# available apps
application_avail="pkt-gen bridge lb tlem nmreplay vale-ctl dedup"
application=0
app()
{
setop application "$@"
}
# enable all by default
app enable-all
prefix=/usr/local
cc=cc
ld=ld
# with <command>: success iff <command> is available
with() {
type $1 >/dev/null 2>&1
}
print_realpath() {
if with realpath; then
rp=$(realpath "$1")
if [ "$rp" != "$1" ]; then
echo " [$rp]"
fi
fi
}
decode_version() {
if [ -n "$1" ] && with perl; then
echo " [$($SRCDIR/scripts/vers $1 -C)]"
fi
}
# report: print the current state of the configuration variables
report() {
echo "kernel directory $ksrc"
print_realpath $ksrc
echo "kernel sources $src"
print_realpath "$src"
local v=$lin_ver
[ -n "$v" ] || v="-"
local dv="$(decode_version $lin_ver)"
echo "linux version $v $dv"
echo "module file $MODNAME.ko"
echo
echo "subsystems $(subsys print)"
echo "apps $(app print)"
echo "native drivers $(drv print)"
echo
if [ -f "drivers.mak" ]; then
cat <<EOF
Contents of the drivers.mak file:
EOF
cat drivers.mak
fi
}
message()
{
{
cat <<EOF
********************************** $1 **********************************
EOF
sed 's/^/*** /' # output the error message from stdin
if [ -n "$2" ]; then
cat <<EOF
***
***
*** Current configuration values:
***
EOF
report | sed 's/^/*** /'
fi
cat <<EOF
*****************************************************************************
EOF
} | tee -a config.log
}
# error: format an error msg containing the lines read from stdin
# and exit with failure.
error() {
message " ERROR " true
exit 1
}
warning()
{
message WARNING
}
drverror() {
message WARNING
if [ -n "$DRVERRFAIL" ]; then
error <<EOF
Exiting because of --fail-on-driver-errors.
EOF
fi
}
replace_vars()
{
sed \
-e "s|@BUILDDIR@|$BUILDDIR|g" \
-e "s|@SRCDIR@|$SRCDIR|g" \
-e "s|@TMPDIR@|$TMPDIR|g" \
-e "s|@KSRC@|$ksrc|g" \
-e "s|@SRC@|$src|g" \
-e "s|@KOPTS@|$kopts|g" \
-e "s|@MODPATH@|$modpath|g" \
-e "s|@MODNAME@|$MODNAME|g" \
-e "s|@SUBSYS@|$(subsys print)|g" \
-e "s|@LIN_VER@|$lin_ver|g" \
-e "s|@MOD_LIST@|$mod_list|g" \
-e "s|@PATCHES@|$(echo $patches)|g" \
-e "s|@S_DRIVERS@|$(drv print)|g" \
-e "s|@E_DRIVERS@|$(edrv print)|g" \
-e "s|@I_DRIVERS@|$(idrv print)|g" \
-e "s|@DRVSUFFIX@|$drvsuffix|g" \
-e "s|@APPS_LIST@|$(app print)|g" \
-e "s|@APPS_CC@|$cc|g" \
-e "s|@APPS_LD@|$ld|g" \
-e "s|@PREFIX@|$prefix|g" \
-e "s|@DESTDIR@|$DESTDIR|g" \
-e "s|@DEBUG@|$DEBUG|g" \
-e "s|@UTILS@|$UTILS|g" \
-e "s|@REC_DISABLED_WARNINGS@|$REC_DISABLED_WARNINGS|g" \
$1
}
# print_help
print_help() {
cat <<EOF
Available options:
--help print this message
--kernel-dir= path to configured kernel directory
--kernel-sources= path to full kernel sources
--kernel-version= specify the kernel version
(assuming everything is in the default place)
--kernel-opts= additional options to pass to kernel make
(you can call this several times)
--install-mod-path= where the modules will be installed
--driver-suffix= add suffix to the patched modules names
--no-drivers do not compile any driver
--no-drivers= do not compile the given drivers (comma sep.)
--drivers= only compile the given drivers (comma sep.)
--no-ext-drivers do not use external drivers
--no-ext-drivers= do not use the given external drivers (comma sep.)
--select-version= comma sep. list of driver:version expressions
(select a different versions for external drivers)
--fail-on-driver-errors stop the build when a driver fails to compile,
rather than disabling it
--no-apps do not compile any app
--no-apps= do not compile the given apps (comma sep.)
--apps= only compile the given apps (comma sep.)
--no-utils do not compile the utils
--mod-name= netmap module name [$MODNAME]
--enable-vale enable the VALE switch
--disable-vale disable the VALE switch
--enable-pipe enable the netmap pipes
--disable-pipe disable the netmap pipes
--enable-monitor enable the nemtap monitors
--disable-monitor disable the nemtap monitors
--enable-generic enable the generic netmap adapter
--disable-generic disable the generic netmap adapter
--enable-ptnetmap enable ptnetmap
--disable-ptnetmap disable ptnetmap
--enable-sink enable the netmap sink device
--disable-sink disable the netmap sink device
--enable-extmem enable the external memory allocators
--disable-extmem disable the external memory allocators
--force-debug build the modules w/ debug symbols (default)
--no-force-debug build the modules w/ or w/o debug symbols,
--cache= dir for reusing/caching of netmap_linux_config.h
--without-dmasync use this if you are on x86 with a recent NIC and no IOMMU
--cc= C compiler to be used for the apps and utils [$cc]
--ld= linker to be used for the apps and utils [$ld]
--prefix= install path for the apps and utils [$prefix]
--destdir= destination dir for the apps and utils [$DESTDIR]
--show-drivers print the list of available drivers and exit
--show-ext-drivers print the list of available external drivers and exit
--show-apps print the list of available apps and exit
EOF
}
#################################################################
# machinery for the creation of netmap_linux_config.h #
#################################################################
# We check for the availability/version of several linux
# internal APIs by running compilation tests. The results
# of the tests will produce a set of macros in the
# 'netmap_linux_config.h' file. All macros names begin
# with 'NETMAP_LINUX'.
# TMPDIR is where we build all the tests
TMPDIR=netmap-tmpdir
# tests are first accumulated using add_named_test and add_test, then
# run by run_tests. This setup amortizes the cost of going
# through linux kbuild and opens the opportunity of using the '-j'
# flag of make. Speedup is in the order of x10.
# TESTOBJS will contain the list of test modules to build
TESTOBJS=
# TESTPOSTPROC will contain a script that runs the pertinent
# 'on success' or 'on failure' action for each test at the
# end of 'run_tests'.
TESTPOSTPROC=
# add_file_exists_check <file-name> <on success> [<on failure>]
add_file_exists_check()
{
cmd="if [ -f "$TMPDIR/$1" ]; then $2"
[ -n "$3" ] && cmd="$cmd; else $3"
cmd="$cmd; fi"
cat >> config.log <<EOF
##############################################################################
## cmd: $cmd
##############################################################################
EOF
TESTPOSTPROC="$cmd; $TESTPOSTPROC"
}
# add_named_test <test-name> [<on success> [<on failure>]]:
# the test code is read from stdin, completed with
# some standard modules boiler plate and put in
# $TMPDIR/test-name.c for future compilation by 'run_tests'.
# The optional <on success> script (which must be a single
# argument) will be executed if $TMPDIR/test-name.o will
# be correctly created. The optional <on failure>
# script (one argument) will be executed if compilation fails.
#
# Note: add_test (below) is preferred. Use add_named_test
# only if you need to do some complex check for which you need to
# know the name of the test files.
add_named_test() {
{
cat <<EOF
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
EOF
cat # output the test code read from stdin
cat <<EOF
MODULE_LICENSE("GPL");
EOF
} > $TMPDIR/$1.c
{
cat <<EOF
##############################################################################
## TEST: $1
##############################################################################
EOF
cat $TMPDIR/$1.c
} >> config.log
# add the module to the running list
TESTOBJS="$1.o $TESTOBJS"
# add the postprocess script for this test
if [ -n "$2" ]; then
add_file_exists_check "$1.o" "$2" "$3"
fi
}
# add_test [<on success> [<on failure>]]
# used like add_named_test above, but without the need of
# explicitly naming the test.
NEXTTEST=1
add_test() {
local t="test__$NEXTTEST"
add_named_test $t "$@"
NEXTTEST=$(($NEXTTEST+1))
}
PERTESTFLAGS=
# add_test_flags flags...
# call this immediately before add_test to set special compilation flags
# for the next test
add_test_flags() {
PERTESTFLAGS="$PERTESTFLAGS
CFLAGS_test__$NEXTTEST.o := $@"
}
reset_tests() {
rm -rf $TMPDIR
mkdir $TMPDIR
TESTOBJS=
TESTPOSTPROC=
NEXTTEST=1
cat >> config.log <<EOF
##############################################################################
## NEW TESTS
##############################################################################
EOF
}
# run_preliminary_tests: this must be run before run_tests. It checks some
# options related to the build system itself and sets some variables later
# used by run_tests.
run_preliminary_tests() {
{
cat <<EOF
ifneq (\$(KERNELRELEASE),)
obj-m := $TESTOBJS
EOF
if [ -e $TMPDIR/extra.mk ]; then cat $TMPDIR/extra.mk; fi
cat <<EOF
else
all:
\$(MAKE) -C $ksrc M=\$\$PWD EXTRA_CFLAGS="\$(EXTRA_CFLAGS)" $kopts
endif
EOF
} > $TMPDIR/Makefile
NPROC=$(grep -c processor /proc/cpuinfo)
MAKE_OPT=-O
{
cat <<EOF
##############################################################################
## BEGIN RUNNING PRELIMINARY TESTS: $(date)
##############################################################################
## Makefile:
EOF
cat $TMPDIR/Makefile
cat <<EOF
##############################################################################
EOF
} >> config.log
(
cd $TMPDIR
LANG=C make $MAKE_OPT -k -j $NPROC
) >> config.log 2>&1
if grep -q ": invalid option -- 'O'" config.log; then
MAKE_OPT=
# let us try again without -O
(
cd $TMPDIR
make -k -j $NPROC
) >> config.log 2>&1
fi
eval "$TESTPOSTPROC"
cat >> config.log <<EOF
##############################################################################
## END RUNNING PRELIMINARY TESTS: $(date)
##############################################################################
EOF
}
# run_tests: run all accumulated tests and exec the pertinent
# success/failure actions for each one.
run_tests() {
ln -s $BUILDDIR/patches $TMPDIR
cat > $TMPDIR/Makefile <<EOF
SRCDIR=$SRCDIR
ifneq (\$(KERNELRELEASE),)
obj-m := $TESTOBJS
$PERTESTFLAGS
else
WARN_CFLAGS := -Werror \$(addprefix -Wno-error=,$REC_DISABLED_WARNINGS)
S_DRIVERS := $(drv print)
E_DRIVERS := $(edrv print)
C_DRIVERS := $(cdrv print)
I_DRIVERS := $(idrv print)
TOBUILD := \$(filter-out \$(C_DRIVERS),\$(E_DRIVERS))
all: \$(S_DRIVERS:%=get-%) \$(TOBUILD:%=build-%) \$(I_DRIVERS:%=patch-%) tests
tests:
\$(MAKE) -C $ksrc M=\$\$PWD EXTRA_CFLAGS="\$(WARN_CFLAGS)" $kopts
test__%:
\$(MAKE) -C $ksrc M=\$\$PWD EXTRA_CFLAGS="\$(WARN_CFLAGS)" $kopts \$@.o
-include $BUILDDIR/extdrv-versions.mak
-include $BUILDDIR/default-config.mak
-include $BUILDDIR/config.mak
-include $BUILDDIR/drivers.mak
EOF
for d in $(drv print); do
cat >> $TMPDIR/Makefile <<EOF
get-$d:
\$($d@fetch)
\$($d@src)
touch get-$d
prepare-$d: get-$d
\$($d@prepare)
touch prepare-$d
build-$d: prepare-$d
+\$($d@build)
touch build-$d
patch-$d: get-$d
\$(foreach p,\$($d@patch),patch --quiet --force -p1 < \$(p);)
touch patch-$d
EOF
done
echo endif >> $TMPDIR/Makefile
{
cat <<EOF
##############################################################################
## BEGIN RUNNING TESTS: $(date)
##############################################################################
## Makefile:
EOF
cat $TMPDIR/Makefile
cat <<EOF
##############################################################################
EOF
} >> config.log
(
cd $TMPDIR
make $MAKE_OPT -k -j $NPROC
) >> config.log 2>&1
eval "$TESTPOSTPROC"
cat >> config.log <<EOF
##############################################################################
## END RUNNING TESTS: $(date)
##############################################################################
EOF
}
configh=netmap_linux_config.h
# success/failure actions are expected to write some macros
# in netma_linux_config.h. The following functions can be
# used to simplify the task.
# define <macro> <value>: define NETMAP_LINUX_<macro> as <value>
define() {
cat >> $configh <<EOF
#define NETMAP_LINUX_$1 $2
EOF
}
# have <macro>: define NETMAP_LINUX_HAVE_<macro>
have() {
define "HAVE_$1"
}
############################
# parse options
############################
ksrc=
src=
kopts=
modpath=
drvsuffix=
cache=
versions=
for opt do
optarg=${opt#*=}
case "$opt" in
--kernel-dir=*) ksrc="$optarg"
;;
--kernel-sources=*) src="$optarg"
;;
--kernel-version=*) ksrc="/lib/modules/$optarg/build"
;;
--kernel-opts=*) kopts="$kopts $optarg"
;;
--install-mod-path=*) modpath="$optarg"
;;
--driver-suffix=*) drvsuffix="$optarg"
;;
--no-drivers) drv disable-all
;;
--no-drivers=*)
drv enable-all
for d in $(echo "$optarg" | sed 's/,/ /g'); do
drv disable "$d"
done
;;
--no-ext-drivers) edrv disable-all
;;
--no-ext-drivers=*)
for d in $(echo "$optarg" | sed 's/,/ /g'); do
edrv disable "$d"
done
;;
--drivers=*)
drv disable-all
for d in $(echo "$optarg" | sed 's/,/ /g'); do
drv enable "$d"
done
;;
--no-apps) app disable-all
;;
--no-apps=*)
app enable-all
for d in $(echo "$optarg" | sed 's/,/ /g'); do
app disable "$d"
done
;;
--apps=*)
app disable-all
for d in $(echo "$optarg" | sed 's/,/ /g'); do
app enable "$d"
done
;;
--select-version=*)
if [ -z "$versions" ]; then
versions=$optarg
else
versions="$versions,$optarg"
fi
;;
--cc=*) cc="$optarg"
;;
--ld=*) ld="$optarg"
;;
--prefix=*) prefix="$optarg"
;;
--destdir=*) DESTDIR="$optarg"
;;
--mod-name=*) MODNAME="$optarg"
;;
--disable-*)
subsys disable "${opt#--disable-}"
;;
--enable-*)
subsys enable "${opt#--enable-}"
;;
--cache=*) cache="$optarg"
;;
--help | -h)
print_help
exit
;;
--show-drivers)
drv print
exit
;;
--show-ext-drivers)
edrv print
exit
;;
--show-apps)
app print
exit
;;
--force-debug)
DEBUG=1
;;
--no-force-debug)
DEBUG=
;;
--no-utils)
UTILS=
;;
--fail-on-driver-errors)
DRVERRFAIL=1
;;
--without-dmasync)
DMASYNC=
;;
*)
echo "Unrecognized option: $opt" | warning
;;
esac
done
# update the divers subsets so that they are all consistent
update_drivers
####################################################################
################### START OF PROCESSING ############################
####################################################################
rm -f config.log
{
echo "# netmap configure log $(date)"
echo "# Configured with:"
printf " '%s'" "$0" "$@"
echo
echo "#"
} > config.log
exec 2>> config.log
cp pre-commit .git/hooks
appl_arch=$($cc -dumpmachine | cut -d '-' -f 1)
if [ $appl_arch != "x86_64" ]; then
# dedup uses inline x86_64 assembly
app disable dedup
fi
################################
# check for sane configuration
################################
[ -n "$kernelver" ] || {
kernelver="$(uname -r)"
}
[ -n "$ksrc" ] || {
# user did not provide a kernel dir,
# we try to find one by ourselves
ksrc="/lib/modules/${kernelver}/build"
}
[ -n "$src" ] || {
# user did not provide the path for the full kernel sources
# we try to find one by ourselves
[ -d "$ksrc/source" ] && src="$ksrc/source"
[ -n "$src" ] || src=$ksrc
}
if [ ! -d "$ksrc" ]; then
error <<EOF
Cannot find kernel directory.
We need at least the kernel headers to compile the netmap kernel module.
If your kernel headers are not in the standard place, please provide the
correct path using the
--kernel-dir=/path/to/kernel/dir
option.
Otherwise, check that the 'build' symlink in
/lib/modules/\$(uname -r)
is not broken.
EOF
fi
ksrc=$(cd $ksrc; pwd)
# check that ksrc has been prepared for external modules compilation
# It should contain a version.h file (in one of two possible places,
# depending on kernel version, and a .config file)
version_hdr="$ksrc/include/generated/uapi/linux/version.h"
[ -f "$version_hdr" ] || version_hdr="$ksrc/include/linux/version.h"
if [ ! -f "$ksrc/.config" ] || [ ! -f "$version_hdr" ]; then
error <<EOF
kernel not configured.
The kernel directory must be ready for external module compilation.
You may need to issue the following or equivalent commands:
cd $ksrc
make oldconfig
make modules_prepare
EOF
fi
lin_ver=$(awk '/LINUX_VERSION_CODE/ { printf "%03x%02x", $3/256, $3%256}' "$version_hdr")
#################################################
# preliminary build tests
#################################################
reset_tests
broken_buildsystem() {
error <<EOF
It looks like we are not able to build kernel modules for the current
configuration. Please check 'config.log' for possible clues.
EOF
}
add_test true broken_buildsystem < /dev/null
DISABLED_WARNINGS="unused-but-set-variable attributes packed-not-aligned \
stringop-truncation missing-attributes format-truncation \
maybe-uninitialized unused-variable unused-label \
implicit-fallthrough enum-int-mismatch missing-prototypes"
REC_DISABLED_WARNINGS=
disable_warning() {
REC_DISABLED_WARNINGS="$1 $REC_DISABLED_WARNINGS"
}
i=1
for w in $DISABLED_WARNINGS; do
add_named_test "__warn__$i" "disable_warning $w" < /dev/null
echo "CFLAGS___warn__$i.o = -Wno-error=$w" >> $TMPDIR/extra.mk
i=$(($i+1))
done
message " NOTE " <<EOF
Running some preliminary tests to customize the build environment.
EOF
run_preliminary_tests
# create the versions file
rm -f extdrv-versions.mak
for dv in $(echo "$versions" | sed 's/,/ /g'); do
d=${dv%:*}
v=${dv#*:}
if ! edrv enabled $d; then
echo "$d is not an external driver" | warning
fi
echo "$d@v := $v" >> extdrv-versions.mak
done
replace_vars $SRCDIR/default-config.mak.in_ > default-config.mak
replace_vars $SRCDIR/intel-fix.sh_ > intel-fix.sh
chmod +x intel-fix.sh
###############################################################
# Makefile creation
###############################################################
# here we select the patches for the drivers and create the
# main Makefile. The Makefile is obtained from Makefile.in
# with some values replaced in (mainly the kernel directory).
# The final Makefile will include drivers.mak, which is also
# created here. drivers.mak will contain a <driver>@src
# and <driver>@patch variable each of the available drivers.
mod_list=
if ! drv is-empty; then
[ -d patches ] || { rm -f patches; ln -s $SRCDIR/final-patches patches; }
fi
ln -s $SRCDIR/read-vars.mak 2>/dev/null || true
rm -f drivers.mak
# read in all the kernel .config, we use it below
. $ksrc/.config
# check for full kernel sources just once
src_checked=
src_found=
# cache
e_drivers=$(edrv print)
for d in $(drv print); do
# reset all driver variables to default values
drv_fetch=
drv_src=
drv_patch=
drv_build=
drv_distclean=
drv_conf="CONFIG_$(basename $d .c | tr a-z- A-Z_)"
# possibly override from config.mak
eval $(make -snrf read-vars.mak $d@vars E_DRIVERS="$e_drivers")
# check that the original driver had been compiled as a module, otherwise
# skip this driver
# (we do this mainly to be sure that any module dependency has already
# been taken care of)
if [ -z "$drv_force" ]; then
m="$(eval echo \$$drv_conf)"
[ -n "$m" ] || {
echo "$drv_conf not set in $ksrc/.config, skipping $d" | warning
drv disable $d
continue
}
fi
[ "$m" = y ] && [ -z "$drvsuffix" ] && {
warning <<EOF
The $d driver is not compiled as a module:
you will not be able to load the netmap enabled driver on this kernel.
Please consider setting
$drv_conf=m
in your .config.
Alternatively, you can pass a --driver-suffix= option to configure.
EOF
}
if [ -n "$drv_fetch" ]; then
message " NOTE " <<EOF
We are trying to download the original sources for driver
$d using the following command:
$drv_fetch
If this fails, please download the above file and put it
in $SRCDIR/ext-drivers/, then run configure again.
EOF
eval $drv_fetch 2>&1 || { drverror <<EOF
Unable to fetch the sources for driver $d. Disabling driver.
EOF
drv disable $d
continue
}
fi
if [ -z "$drv_src" ]; then
# if the user has asked for the patched drivers, we also need the
# full kernel sources. Since we may have put $src=$ksrc, and $ksrc
# may only contain header files, we check that $src/drivers actually
# contains some .c file
if [ -z "$src_checked" ]; then
if [ ! -d "$src" ] || [ -z "$(find "$src/drivers" -name '*.c' -print -quit)" ]; then {
cat <<EOF
Cannot find full kernel sources.
Please note that most distributions provide separate packages for kernel
headers and sources. Once you know the path to kernel sources, you can
rerun this script with the additional
--kernel-sources=/path/to/sources
option.
Native drivers that are listed as disabled below are not going to be built.
EOF
if subsys enabled generic; then
cat <<EOF
The corresponding devices will be accessed using a generic driver at
reduced performance.
EOF
else
cat <<EOF
Since the generic driver has been disabled, the corresponding NICs
will NOT be usable by netmap.
EOF
fi
} | warning
else
src=$(cd $src; pwd)
src_found=1
fi
src_checked=1
fi
drv_kernel_src=
if [ -n "$src_found" ]; then
drv_kernel_src=$(find $src/drivers/ -name "$d" -print -quit)
fi
if [ -z "$drv_kernel_src" ]; then
drverror <<EOF
'$d': sources not found. Disabling driver.
EOF
drv disable $d
continue
fi