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