3 # this script is brutal and verbose, has no tricks and is quite linear, then
4 # quite easy to deal with
5 # for the moment, it's hardcoded for a gcc toolchain... BAD! Since now
6 # gcc is a c++ piece of shit
8 # stolen from ffmpeg configure like a pig
11 # prevent locale nonsense from breaking basic text processing
17 init_ulinux_src_files
='
18 ulinux/utils/ascii/string/vsprintf.c
20 ulinux/utils/ascii/string/conv/decimal/decimal.c
29 $init_ulinux_src_files
34 printf '###############################################################################\n'
39 printf '###############################################################################\n\n'
44 printf '*******************************************************************************\n'
49 printf '*******************************************************************************\n'
52 ################################################################################
59 [ $var = $value ] && return 0
65 echo "Unknown option \"$1\"."
66 echo "See $0 --help for available options."
72 eval : \
${$opt:=\$${opt}_default}
78 kernel_modules_base_dir
90 # command line set defaults
91 # if the root is not around in less than 4s, something is really wrong
92 uevents_timeout_default
=4000
93 gen_init_cpio_default
='$linux_build_dir/usr/gen_init_cpio'
94 linux_build_dir_default
=/usr
/src
/linux
95 #-------------------------------------------------------------------------------
96 # this defaults are for gcc, tested with version 4.7.3. You will need to
97 # override those for you compiler (tinycc/open64/pcc...). additionnally, source
98 # support for different toolchains is not done
99 # since we use standard C runtime libs, be nice with the C runtime
100 init_cpp_default
='gcc -E -Wall -Wextra'
101 init_cc_default
='gcc -Wall -Wextra -Wno-implicit-fallthrough -std=gnu99 -O2 -c'
102 init_ccld_default
='gcc -Wl,-s -static'
103 #-------------------------------------------------------------------------------
104 kernel_modules_base_dir_default
=/
105 kernel_release_default
=$
(uname
-r)
106 init_ulinux_arch_default
=$
(uname
-m |
sed -e s
/i
.86/i386
/ -e s
/parisc64
/parisc
/ -e s
/sun4u
/sparc64
/ -e s
/arm.
*/arm
/ -e s
/sa110
/arm
/ -e s
/sh.
*/sh
/)
107 extra_modules_default
=
108 pkg_config_default
=pkg-config
109 elf_interpreter_default
=
111 set_default
$CMDLINE_SET
116 Usage: make [options] [operations]
118 default is to build the the initramfs xz compressed cpio archive:
120 Options: [defaults in brackets after descriptions]
123 --help print this message
126 --lib-path-list=LIB_PATH_LIST colon separated paths to look for target libraries
127 --uevents-timeout=UEVENTS_TIMEOUT uevents timeout in ms looking up for root block device to go online [$uevents_timeout]
128 --quiet init will be silenced (output code compiled out)
129 --linux-build-dir=DIR where to find the target linux build tree [$linux_build_dir_default]
130 --kernel-release=RELEASE the linux releases version [$kernel_release]
131 --kernel-modules-base-dir=DIR the base dir for linux modules and support files [$kernel_modules_base_dir]
132 --extra-modules=EXTRA_MODULES coma separated list of extra module to probe
135 --gen-init-cpio=GEN_INIT_CPIO_PATH use this linux host tool to build the linux cpio initramfs [$gen_init_cpio_default]
136 --pkg-config=PKG_CONFIG use PKG_CONFIG pkg-config command for target libraries [$pkg_config_default]
137 --init-cpp=CPP use CPP compiler command line CPP for target init process [$init_cpp_default]
138 --init-cc=CC use C compiler command line CC for target init process objects [$init_cc_default]
139 --init-ccld=CCLD use compiler driver linker command line CCLD for target init process [$init_ccld_default]
140 --init-ulinux-arch=ARCH use ulinux ARCH for target init process [$init_ulinux_arch]
145 ################################################################################
152 --quiet) CPPFLAGS
="$CPPFLAGS -DQUIET"
156 optname
=${optname#--}
157 optname
=$
(echo "$optname" |
sed 's/-/_/g')
158 if is_in
$optname $CMDLINE_SET; then
159 eval $optname='$optval'
167 ################################################################################
169 sep_start
;echo 'looking for source path:'
170 if test -f make; then
173 src_path
=$
(cd $
(dirname "$0"); pwd)
174 echo "$src_path" |
grep -q '[[:blank:]]' &&
175 die
"out of tree builds are impossible with whitespace in source path."
177 echo "source path is $src_path";sep_end
179 ################################################################################
181 sep_start
;echo 'checking libkmod and libblkid pkgconfig support:'
182 if $pkg_config --exists libkmod blkid
; then
183 echo "found pkg-config files for libkmod and libblkid"
185 echo "missing pkg-config file for libkmod or libblkid"
190 ################################################################################
192 # define variable in source
193 CPPFLAGS
="$CPPFLAGS -DUEVENTS_TIMEOUT=$uevents_timeout"
194 CPPFLAGS
="$CPPFLAGS $($pkg_config --cflags-only-I libkmod blkid)"
195 CFLAGS
="$CFLAGS $($pkg_config --cflags-only-other libkmod blkid)"
196 LIBS
="$($pkg_config --libs --static libkmod blkid) $LIBS"
198 ################################################################################
200 sep_start
;echo 'configure ulinux src tree for target arch:'
201 rm -f $src_path/ulinux
/arch
202 ln -s archs
/$init_ulinux_arch $src_path/ulinux
/arch
203 echo "init ulinux arch is $init_ulinux_arch"
206 ################################################################################
208 # generated some code/headers
211 revision
=$
(echo "$kernel_release" |
egrep -o '^[[:digit:]]+\.[[:digit:]]+')
212 .
$src_path/$revision
213 printf "linux revision is $revision, $src_path/$revision was sourced:\n--------\n"
214 cat $src_path/$revision
218 # those modules are all loaded before anything else
219 sep_start
;echo 'generate static module list:'
220 $src_path/script
/static_modules_h.sh
$extra_modules $DISK_MODULES \
222 cat .
/static_modules.h
225 ################################################################################
227 sep_start
;echo 'C preprocess init src files:'
228 for init_src_file
in $init_src_files
230 init_pp_c_file
=${init_src_file%.c}.pp.c
231 echo "INIT_CPP $init_src_file->$init_pp_c_file"
232 mkdir
-p $
(dirname $init_pp_c_file)
233 $init_cpp -o $init_pp_c_file \
237 $src_path/$init_src_file
238 init_pp_c_files
="$init_pp_c_file $init_pp_c_files"
242 ################################################################################
244 sep_start
;echo 'compile init preprocessed src files:'
245 for init_pp_c_file
in $init_pp_c_files
247 init_obj_file
=${init_pp_c_file%.pp.c}.o
248 echo "INIT_CC $init_pp_c_file-->$init_obj_file"
249 $init_cc $CFLAGS -o $init_obj_file $init_pp_c_file
250 init_obj_files
="$init_obj_file $init_obj_files"
254 ################################################################################
256 sep_start
;echo 'link the init objects to produce the init binary:'
257 echo "INIT_CCLD $init_file_name"
258 $init_ccld -o $init_file_name $init_obj_files $LIBS
261 ################################################################################
263 sep_start
;echo 'generate the cpio source file:'
264 sed -e "s:@INIT_PATH@:$(readlink -f $init_file_name):" "$src_path/cpio.in" >cpio
265 echo "dir /lib/modules/$kernel_release 0755 0 0">>cpio
267 modules
=$HW_MODULES,$DISK_MODULES,$FS_MODULES
268 if test -n "$extra_modules";then
269 modules
=$modules,$extra_modules
273 #add proper entries in the cpio definition file related to linux modules
274 $src_path/script
/cpio_modules_add.sh
$kernel_modules_base_dir $kernel_release \
278 printf "cpio source file is:\n--------\n"
283 ################################################################################
285 sep_start
;echo 'generating and compressing the cpio archive'
286 e_gen_init_cpio
=$
(eval echo "$gen_init_cpio")
287 $e_gen_init_cpio cpio >${kernel_release}.
cpio
288 xz
--force --check=crc32
--extreme --stdout ${kernel_release}.
cpio >${kernel_release}.
cpio.xz