3d031f1d8e67b37f084dab13afc158ee662d9ac3
[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 "        --bootloader=grub       Add new kernel to GRUB configuration"
73   echo "        --linuxrc=<file>        Specifies a user created linuxrc"
74   echo "  Internals"
75   echo "        --arch-override=<arch>  Force to arch instead of autodetect"
76   echo "        --cachedir=<dir>        Override the default cache location"
77   echo "        --tempdir=<dir>         Location of Genkernel's temporary directory"
78   echo "  Output Settings"
79   echo "        --kernname=<...>        Tag the kernel and initrd with a name:"
80   echo "                                If not defined the option defaults to 'genkernel'"
81   echo "        --minkernpackage=<tbz2> File to output a .tar.bz2'd kernel and initrd:"
82   echo "                                No modules outside of the initrd will be"
83   echo "                                included..."
84   echo "        --modulespackage=<tbz2> File to output a .tar.bz2'd modules after the callbacks have run"
85   echo "        --kerncache=<tbz2>      File to output a .tar.bz2'd kernel,"
86   echo "                                contents of /lib/modules/ and the kernel config"
87   echo "                                NOTE: This is created before the callbacks are run!"
88   echo "        --no-kernel-sources     This option is only valid if kerncache is defined"
89   echo "                                If there is a valid kerncache no checks will be made"
90   echo "                                against a kernel source tree"
91   echo "        --initramfs-overlay=<dir>"
92   echo "                                Directory structure to include in the initramfs,"
93   echo "                                only available on 2.6 kernels that don't use bootsplash"
94 }
95
96 usage() {
97   echo "Gentoo Linux Genkernel ${GK_V}"
98   echo "Usage: "
99   echo "        genkernel [options] all"
100   echo
101   echo 'Some useful options:'
102   echo '        --menuconfig            Run menuconfig after oldconfig'
103   echo '        --no-clean              Do not run make clean before compilation'
104   echo '        --no-mrproper           Do not run make mrproper before compilation,'
105   echo '                                this is implied by --no-clean.'
106   echo
107   echo 'For a detailed list of supported options and flags; issue:'
108   echo '        genkernel --help'
109 }
110
111 parse_opt() {
112         case "$1" in
113                 *\=*)
114                         echo "$1" | cut -f2- -d=
115                 ;;
116         esac
117 }
118
119 parse_cmdline() {
120         case "$*" in
121               --kernel-cc=*)
122                       CMD_KERNEL_CC=`parse_opt "$*"`
123                       print_info 2 "CMD_KERNEL_CC: $CMD_KERNEL_CC"
124               ;;
125               --kernel-ld=*)
126                       CMD_KERNEL_LD=`parse_opt "$*"`
127                       print_info 2 "CMD_KERNEL_LD: $CMD_KERNEL_LD"
128               ;;
129               --kernel-as=*)
130                       CMD_KERNEL_AS=`parse_opt "$*"`
131                       print_info 2 "CMD_KERNEL_AS: $CMD_KERNEL_AS"
132               ;;
133               --kernel-make=*)
134                       CMD_KERNEL_MAKE=`parse_opt "$*"`
135                       print_info 2 "CMD_KERNEL_MAKE: $CMD_KERNEL_MAKE"
136               ;;
137               --kernel-cross-compile=*)
138                       CMD_KERNEL_CROSS_COMPILE=`parse_opt "$*"`
139                       CMD_KERNEL_CROSS_COMPILE=$(echo ${CMD_KERNEL_CROSS_COMPILE}|sed -e 's/.*[^-]$/&-/g')
140                       print_info 2 "CMD_KERNEL_CROSS_COMPILE: $CMD_KERNEL_CROSS_COMPILE"
141               ;;
142               --utils-cc=*)
143                       CMD_UTILS_CC=`parse_opt "$*"`
144                       print_info 2 "CMD_UTILS_CC: $CMD_UTILS_CC"
145               ;;
146               --utils-ld=*)
147                       CMD_UTILS_LD=`parse_opt "$*"`
148                       print_info 2 "CMD_UTILS_LD: $CMD_UTILS_LD"
149               ;;
150               --utils-as=*)
151                       CMD_UTILS_AS=`parse_opt "$*"`
152                       print_info 2 "CMD_UTILS_AS: $CMD_UTILS_AS"
153               ;;
154               --utils-make=*)
155                       CMD_UTILS_MAKE=`parse_opt "$*"`
156                       print_info 2 "CMD_UTILS_MAKE: $CMD_UTILS_MAKE"
157               ;;
158               --makeopts=*)
159                       CMD_MAKEOPTS=`parse_opt "$*"`
160                       print_info 2 "CMD_MAKEOPTS: $CMD_MAKEOPTS"
161               ;;
162               --mountboot)
163                       CMD_MOUNTBOOT=1
164                       print_info 2 "CMD_MOUNTBOOT: $CMD_MOUNTBOOT"
165               ;;
166               --no-mountboot)
167                       CMD_MOUNTBOOT=0
168                       print_info 2 "CMD_MOUNTBOOT: $CMD_MOUNTBOOT"
169               ;;
170               --do-keymap-auto)
171                       CMD_DOKEYMAPAUTO=1
172                       print_info 2 "CMD_DOKEYMAPAUTO: $CMD_DOKEYMAPAUTO"
173               ;;
174               --evms2)
175                       CMD_EVMS2=1
176                       print_info 2 "CMD_EVMS2: $CMD_EVMS2"
177               ;;
178               --unionfs)
179                       CMD_UNIONFS=1
180                       print_info 2 "CMD_UNIONFS: $CMD_UNIONFS"
181               ;;
182               --lvm2)
183                       CMD_LVM2=1
184                       print_info 2 "CMD_LVM2: $CMD_LVM2"
185               ;;
186               --no-busybox)
187                       CMD_NO_BUSYBOX=1
188                       print_info 2 "CMD_NO_BUSYBOX: $CMD_NO_BUSYBOX"
189               ;;
190               --dmraid)
191                       CMD_DMRAID=1
192                       print_info 2 "CMD_DMRAID: $CMD_DMRAID"
193               ;;
194               --bootloader=*)
195                       CMD_BOOTLOADER=`parse_opt "$*"`
196                       print_info 2 "CMD_BOOTLOADER: $CMD_BOOTLOADER"
197               ;;
198               --debuglevel=*)
199                       CMD_DEBUGLEVEL=`parse_opt "$*"`
200                       DEBUGLEVEL="${CMD_DEBUGLEVEL}"
201                       print_info 2 "CMD_DEBUGLEVEL: $CMD_DEBUGLEVEL"
202               ;;
203               --menuconfig)
204                       TERM_LINES=`stty -a | head -n 1 | cut -d\  -f5 | cut -d\; -f1`
205                       TERM_COLUMNS=`stty -a | head -n 1 | cut -d\  -f7 | cut -d\; -f1`
206
207                       if [[ TERM_LINES -lt 19 || TERM_COLUMNS -lt 80 ]]
208                       then
209                               echo "Error: You need a terminal with at least 80 columns"
210                               echo "       and 19 lines for --menuconfig; try --nomenuconfig..."
211                               exit 1
212                       fi
213                       CMD_MENUCONFIG=1
214                       print_info 2 "CMD_MENUCONFIG: $CMD_MENUCONFIG"
215               ;;
216               --no-menuconfig)
217                       CMD_MENUCONFIG=0
218                       print_info 2 "CMD_MENUCONFIG: $CMD_MENUCONFIG"
219               ;;
220               --gconfig)
221                       CMD_GCONFIG=1
222                       print_info 2 "CMD_GCONFIG: $CMD_GCONFIG"
223               ;;
224               --xconfig)
225                       CMD_XCONFIG=1
226                       print_info 2 "CMD_XCONFIG: $CMD_XCONFIG"
227               ;;
228               --save-config)
229                       CMD_SAVE_CONFIG=1
230                       print_info 2 "CMD_SAVE_CONFIG: $CMD_SAVE_CONFIG"
231               ;;
232               --no-save-config)
233                       CMD_SAVE_CONFIG=0
234                       print_info 2 "CMD_SAVE_CONFIG: $CMD_SAVE_CONFIG"
235               ;;
236               --mrproper)
237                       CMD_MRPROPER=1
238                       print_info 2 "CMD_MRPROPER: $CMD_MRPROPER"
239               ;;
240               --no-mrproper)
241                       CMD_MRPROPER=0
242                       print_info 2 "CMD_MRPROPER: $CMD_MRPROPER"
243               ;;
244               --clean)
245                       CMD_CLEAN=1
246                       print_info 2 "CMD_CLEAN: $CMD_CLEAN"
247               ;;
248               --no-clean)
249                       CMD_CLEAN=0
250                       print_info 2 "CMD_CLEAN: $CMD_CLEAN"
251               ;;
252               --oldconfig)
253                       CMD_CLEAN=0
254                       CMD_OLDCONFIG=1
255                       print_info 2 "CMD_CLEAN: $CMD_CLEAN"
256                       print_info 2 "CMD_OLDCONFIG: $CMD_OLDCONFIG"
257               ;;
258               --bootsplash=*)
259                       CMD_BOOTSPLASH=1
260                       CMD_GENSPLASH=0
261                       BOOTSPLASH_THEME=`parse_opt "$*"`
262                       print_info 2 "CMD_BOOTSPLASH: $CMD_BOOTSPLASH"
263                       print_info 2 "CMD_GENSPLASH: $CMD_GENSPLASH"
264                       print_info 2 "BOOTSPLASH_THEME: $BOOTSPLASH_THEME"
265               ;;
266               --bootsplash)
267                       CMD_BOOTSPLASH=1
268                       CMD_GENSPLASH=0
269                       print_info 2 "CMD_BOOTSPLASH: $CMD_BOOTSPLASH"
270                       print_info 2 "CMD_GENSPLASH: $CMD_GENSPLASH"
271               ;;
272               --no-bootsplash)
273                       CMD_BOOTSPLASH=0
274                       print_info 2 "CMD_BOOTSPLASH: $CMD_BOOTSPLASH"
275               ;;
276               --gensplash=*)
277                       CMD_GENSPLASH=1
278                       CMD_BOOTSPLASH=0
279                       GENSPLASH_THEME=`parse_opt "$*"`
280                       print_info 2 "CMD_GENSPLASH: $CMD_GENSPLASH"
281                       print_info 2 "GENSPLASH_THEME: $GENSPLASH_THEME"
282                       print_info 2 "CMD_BOOTSPLASH: $CMD_BOOTSPLASH"
283               ;;
284               --gensplash)
285                       CMD_GENSPLASH=1
286                       CMD_BOOTSPLASH=0
287                       GENSPLASH_THEME='default'
288                       print_info 2 "CMD_GENSPLASH: $CMD_GENSPLASH"
289                       print_info 2 "CMD_BOOTSPLASH: $CMD_BOOTSPLASH"
290               ;;
291               --no-gensplash)
292                       CMD_GENSPLASH=0
293                       print_info 2 "CMD_GENSPLASH: $CMD_GENSPLASH"
294               ;;
295               --gensplash-res=*)
296                       GENSPLASH_RES=`parse_opt "$*"`
297                       print info 2 "GENSPLASH_RES: $GENSPLASH_RES"
298               ;;
299               --install)
300                       CMD_NOINSTALL=0
301                       print_info 2 "CMD_NOINSTALL: $CMD_NOINSTALL"
302               ;;
303               --no-install)
304                       CMD_NOINSTALL=1
305                       print_info 2 "CMD_NOINSTALL: $CMD_NOINSTALL"
306               ;;
307               --no-initrdmodules)
308                       CMD_NOINITRDMODULES=1
309                       print_info 2 "CMD_NOINITRDMODULES: $CMD_NOINITRDMODULES"
310               ;;
311               --udev)
312                       echo
313                       echo
314                       print_info 1 "--udev is deprecated and no longer necessary as udev is on by default"
315                       sleep 3
316                       echo
317                       echo
318                       print_info 2 "CMD_UDEV: $CMD_UDEV"
319               ;;
320               --no-udev)
321                       CMD_NO_UDEV=1
322                       print_info 2 "CMD_NO_UDEV: $CMD_NO_UDEV"
323               ;;
324               --no-devfs)
325                       CMD_NO_DEVFS=1
326                       print_info 2 "CMD_NO_DEVFS: $CMD_NO_DEVFS"
327               ;;
328               --callback=*)
329                       CMD_CALLBACK=`parse_opt "$*"`
330                       print_info 2 "CMD_CALLBACK: $CMD_CALLBACK/$*"
331               ;;
332               --tempdir=*)
333                       TEMP=`parse_opt "$*"`
334                       print_info 2 "TEMP: $TEMP"
335               ;; 
336               --arch-override=*)
337                       CMD_ARCHOVERRIDE=`parse_opt "$*"`
338                       print_info 2 "CMD_ARCHOVERRIDE: $CMD_ARCHOVERRIDE"
339               ;;
340               --color)
341                       CMD_USECOLOR=1
342                       print_info 2 "CMD_USECOLOR: $CMD_USECOLOR"
343               ;;
344               --no-color)
345                       CMD_USECOLOR=0
346                       print_info 2 "CMD_USECOLOR: $CMD_USECOLOR"
347               ;;
348               --debugfile=*)
349                       CMD_DEBUGFILE=`parse_opt "$*"`
350                       DEBUGFILE=`parse_opt "$*"`
351                       print_info 2 "CMD_DEBUGFILE: $CMD_DEBUGFILE"
352                       print_info 2 "DEBUGFILE: $CMD_DEBUGFILE"
353               ;;
354               --kerneldir=*)
355                       CMD_KERNELDIR=`parse_opt "$*"`
356                       print_info 2 "CMD_KERNELDIR: $CMD_KERNELDIR"
357               ;;
358               --kernel-config=*)
359                       CMD_KERNEL_CONFIG=`parse_opt "$*"`
360                       print_info 2 "CMD_KERNEL_CONFIG: $CMD_KERNEL_CONFIG"
361               ;;
362               --module-prefix=*)
363                       CMD_INSTALL_MOD_PATH=`parse_opt "$*"`
364                       print_info 2 "CMD_INSTALL_MOD_PATH: $CMD_INSTALL_MOD_PATH"
365               ;;
366               --cachedir=*)
367                       CACHE_DIR=`parse_opt "$*"`
368                       print_info 2 "CACHE_DIR: $CACHE_DIR"
369               ;;
370               --minkernpackage=*)
371                       CMD_MINKERNPACKAGE=`parse_opt "$*"`
372                       print_info 2 "MINKERNPACKAGE: $CMD_MINKERNPACKAGE"
373               ;;
374               --modulespackage=*)
375                       CMD_MODULESPACKAGE=`parse_opt "$*"`
376                       print_info 2 "MODULESPACKAGE: $CMD_MODULESPACKAGE"
377               ;;
378               --kerncache=*)
379                       CMD_KERNCACHE=`parse_opt "$*"`
380                       print_info 2 "KERNCACHE: $CMD_KERNCACHE"
381               ;;
382               --kernname=*)
383                       CMD_KERNNAME=`parse_opt "$*"`
384                       print_info 2 "KERNNAME: $CMD_KERNNAME"
385               ;;
386               --no-kernel-sources)
387                       CMD_NO_KERNEL_SOURCES=1
388                       print_info 2 "CMD_NO_KERNEL_SOURCES: $CMD_NO_KERNEL_SOURCES"
389               ;;
390               --initramfs-overlay=*)
391                       CMD_INITRAMFS_OVERLAY=`parse_opt "$*"`
392                       print_info 2 "CMD_INITRAMFS_OVERLAY: $CMD_INITRAMFS_OVERLAY"
393               ;;
394               --linuxrc=*)
395                         CMD_LINUXRC=`parse_opt "$*"`
396                         print_info 2 "CMD_LINUXRC: $CMD_LINUXRC"
397               ;;
398               --genzimage)
399                         GENERATE_Z_IMAGE=1
400                         print_info 2 "GENERATE_Z_IMAGE: $GENERATE_Z_IMAGE"
401               ;;
402               all)
403                       BUILD_KERNEL=1
404                       BUILD_MODULES=1
405                       BUILD_INITRD=1
406               ;;
407               initrd)
408                       BUILD_INITRD=1
409               ;;
410               kernel)
411                       BUILD_KERNEL=1
412                       BUILD_MODULES=1
413                       BUILD_INITRD=0
414               ;;
415               bzImage)
416                       BUILD_KERNEL=1
417                       BUILD_MODULES=0
418                       BUILD_INITRD=1
419                       CMD_NOINITRDMODULES=1
420                       print_info 2 "CMD_NOINITRDMODULES: $CMD_NOINITRDMODULES"
421               ;;
422               --help)
423                       longusage
424                       exit 1
425               ;;
426               --version)
427                       echo "${GK_V}"
428                       exit 0
429               ;;
430               *)
431                       echo "Error: Unknown option '$*'!"
432                       exit 1
433               ;;
434         esac
435 }