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