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 rm -f static_modules.h
39 for init_src_file
in $init_src_files
41 rm -f ${init_src_file/\.c/.pp.c}
42 rm -f ${init_src_file/\.c/.o}
43 #clean directories, but keep root of build tree
44 tgt_dir
=$
(dirname $init_src_file)
45 if test -d $tgt_dir -a "$tgt_dir" != "."; then
46 rmdir --ignore-fail-on-non-empty -p $tgt_dir
54 echo '###############################################################################'
59 echo -e '###############################################################################\n'
64 echo -e '*******************************************************************************'
69 echo -e '*******************************************************************************'
71 ################################################################################
77 [ $var = $value ] && return 0
83 echo "Unknown option \"$1\"."
84 echo "See $0 --help for available options."
90 eval : \
${$opt:=\$${opt}_default}
96 kernel_modules_base_dir
110 #command line set defaults
111 #if the root is not around in less than 4s, something is really wrong
112 uevents_timeout_default
=4000
113 root_uuid_default
=00000000-0000-0000-0000-000000000000
114 gen_init_cpio_default
='$linux_src_dir/usr/gen_init_cpio'
115 linux_src_dir_default
=/usr
/src
/linux
116 #-------------------------------------------------------------------------------
117 #This defaults are for gcc, tested with version 4.7.3. You will need to
118 #override those for you compiler (tinycc/open64/pcc...). Additionnally, source
119 #support for different toolchains is not done.
120 #Since we use standard C runtime libs, be nice with the C runtime.
121 #The right way to do it is to have a toolchain abstraction layer since there are
122 #no standards for some
123 init_cpp_default
='gcc -E -Wall -Wextra'
124 init_cc_default
="gcc -Wall -Wextra -std=gnu99 -O0 \
125 -Wl,--dynamic-linker=/lib/ld.so -c"
126 init_ld_default
='gcc -Wl,-O10,-s'
127 #-------------------------------------------------------------------------------
128 kernel_modules_base_dir_default
=/
129 kernel_release_default
=$
(uname
-r)
130 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
/)
131 extra_modules_default
=
132 pkg_config_default
=pkg-config
133 readelf_default
=readelf
134 elf_interpreter_default
=
136 set_default
$CMDLINE_SET
140 Usage: make [options] [operations]
142 Operations: [default is to build the the initramfs xz compressed cpio archive]:
143 clean clean build products
145 Options: [defaults in brackets after descriptions]
148 --help print this message
151 --root-uuid=ROOT_UUID the uuid or the root filesystem to mount [$root_uuid_default]
152 --lib-path-list=LIB_PATH_LIST colon separated paths to look for target libraries
153 --uevents-timeout=UEVENTS_TIMEOUT uevents timeout in ms looking up for root block device to go online [$uevents_timeout]
154 --quiet init will be silenced (output code compiled out)
155 --linux-src-dir=DIR where to find the target linux source tree [$linux_src_dir_default]
156 --kernel-release=RELEASE the linux releases version [$kernel_release]
157 --kernel-modules-base-dir=DIR the base dir for linux modules and support files [$kernel_modules_base_dir]
158 --extra-modules=EXTRA_MODULES coma separated list of extra module to probe
161 --gen-init-cpio=GEN_INIT_CPIO_PATH use this linux host tool to build the linux cpio initramfs [$gen_init_cpio_default]
162 --pkg-config=PKG_CONFIG use PKG_CONFIG pkg-config command for target libraries [$pkg_config_default]
163 --readelf=READELF use READELF readelf command for target readelf [$readelf_default]
164 --elf-interpreter=ELF_INTERPRETER copy target ELF_INTERPRETER in cpio archive [will use the interpreter from the generated init elf binary]
165 --init-cpp=CPP use CPP compiler command line CPP for target init process [$init_cpp_default]
166 --init-cc=CC use C compiler command line CC for target init process objects [$init_cc_default]
167 --init-ld=LD use linker command line LD for target init process [$init_ld_default]
168 --init-ulinux-arch=ARCH use ulinux ARCH for target init process [$init_ulinux_arch]
173 ################################################################################
182 --quiet) CPPFLAGS
="$CPPFLAGS -DQUIET"
186 optname
=${optname#--}
187 optname
=$
(echo "$optname" |
sed 's/-/_/g')
188 if is_in
$optname $CMDLINE_SET; then
189 eval $optname='$optval'
197 ################################################################################
199 sep_start
;echo 'looking for source path:'
200 if test -f make; then
203 src_path
=$
(cd $
(dirname "$0"); pwd)
204 echo "$src_path" |
grep -q '[[:blank:]]' &&
205 die
"out of tree builds are impossible with whitespace in source path."
206 test -e "$src_path/config.h" &&
207 die
"out of tree builds are impossible with config.h in source dir."
209 echo "source path is $src_path";sep_end
211 ################################################################################
213 sep_start
;echo 'checking libkmod and libblkid pkgconfig support:'
214 if $pkg_config --exists libkmod blkid
; then
215 echo "found pkg-config files for libkmod and libblkid"
217 echo "missing pkg-config file for libkmod or libblkid"
222 ################################################################################
224 #define variable in source
225 CPPFLAGS
="$CPPFLAGS -DUEVENTS_TIMEOUT=$uevents_timeout"
226 CPPFLAGS
="$CPPFLAGS -DROOT_UUID="$root_uuid""
227 CPPFLAGS
="$CPPFLAGS $($pkg_config --cflags-only-I libkmod blkid)"
228 CFLAGS
="$CFLAGS $($pkg_config --cflags-only-other libkmod blkid)"
229 LDFLAGS
="$LDFLAGS $($pkg_config --libs libkmod blkid)"
231 ################################################################################
233 sep_start
;echo 'configure ulinux src tree for target arch:'
234 rm -f $src_path/ulinux
/arch
235 ln -s archs
/$init_ulinux_arch $src_path/ulinux
/arch
236 echo "init ulinux arch is $init_ulinux_arch"
239 ################################################################################
241 #generated some code/headers
244 revision
=$
(uname
-r |
egrep -o '^[[:digit:]]+\.[[:digit:]]+')
245 source $src_path/$revision
246 echo -e "linux revision is $revision, $src_path/$revision was sourced:\n--------"
247 cat $src_path/$revision
251 sep_start
;echo 'generate static module list:'
252 $src_path/script
/static_modules_h.sh
$extra_modules $DISK_MODULES \
254 cat .
/static_modules.h
257 ################################################################################
259 sep_start
;echo 'C preprocess init src files:'
260 for init_src_file
in $init_src_files
262 init_pp_c_file
=${init_src_file/\.c/.pp.c}
263 echo "INIT_CPP $init_src_file->$init_pp_c_file"
264 mkdir
-p $
(dirname $init_pp_c_file)
265 $init_cpp $CPPFLAGS -I.
-I$src_path -o $init_pp_c_file \
266 $src_path/$init_src_file
267 init_pp_c_files
="$init_pp_c_file $init_pp_c_files"
271 ################################################################################
273 sep_start
;echo 'compile init preprocessed src files:'
274 for init_pp_c_file
in $init_pp_c_files
276 init_obj_file
=${init_pp_c_file/\.pp.c/.o}
277 echo "INIT_CC $init_pp_c_file-->$init_obj_file"
278 $init_cc $CFLAGS -o $init_obj_file $init_pp_c_file
279 init_obj_files
="$init_obj_file $init_obj_files"
283 ################################################################################
285 sep_start
;echo 'link the init objects to produce the init binary:'
286 echo "INIT_LD $init_file_name"
287 $init_ld -o $init_file_name $init_obj_files $LDFLAGS
290 ################################################################################
292 #build the library path used by the gcc toolchain. We will need it to lookup
293 #for the dynamic shared libraries and copy them into the cpio
294 sep_start
;echo "computing gcc library path:"
295 #in gcc search paths, the sysroot uses '='
296 lib_path_nosysroot
=$
($init_ld $LDFLAGS -print-search-dirs |
egrep '^libraries' \
297 |
sed -r 's/libraries:[[:space:]]+(.+)/\1/')
298 echo "gcc library path is $lib_path_nosysroot"
299 gcc_sysroot
=$
($init_ld -print-sysroot)
300 echo "gcc_sysroot (can be empty) is $gcc_sysroot"
303 #replace the sysroot marker, '=', in gcc library path
304 if test -n "$gcc_sysroot"; then
305 for p
in $lib_path_nosysroot; do
306 lib_path_norealpath
="$lib_path_norealpath:$(echo $p | sed -r "s
:^
=:$gcc_sysroot:")"
309 for p
in $lib_path_nosysroot; do
310 lib_path_norealpath
="$lib_path_norealpath:$(echo $p | sed -r 's/^=//')"
313 for p
in $lib_path_norealpath; do
314 if realpath
-q "$p" &>/dev
/null
; then
315 lib_path
="$lib_path:$(realpath "$p")"
318 lib_path
=${lib_path#:}
319 echo "final LIB_PATH=$lib_path"
322 ################################################################################
324 #locate the target elf interpreter which will be copied in the cpio archive
326 if test -z "$elf_interpreter"; then
327 elf_interpreter
=$
($readelf -l .
/init |
egrep 'Requesting program interpreter' |
sed -r 's/^.+interpreter:[[:space:]]*(.+)\]/\1/')
329 echo "will copy $elf_interpreter elf interpreter in cpio archive"
332 ################################################################################
334 sep_start
;echo 'generate the cpio source file:'
335 sed -e "s:@INIT_PATH@:$(realpath $init_file_name):" "$src_path/cpio.in" >cpio
336 echo "dir /lib/modules/$kernel_release 0755 0 0">>cpio
338 modules
=$HW_MODULES,$DISK_MODULES,$FS_MODULES
339 if test -n $
"extra_modules";then
340 modules
=$modules,$extra_modules
344 #add proper entries in the cpio definition file related to linux modules
345 $src_path/script
/cpio_modules_add.sh
$kernel_modules_base_dir $kernel_release \
350 #add proper entries in the cpio definition file related to shared elf libs
351 $src_path/script
/cpio_libs_add.sh
"$readelf" "$lib_path" .
/init \
352 "$elf_interpreter" .
/cpio
355 echo -e 'cpio source file is:\n--------'
360 ################################################################################
362 e_gen_init_cpio
=$
(eval echo "$gen_init_cpio")
363 $e_gen_init_cpio cpio >${kernel_release}.
cpio
364 xz
--force --check=crc32
--extreme --stdout ${kernel_release}.
cpio >${kernel_release}.
cpio.xz