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