Dash:
[t2-trunk.git] / package / base / linux / linux-conf.in
blob74f2d24d9ccc2222ceae5e4adae5eca18ee64d65
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by scripts/Create-CopyPatch.
3
4 # T2 SDE: package/*/linux/linux-conf.in
5 # Copyright (C) 2004 - 2021 The T2 SDE Project
6 # Copyright (C) 1998 - 2003 ROCK Linux Project
7
8 # More information can be found in the files COPYING and README.
9
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; version 2 of the License. A copy of the
13 # GNU General Public License can be found in the file COPYING.
14 # --- T2-COPYRIGHT-NOTE-END ---
16 if [ ! "$lx_cpu" ]; then
17         lx_cpu=`echo $arch | arch2uname |
18         sed 's/mips64/mips/;s/bfin/blackfin/;s/aarch64/arm64/;s/hppa.*/parisc/;s/riscv64/riscv/;s/s390x/s390/'`
19         # unifications since ~2.6
20         lx_cpu=`echo $lx_cpu | sed 's/i386/x86/;s/x86_64/x86/;s/ppc.*/powerpc/'`
22 lx_extraversion=""
23 lx_kernelrelease=""
24 lx_customconf="\$base/config/$config/linux.cfg"
26 # cleanups in this fat directory are a bit expensive
27 nocvsinsrcdir=0
28 chownsrcdir=0
30 # inject a possible pre-/ post-release patch
31 # we filter out .tar`s to avoid trouble with the linuxsh kernel drop-in trees
32 var_insert patchfiles " " "`match_source_file patch-.* | grep -v '\.tar\.'`"
34 makeopt=`echo $makeopt | sed -n 's/.*\(-j[^ ]*\).*/\1/p'`
35 var_append makeopt ' ' "ARCH=$lx_cpu CROSS_COMPILE=$archprefix HOSTCC=cc KCC=$KCC"
36 makeinstopt="$makeopt"
38 auto_config () {
39         if [ -f $base/architecture/$arch/linux.conf ]; then
40                 echo "  using: architecture/$arch/linux.conf"
41                 cp $base/architecture/$arch/linux.conf .config
42         elif [ -f $base/architecture/$arch/linux.conf.sh ]; then
43                 echo "  using: architecture/$arch/linux.conf.sh"
44                 . $base/architecture/$arch/linux.conf.sh > .config
45         elif [ -f $base/architecture/$arch/linux.conf.m4 ]; then
46                 echo "  using: architecture/$arch/linux.conf.m4"
47                 m4 -I $base/architecture/$arch -I $base/architecture/share \
48                    $base/architecture/$arch/linux.conf.m4 > .config
49         else
50                 echo "  using: no SDE linux kernel config found"
51                 cp arch/$lx_cpu/defconfig .config
52         fi
53         case "$SDECFG_OPT" in
54           size*|smart) echo "CONFIG_CC_OPTIMIZE_FOR_SIZE=y" >> .config ;;
55           *) echo "# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set" >> .config ;;
56         esac
57         cp .config{,.1}
59         # all modules needs to be first so modules can be disabled by i.e.
60         # the targets later
61         echo "Enabling all modules ..."
62         yes '' | eval $MAKE $makeopt no2modconfig > /dev/null; cp .config{,.2}
64         if [ -f $base/target/$target/linux.conf.sh ]; then
65                 confscripts="$base/target/$target/linux.conf.sh $confscripts"
66         fi
68         for x in $confscripts; do
69                 echo "  running: $x"
70                 sh $x .config
71         done
72         cp .config{,.3}
74         # merge various text/plain config files
75         for x in $base/config/$config/linux.cfg \
76                  $base/target/$target/linux.conf; do
77            if [ -f $x ]; then
78                 echo "  merging: '$x'"
79                 tag="$(sed '/CONFIG_/ ! d; s,.*CONFIG_\([^ =]*\).*,\1,' \
80                         $x | tr '\n' '|')"
81                 egrep -v "\bCONFIG_($tag)\b" < .config > .config.4
82                 sed 's,\(CONFIG_.*\)=n,# \1 is not set,' \
83                         $x >> .config.4
84                 cp .config{.4,}
85            fi
86         done
88         # create a valid .config
89         yes '' | eval $MAKE $makeopt oldconfig > /dev/null; cp .config{,.5}
91         # last disable broken stuff
92         rm -f /tmp/$$.sed
93         list="CONFIG_THIS_DOES_NOT_EXIST"
94         for x in $pkg_linux_brokenfiles; do
95             if [ -f "$x" ]; then
96                 echo "Disable broken file: $x"
97                 list="$list `tr ' ' '\t' < $x | cut -f1 | grep '^CONFIG_'`"
98             fi
99         done
100         for x in $list; do
101                 echo "s,^$x=.\$,# $x is not set,;" >> /tmp/$$.sed
102         done
104         sed -f /tmp/$$.sed < .config > .config.6
105         cp .config{.6,}; rm -f /tmp/$$.sed
107         # create a valid .config (dependencies might need to be disabled)
108         yes '' | eval $MAKE $makeopt oldconfig > /dev/null
110         # save final config
111         cp .config{,_modules}
113         echo "Creating config without modules ...."
114         sed "s,\(CONFIG_.*\)=m,# \1 is not set," .config > .config_new
115         mv .config_new .config
116         # create a valid .config (dependencies might need to be disabled)
117         yes '' | eval $MAKE $makeopt oldconfig > /dev/null
118         mv .config .config_nomods
120         # which .config to use?
121         if [ "$SDECFG_PKG_LINUX_CONFIG_STYLE" = "modules" ]; then
122                 cp .config{_modules,}
123         else
124                 cp .config{_nomods,}
125         fi
128 lx_grabextraversion () {
129         local ev
130         ev=$( sed -n -e 's,^[ \t]*EXTRAVERSION[ \t]*=[ \t]*\([^ \t]*\),\1,p' Makefile | tail -n 1 )
131         if [ "$ev" ]; then
132                 lx_extraversion="${lx_extraversion}${ev}"
133                 # keep intact but commented since the second EXTRAVERSION
134                 # definition, and clean the first.
135                 sed -i -e 's,^\([ \t]*EXTRAVERSION[ \t]*=.*\),#\1,g' \
136                        -e 's,^#\(EXTRAVERSION =\).*,\1,' Makefile
137         fi
139 lx_injectextraversion () {
140         # inject final EXTRAVERSION into Makefile
141         sed -i -e "s,^\([ \t]*EXTRAVERSION[ \t]*\)=.*,\1= ${lx_extraversion},g" Makefile
143         # update version.h - we only do this, because some other freaky
144         # projects like rsbac change EXTRAVERSION in other Makefiles ...
145         local rerun=""
146         ( eval $MAKE $makeopt include/generated/utsrelease.h ||
147           eval $MAKE $makeopt include/linux/utsrelease.h ||
148           eval $MAKE $makeopt include/linux/version.h ) |
149                 grep -q "is up to date" && rerun=1
150         if [ "$rerun" ]; then
151                 echo "WARNING: Your system's timer resolution is too low ..."
152                 sleep 1; touch Makefile
153                 eval $MAKE $makeopt include/generated/utsrelease.h ||
154                 eval $MAKE $makeopt include/linux/utsrelease.h ||
155                 eval $MAKE $makeopt include/linux/version.h
156         fi
158         # get kernel_release
159         rerun=1
160         while true; do
161                 for fn in include/generated/utsrelease.h \
162                           include/linux/utsrelease.h \
163                           include/linux/version.h; do
164                         [ -f $fn ] && versionh=$fn && break
165                 done
167                 lx_kernelrelease="$( echo -e "#include \"$versionh\"\nUTS_RELEASE" |
168                                      $KCC -E - | tail -n 1 | cut -d '"' -f 2 )"
169                 if [ -z "$lx_kernelrelease" -a "$rerun" ]; then
170                         $MAKE $makeopt .kernelrelease include/linux/version.h
171                         $MAKE $makeopt include/generated/utsrelease.h ||
172                         $MAKE $makeopt include/linux/utsrelease.h
173                         rerun=; continue
174                 fi
175                 break
176         done
178         if [ ! "$lx_kernelrelease" -o "$lx_kernelrelease" = "UTS_RELEASE" ]; then
179                 abort "Could not grab final kernel version!"
180         fi
183 lx_filter_patch () {
184         local prefix="`sed -n '/^-EXTRAVERSION =/ {
185                                s/^-EXTRAVERSION =//p
186                                q }' $1`"
187         # whitespace after EXTRAVERSION must be preserve to apply
188         expr=
189         # only tweak EXTRAVERSION if no space content
190         [ "${prefix%% }" != ""  ] &&
191                 var_append expr ';'  "s/^-EXTRAVERSION =.*/-EXTRAVERSION =/"
192         var_append expr ';' "s/^+EXTRAVERSION = *$prefix/+EXTRAVERSION =/"
194         sed -e "$expr" $1
197 lx_patch () {
198         echo "Generic linux patching ..."
200         # grab extraversion from vanilla
201         lx_grabextraversion
203         apply_patchfiles lx_grabextraversion lx_filter_patch
205         # some arches (avr32, sh64 at the time of writing) have a "defect" Makefile
206         # and do not work without a .config ...
207         yes '' | eval $MAKE $makeopt oldconfig > /dev/null
209         echo "Redefining VERSION  ..."
210         lx_extraversion="${lx_extraversion}-t2"
211         lx_injectextraversion
212         echo "... linux source patching for ${lx_extraversion} finished."
214         echo "Clean up the *.orig and *~ files ... "
215         rm -f .config.old .config
218 lx_config() {
219         echo "Generic linux configuration ..."
220         if [ "$SDECFG_PKG_LINUX_CONFIG_STYLE" = none ]; then
221                 echo "Using $lx_customconf."
222                 echo "Since automatic generation is disabled ..."
223                 eval cp -v $lx_customconf .config || true
224         else
225                 echo "Automatically creating default configuration ...."
226                 auto_config
227         fi
229         # regrab for stuff like rsbac ... :-(
230         lx_injectextraversion
232         echo "... configuration of $lx_kernelrelease finished!"
235 pkg_linux_brokenfiles="$base/architecture/$arch/linux-disable.lst \
236         $base/package/*/linux/disable-broken.lst \
237         $pkg_linux_brokenfiles"