Added patch from Kumba to make certain initrd functions less mips-specific.
[genkernel.git] / gen_cmdline.sh
1 #!/bin/bash
2
3 longusage() {
4   echo "Gentoo Linux Genkernel ${GK_V}"
5   echo "Usage: "
6   echo "  genkernel [options] action"
7   echo
8   echo "Available Actions: "
9   echo "  all                           Build all steps"
10   echo "  bzImage                       Build only the kernel"
11   echo "  kernel                        Build only the kernel and modules"
12   echo "  initrd                        Build only the initrd"
13   echo
14   echo "Available Options: "
15   echo "  Debug settings"
16   echo "        --debuglevel=<0-5>      Debug Verbosity Level"
17   echo "        --debugfile=<outfile>   Output file for debug info"
18   echo "        --color                 Output debug in color"
19   echo "        --no-color              Do not output debug in color"
20   echo "  Kernel Configuration settings"
21   echo "        --menuconfig            Run menuconfig after oldconfig"
22   echo "        --no-menuconfig         Do not run menuconfig after oldconfig"
23   echo "        --gconfig               Run gconfig after oldconfig"
24   echo "        --xconfig               Run xconfig after oldconfig"
25   echo "        --save-config           Save the configuration to /etc/kernels"
26   echo "        --no-save-config        Don't save the configuration to /etc/kernels"
27   echo "  Kernel Compile settings"
28   echo "        --clean                 Run make clean before compilation"
29   echo "        --mrproper              Run make mrproper before compilation"
30   echo "        --no-clean              Do not run make clean before compilation"
31   echo "        --no-mrproper           Do not run make mrproper before compilation"
32   echo "        --oldconfig             Implies --no-clean and runs a 'make oldconfig'"
33   echo "        --bootsplash            Install bootsplash support to the initrd"
34   echo "        --no-bootsplash         Do not use bootsplash"
35   echo "        --gensplash             Install gensplash support into bzImage"
36   echo "        --no-gensplash          Do not use gensplash"
37   echo "        --install               Install the kernel after building"
38   echo "        --no-install            Do not install the kernel after building"
39   echo "        --no-initrdmodules      Don't copy any modules to the initrd"
40   echo "        --no-udev               Disable udev support"
41   echo "        --no-devfs              Disable devfs support"
42   echo "        --callback=<...>        Run the specified arguments after the"
43   echo "                                kernel and modules have been compiled"
44   echo "        --static                Build a static (monolithic kernel)."
45   echo "        --initramfs             Builds initramfs before kernel and embeds it"
46   echo "                                into the kernel."
47   echo "  Kernel settings"
48   echo "        --kerneldir=<dir>       Location of the kernel sources"
49   echo "        --kernel-config=<file>  Kernel configuration file to use for compilation"
50   echo "        --module-prefix=<dir>   Prefix to kernel module destination, modules will"
51   echo "                                be installed in <prefix>/lib/modules"
52   echo "  Low-Level Compile settings"
53   echo "        --kernel-cc=<compiler>  Compiler to use for kernel (e.g. distcc)"
54   echo "        --kernel-as=<assembler> Assembler to use for kernel"
55   echo "        --kernel-ld=<linker>    Linker to use for kernel"
56   echo "        --kernel-cross-compile=<cross var> CROSS_COMPILE kernel variable"
57   echo "        --kernel-make=<makeprg> GNU Make to use for kernel"
58   echo "        --utils-cc=<compiler>   Compiler to use for utilities"
59   echo "        --utils-as=<assembler>  Assembler to use for utils"
60   echo "        --utils-ld=<linker>     Linker to use for utils"
61   echo "        --utils-make=<makeprog> GNU Make to use for utils"
62   echo "        --utils-cross-compile=<cross var> CROSS_COMPILE utils variable"
63   echo "        --utils-arch=<arch>     Force to arch for utils only instead of autodetect."
64   echo "        --makeopts=<makeopts>   Make options such as -j2, etc..."
65   echo "        --mountboot             Mount /boot automatically"
66   echo "        --no-mountboot          Don't mount /boot automatically"  
67   echo "  Initialization"
68   echo "        --bootsplash=<theme>    Force bootsplash using <theme>"
69   echo "        --gensplash=<theme>     Force gensplash using <theme>"
70   echo "        --gensplash-res=<res>   Select gensplash resolutions"
71   echo "        --do-keymap-auto        Forces keymap selection at boot"
72   echo "        --evms2                 Include EVMS2 support"
73   echo "                                --> 'emerge evms' in the host operating system first"
74   echo "        --lvm2                  Include LVM2 support"
75 #  echo "       --unionfs               Include UNIONFS support"
76   echo "        --dmraid                Include DMRAID support"
77   echo "        --bladecenter   Enables extra pauses for IBM Bladecenter CD boots"
78   echo "        --bootloader=grub       Add new kernel to GRUB configuration"
79   echo "        --linuxrc=<file>        Specifies a user created linuxrc"
80   echo "        --disklabel             Include disk label and uuid support in your initrd"
81   echo "  Internals"
82   echo "        --arch-override=<arch>  Force to arch instead of autodetect"
83   echo "        --cachedir=<dir>        Override the default cache location"
84   echo "        --tempdir=<dir>         Location of Genkernel's temporary directory"
85   echo "        --postclear             Clear all tmp files and caches after genkernel has run"
86   echo "  Output Settings"
87   echo "        --kernname=<...>        Tag the kernel and initrd with a name:"
88   echo "                                If not defined the option defaults to 'genkernel'"
89   echo "        --minkernpackage=<tbz2> File to output a .tar.bz2'd kernel and initrd:"
90   echo "                                No modules outside of the initrd will be"
91   echo "                                included..."
92   echo "        --modulespackage=<tbz2> File to output a .tar.bz2'd modules after the callbacks have run"
93   echo "        --kerncache=<tbz2>      File to output a .tar.bz2'd kernel,"
94   echo "                                contents of /lib/modules/ and the kernel config"
95   echo "                                NOTE: This is created before the callbacks are run!"
96   echo "        --no-kernel-sources     This option is only valid if kerncache is defined"
97   echo "                                If there is a valid kerncache no checks will be made"
98   echo "                                against a kernel source tree"
99   echo "        --initramfs-overlay=<dir>"
100   echo "                                Directory structure to include in the initramfs,"
101   echo "                                only available on 2.6 kernels that don't use bootsplash"
102 }
103
104 usage() {
105   echo "Gentoo Linux Genkernel ${GK_V}"
106   echo "Usage: "
107   echo "        genkernel [options] all"
108   echo
109   echo 'Some useful options:'
110   echo '        --menuconfig            Run menuconfig after oldconfig'
111   echo '        --no-clean              Do not run make clean before compilation'
112   echo '        --no-mrproper           Do not run make mrproper before compilation,'
113   echo '                                this is implied by --no-clean.'
114   echo
115   echo 'For a detailed list of supported options and flags; issue:'
116   echo '        genkernel --help'
117 }
118
119 parse_opt() {
120         case "$1" in
121                 *\=*)
122                         echo "$1" | cut -f2- -d=
123                 ;;
124         esac
125 }
126
127 parse_cmdline() {
128         case "$*" in
129               --kernel-cc=*)
130                       CMD_KERNEL_CC=`parse_opt "$*"`
131                       print_info 2 "CMD_KERNEL_CC: $CMD_KERNEL_CC"
132               ;;
133               --kernel-ld=*)
134                       CMD_KERNEL_LD=`parse_opt "$*"`
135                       print_info 2 "CMD_KERNEL_LD: $CMD_KERNEL_LD"
136               ;;
137               --kernel-as=*)
138                       CMD_KERNEL_AS=`parse_opt "$*"`
139                       print_info 2 "CMD_KERNEL_AS: $CMD_KERNEL_AS"
140               ;;
141               --kernel-make=*)
142                       CMD_KERNEL_MAKE=`parse_opt "$*"`
143                       print_info 2 "CMD_KERNEL_MAKE: $CMD_KERNEL_MAKE"
144               ;;
145               --kernel-cross-compile=*)
146                       CMD_KERNEL_CROSS_COMPILE=`parse_opt "$*"`
147                       CMD_KERNEL_CROSS_COMPILE=$(echo ${CMD_KERNEL_CROSS_COMPILE}|sed -e 's/.*[^-]$/&-/g')
148                       print_info 2 "CMD_KERNEL_CROSS_COMPILE: $CMD_KERNEL_CROSS_COMPILE"
149               ;;
150               --utils-cc=*)
151                       CMD_UTILS_CC=`parse_opt "$*"`
152                       print_info 2 "CMD_UTILS_CC: $CMD_UTILS_CC"
153               ;;
154               --utils-ld=*)
155                       CMD_UTILS_LD=`parse_opt "$*"`
156                       print_info 2 "CMD_UTILS_LD: $CMD_UTILS_LD"
157               ;;
158               --utils-as=*)
159                       CMD_UTILS_AS=`parse_opt "$*"`
160                       print_info 2 "CMD_UTILS_AS: $CMD_UTILS_AS"
161               ;;
162               --utils-make=*)
163                       CMD_UTILS_MAKE=`parse_opt "$*"`
164                       print_info 2 "CMD_UTILS_MAKE: $CMD_UTILS_MAKE"
165               ;;
166               --utils-cross-compile=*)
167                       CMD_UTILS_CROSS_COMPILE=`parse_opt "$*"`
168                       CMD_UTILS_CROSS_COMPILE=$(echo ${CMD_UTILS_CROSS_COMPILE}|sed -e 's/.*[^-]$/&-/g')
169                       print_info 2 "CMD_UTILS_CROSS_COMPILE: $CMD_UTILS_CROSS_COMPILE"
170               ;;
171               --utils-arch=*)
172                       CMD_UTILS_ARCH=`parse_opt "$*"`
173                       print_info 2 "CMD_UTILS_ARCH: $CMD_ARCHOVERRIDE"
174               ;;
175               --makeopts=*)
176                       CMD_MAKEOPTS=`parse_opt "$*"`
177                       print_info 2 "CMD_MAKEOPTS: $CMD_MAKEOPTS"
178               ;;
179               --mountboot)
180                       CMD_MOUNTBOOT=1
181                       print_info 2 "CMD_MOUNTBOOT: $CMD_MOUNTBOOT"
182               ;;
183               --no-mountboot)
184                       CMD_MOUNTBOOT=0
185                       print_info 2 "CMD_MOUNTBOOT: $CMD_MOUNTBOOT"
186               ;;
187               --do-keymap-auto)
188                       CMD_DOKEYMAPAUTO=1
189                       print_info 2 "CMD_DOKEYMAPAUTO: $CMD_DOKEYMAPAUTO"
190               ;;
191               --evms2)
192                       CMD_EVMS2=1
193                       print_info 2 "CMD_EVMS2: $CMD_EVMS2"
194               ;;
195               --unionfs)
196                       echo
197                       print_warning 1 "WARNING: unionfs support is in active development and is not meant for general use."
198                       print_warning 1 "DISABLING UNIONFS SUPPORT AT THIS TIME."
199                       echo
200               ;;
201               --unionfs-dev)
202                       CMD_UNIONFS=1
203                       print_info 2 "CMD_UNIONFS: $CMD_UNIONFS"
204                       echo
205                       print_warning 1 "WARNING: unionfs support is in active development and is not meant for general use."
206                       print_warning 1 "Bug Reports without patches/fixes will be ignored."
207                       print_warning 1 "Use at your own risk as this could blow up your system."
208                       print_warning 1 "This code is subject to change at any time."
209                       echo
210               ;;
211               --lvm2)
212                       CMD_LVM2=1
213                       print_info 2 "CMD_LVM2: $CMD_LVM2"
214               ;;
215               --no-busybox)
216                       CMD_NO_BUSYBOX=1
217                       print_info 2 "CMD_NO_BUSYBOX: $CMD_NO_BUSYBOX"
218               ;;
219               --bladecenter)
220                       CMD_BLADECENTER=1
221                       print_info 2 "CMD_BLADECENTER: $CMD_BLADECENTER"
222               ;;
223               --dmraid)
224                       if [ ! -e /usr/include/libdevmapper.h ]
225                       then
226                         echo 'Error: --dmraid requires device-mapper to be installed'
227                         echo '       on the host system; try "emerge device-mapper".'
228                         exit 1
229                       fi
230                       CMD_DMRAID=1
231                       print_info 2 "CMD_DMRAID: $CMD_DMRAID"
232               ;;
233               --bootloader=*)
234                       CMD_BOOTLOADER=`parse_opt "$*"`
235                       print_info 2 "CMD_BOOTLOADER: $CMD_BOOTLOADER"
236               ;;
237               --debuglevel=*)
238                       CMD_DEBUGLEVEL=`parse_opt "$*"`
239                       DEBUGLEVEL="${CMD_DEBUGLEVEL}"
240                       print_info 2 "CMD_DEBUGLEVEL: $CMD_DEBUGLEVEL"
241               ;;
242               --menuconfig)
243                       TERM_LINES=`stty -a | head -n 1 | cut -d\  -f5 | cut -d\; -f1`
244                       TERM_COLUMNS=`stty -a | head -n 1 | cut -d\  -f7 | cut -d\; -f1`
245
246                       if [[ TERM_LINES -lt 19 || TERM_COLUMNS -lt 80 ]]
247                       then
248                         echo "Error: You need a terminal with at least 80 columns"
249                         echo "       and 19 lines for --menuconfig; try --nomenuconfig..."
250                         exit 1
251                       fi
252                       CMD_MENUCONFIG=1
253                       print_info 2 "CMD_MENUCONFIG: $CMD_MENUCONFIG"
254               ;;
255               --no-menuconfig)
256                       CMD_MENUCONFIG=0
257                       print_info 2 "CMD_MENUCONFIG: $CMD_MENUCONFIG"
258               ;;
259               --gconfig)
260                       CMD_GCONFIG=1
261                       print_info 2 "CMD_GCONFIG: $CMD_GCONFIG"
262               ;;
263               --xconfig)
264                       CMD_XCONFIG=1
265                       print_info 2 "CMD_XCONFIG: $CMD_XCONFIG"
266               ;;
267               --save-config)
268                       CMD_SAVE_CONFIG=1
269                       print_info 2 "CMD_SAVE_CONFIG: $CMD_SAVE_CONFIG"
270               ;;
271               --no-save-config)
272                       CMD_SAVE_CONFIG=0
273                       print_info 2 "CMD_SAVE_CONFIG: $CMD_SAVE_CONFIG"
274               ;;
275               --mrproper)
276                       CMD_MRPROPER=1
277                       print_info 2 "CMD_MRPROPER: $CMD_MRPROPER"
278               ;;
279               --no-mrproper)
280                       CMD_MRPROPER=0
281                       print_info 2 "CMD_MRPROPER: $CMD_MRPROPER"
282               ;;
283               --clean)
284                       CMD_CLEAN=1
285                       print_info 2 "CMD_CLEAN: $CMD_CLEAN"
286               ;;
287               --no-clean)
288                       CMD_CLEAN=0
289                       print_info 2 "CMD_CLEAN: $CMD_CLEAN"
290               ;;
291               --oldconfig)
292                       CMD_CLEAN=0
293                       CMD_OLDCONFIG=1
294                       print_info 2 "CMD_CLEAN: $CMD_CLEAN"
295                       print_info 2 "CMD_OLDCONFIG: $CMD_OLDCONFIG"
296               ;;
297               --bootsplash=*)
298                       CMD_BOOTSPLASH=1
299                       CMD_GENSPLASH=0
300                       BOOTSPLASH_THEME=`parse_opt "$*"`
301                       print_info 2 "CMD_BOOTSPLASH: $CMD_BOOTSPLASH"
302                       print_info 2 "CMD_GENSPLASH: $CMD_GENSPLASH"
303                       print_info 2 "BOOTSPLASH_THEME: $BOOTSPLASH_THEME"
304               ;;
305               --bootsplash)
306                       CMD_BOOTSPLASH=1
307                       CMD_GENSPLASH=0
308                       print_info 2 "CMD_BOOTSPLASH: $CMD_BOOTSPLASH"
309                       print_info 2 "CMD_GENSPLASH: $CMD_GENSPLASH"
310               ;;
311               --no-bootsplash)
312                       CMD_BOOTSPLASH=0
313                       print_info 2 "CMD_BOOTSPLASH: $CMD_BOOTSPLASH"
314               ;;
315               --gensplash=*)
316                       CMD_GENSPLASH=1
317                       CMD_BOOTSPLASH=0
318                       GENSPLASH_THEME=`parse_opt "$*"`
319                       print_info 2 "CMD_GENSPLASH: $CMD_GENSPLASH"
320                       print_info 2 "GENSPLASH_THEME: $GENSPLASH_THEME"
321                       print_info 2 "CMD_BOOTSPLASH: $CMD_BOOTSPLASH"
322               ;;
323               --gensplash)
324                       CMD_GENSPLASH=1
325                       CMD_BOOTSPLASH=0
326                       GENSPLASH_THEME='default'
327                       print_info 2 "CMD_GENSPLASH: $CMD_GENSPLASH"
328                       print_info 2 "CMD_BOOTSPLASH: $CMD_BOOTSPLASH"
329               ;;
330               --no-gensplash)
331                       CMD_GENSPLASH=0
332                       print_info 2 "CMD_GENSPLASH: $CMD_GENSPLASH"
333               ;;
334               --gensplash-res=*)
335                       GENSPLASH_RES=`parse_opt "$*"`
336                       print_info 2 "GENSPLASH_RES: $GENSPLASH_RES"
337               ;;
338               --install)
339                       CMD_NOINSTALL=0
340                       print_info 2 "CMD_NOINSTALL: $CMD_NOINSTALL"
341               ;;
342               --no-install)
343                       CMD_NOINSTALL=1
344                       print_info 2 "CMD_NOINSTALL: $CMD_NOINSTALL"
345               ;;
346               --no-initrdmodules)
347                       CMD_NOINITRDMODULES=1
348                       print_info 2 "CMD_NOINITRDMODULES: $CMD_NOINITRDMODULES"
349               ;;
350               --udev)
351                       echo
352                       echo
353                       print_info 1 "--udev is deprecated and no longer necessary as udev is on by default"
354                       sleep 3
355                       echo
356                       echo
357                       print_info 2 "CMD_UDEV: $CMD_UDEV"
358               ;;
359               --no-udev)
360                       CMD_NO_UDEV=1
361                       print_info 2 "CMD_NO_UDEV: $CMD_NO_UDEV"
362               ;;
363               --no-devfs)
364                       CMD_NO_DEVFS=1
365                       print_info 2 "CMD_NO_DEVFS: $CMD_NO_DEVFS"
366               ;;
367               --callback=*)
368                       CMD_CALLBACK=`parse_opt "$*"`
369                       print_info 2 "CMD_CALLBACK: $CMD_CALLBACK/$*"
370               ;;
371               --static)
372                       CMD_STATIC=1
373                       print_info 2 "CMD_STATIC: $CMD_STATIC"
374               ;;
375               --initramfs)
376                       CMD_INITRAMFS=1
377                       print_info 2 "CMD_INITRAMFS: $CMD_INITRAMFS"
378               ;;
379               --tempdir=*)
380                       TEMP=`parse_opt "$*"`
381                       print_info 2 "TEMP: $TEMP"
382               ;; 
383               --postclear)
384                       CMD_POSTCLEAR=1
385                       print_info 2 "CMD_POSTCLEAR: $CMD_POSTCLEAR"
386               ;; 
387               --arch-override=*)
388                       CMD_ARCHOVERRIDE=`parse_opt "$*"`
389                       print_info 2 "CMD_ARCHOVERRIDE: $CMD_ARCHOVERRIDE"
390               ;;
391               --color)
392                       CMD_USECOLOR=1
393                       print_info 2 "CMD_USECOLOR: $CMD_USECOLOR"
394               ;;
395               --no-color)
396                       CMD_USECOLOR=0
397                       print_info 2 "CMD_USECOLOR: $CMD_USECOLOR"
398               ;;
399               --debugfile=*)
400                       CMD_DEBUGFILE=`parse_opt "$*"`
401                       DEBUGFILE=`parse_opt "$*"`
402                       print_info 2 "CMD_DEBUGFILE: $CMD_DEBUGFILE"
403                       print_info 2 "DEBUGFILE: $CMD_DEBUGFILE"
404               ;;
405               --kerneldir=*)
406                       CMD_KERNELDIR=`parse_opt "$*"`
407                       print_info 2 "CMD_KERNELDIR: $CMD_KERNELDIR"
408               ;;
409               --kernel-config=*)
410                       CMD_KERNEL_CONFIG=`parse_opt "$*"`
411                       print_info 2 "CMD_KERNEL_CONFIG: $CMD_KERNEL_CONFIG"
412               ;;
413               --module-prefix=*)
414                       CMD_INSTALL_MOD_PATH=`parse_opt "$*"`
415                       print_info 2 "CMD_INSTALL_MOD_PATH: $CMD_INSTALL_MOD_PATH"
416               ;;
417               --cachedir=*)
418                       CACHE_DIR=`parse_opt "$*"`
419                       print_info 2 "CACHE_DIR: $CACHE_DIR"
420               ;;
421               --minkernpackage=*)
422                       CMD_MINKERNPACKAGE=`parse_opt "$*"`
423                       print_info 2 "MINKERNPACKAGE: $CMD_MINKERNPACKAGE"
424               ;;
425               --modulespackage=*)
426                       CMD_MODULESPACKAGE=`parse_opt "$*"`
427                       print_info 2 "MODULESPACKAGE: $CMD_MODULESPACKAGE"
428               ;;
429               --kerncache=*)
430                       CMD_KERNCACHE=`parse_opt "$*"`
431                       print_info 2 "KERNCACHE: $CMD_KERNCACHE"
432               ;;
433               --kernname=*)
434                       CMD_KERNNAME=`parse_opt "$*"`
435                       print_info 2 "KERNNAME: $CMD_KERNNAME"
436               ;;
437               --symlink)
438                       CMD_SYMLINK=1
439                       print_info 2 "CMD_SYMLINK: $CMD_SYMLINK"
440               ;;
441               --no-kernel-sources)
442                       CMD_NO_KERNEL_SOURCES=1
443                       print_info 2 "CMD_NO_KERNEL_SOURCES: $CMD_NO_KERNEL_SOURCES"
444               ;;
445               --initramfs-overlay=*)
446                       CMD_INITRAMFS_OVERLAY=`parse_opt "$*"`
447                       print_info 2 "CMD_INITRAMFS_OVERLAY: $CMD_INITRAMFS_OVERLAY"
448               ;;
449               --linuxrc=*)
450                         CMD_LINUXRC=`parse_opt "$*"`
451                         print_info 2 "CMD_LINUXRC: $CMD_LINUXRC"
452               ;;
453               --genzimage)
454                         KERNEL_MAKE_DIRECTIVE_2='zImage.initrd'
455                         KERNEL_BINARY_2='arch/ppc/boot/images/zImage.initrd.chrp'
456                         GENERATE_Z_IMAGE=1
457                         print_info 2 "GENERATE_Z_IMAGE: $GENERATE_Z_IMAGE"
458               ;;
459               --disklabel)
460                       CMD_DISKLABEL=1
461                       print_info 2 "CMD_DISKLABEL: $CMD_DISKLABEL"
462               ;;
463               all)
464                       BUILD_KERNEL=1
465                       BUILD_MODULES=1
466                       BUILD_INITRD=1
467               ;;
468               initrd)
469                       BUILD_INITRD=1
470               ;;
471               kernel)
472                       BUILD_KERNEL=1
473                       BUILD_MODULES=1
474                       BUILD_INITRD=0
475               ;;
476               bzImage)
477                       BUILD_KERNEL=1
478                       BUILD_MODULES=0
479                       BUILD_INITRD=1
480                       CMD_NOINITRDMODULES=1
481                       print_info 2 "CMD_NOINITRDMODULES: $CMD_NOINITRDMODULES"
482               ;;
483               --help)
484                       longusage
485                       exit 1
486               ;;
487               --version)
488                       echo "${GK_V}"
489                       exit 0
490               ;;
491               *)
492                       echo "Error: Unknown option '$*'!"
493                       exit 1
494               ;;
495         esac
496 }