GRUB Bootloader support - bug #57576. Thanks to Mathias Gug for the patch!
[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 "  kernel                        Build only the kernel and modules"
11   echo "  initrd                        Build only the initrd"
12   echo
13   echo "Available Options: "
14   echo "  Debug settings"
15   echo "        --debuglevel=<0-5>      Debug Verbosity Level"
16   echo "        --debugfile=<outfile>   Output file for debug info"
17   echo "        --color                 Output debug in color"
18   echo "        --no-color              Do not output debug in color"
19   echo "  Kernel Configuration settings"
20   echo "        --menuconfig            Run menuconfig after oldconfig"
21   echo "        --no-menuconfig         Do not run menuconfig after oldconfig"
22   echo "        --gconfig               Run gconfig after oldconfig"
23   echo "        --xconfig               Run xconfig after oldconfig"
24   echo "        --save-config           Save the configuration to /etc/kernels"
25   echo "        --no-save-config        Don't save the configuration to /etc/kernels"
26   echo "  Kernel Compile settings"
27   echo "        --clean                 Run make clean before compilation"
28   echo "        --mrproper              Run make mrproper before compilation"
29   echo "        --no-clean              Do not run make clean before compilation"
30   echo "        --no-mrproper           Do not run make mrproper before compilation"
31   echo "        --oldconfig             Implies --no-clean and runs a 'make oldconfig'"
32   echo "        --bootsplash            Install bootsplash support to the initrd"
33   echo "        --no-bootsplash         Do not use bootsplash"
34   echo "        --install               Install the kernel after building"
35   echo "        --no-install            Do not install the kernel after building"
36   echo "        --no-initrdmodules      Don't copy any modules to the initrd"
37   echo "        --callback=<...>        Run the specified arguments after"
38   echo "                                the kernel and modules have been"
39   echo "                                compiled."
40   echo "  Kernel settings"
41   echo "        --kerneldir=<dir>       Location of the kernel sources"
42   echo "        --kernel-config=<file>  Kernel configuration file to use for compilation"
43   echo "        --module-prefix=<dir>   Prefix to kernel module destination, modules will"
44   echo "                                be installed in <prefix>/lib/modules"
45   echo "  Low-Level Compile settings"
46   echo "        --kernel-cc=<compiler>  Compiler to use for kernel (e.g. distcc)"
47   echo "        --kernel-as=<assembler> Assembler to use for kernel"
48   echo "        --kernel-ld=<linker>    Linker to use for kernel"
49   echo "        --kernel-make=<makeprg> GNU Make to use for kernel"
50   echo "        --utils-cc=<compiler>   Compiler to use for utilities"
51   echo "        --utils-as=<assembler>  Assembler to use for utils"
52   echo "        --utils-ld=<linker>     Linker to use for utils"
53   echo "        --utils-make=<makeprog> GNU Make to use for utils"
54   echo "        --makeopts=<makeopts>   Make options such as -j2, etc."
55   echo "        --mountboot             Mount /boot automatically"
56   echo "        --no-mountboot          Don't mount /boot automatically"  
57   echo "  Initialization"
58   echo "        --bootsplash=<theme>    Force bootsplash using <theme>."
59   echo "        --do-keymap-auto        Forces keymap selection at boot."
60   echo "        --no-lvm2               Don't add in LVM2 support."
61   echo "        --bootloader=grub       Add new kernel to grub configuration"
62   echo "  Internals"
63   echo "        --tempdir=<dir>   Location of Genkernel's temporary directory"
64   echo "        --arch-override=<arch>  Force to arch instead of autodetect"
65   echo "        --busybox-config=<file> Busybox configuration file to use"
66   echo "        --busybox-bin=<file>    Don't compile busybox, use this _static_"
67   echo "                                bzip2'd binary"
68   echo "  Output Settings"
69   echo "        --minkernpackage=<tbz2> File to output a .tar.bz2'd kernel and initrd:"
70   echo "                                No modules outside of the initrd will be"
71   echo "                                included..."
72 }
73
74 usage() {
75   echo "Gentoo Linux Genkernel ${GK_V}"
76   echo "Usage: "
77   echo "        genkernel [options] all"
78   echo
79   echo 'Some useful options:'
80   echo '        --menuconfig            Run menuconfig after oldconfig'
81   echo '        --no-clean              Do not run make clean before compilation'
82   echo '        --no-mrproper           Do not run make mrproper before compilation,'
83   echo '                                this is implied by --no-clean.'
84   echo
85   echo 'For a detailed list of supported options and flags; issue:'
86   echo '        genkernel --help'
87 }
88
89 parse_opt() {
90         case "$1" in
91                 *\=*)
92                         echo "$1" | cut -f2- -d=
93                 ;;
94         esac
95 }
96
97 parse_cmdline() {
98         case "$*" in
99               --kernel-cc*)
100                       CMD_KERNEL_CC=`parse_opt "$*"`
101                       print_info 2 "CMD_KERNEL_CC: $CMD_KERNEL_CC"
102               ;;
103               --kernel-ld*)
104                       CMD_KERNEL_LD=`parse_opt "$*"`
105                       print_info 2 "CMD_KERNEL_LD: $CMD_KERNEL_LD"
106               ;;
107               --kernel-as*)
108                       CMD_KERNEL_AS=`parse_opt "$*"`
109                       print_info 2 "CMD_KERNEL_AS: $CMD_KERNEL_AS"
110               ;;
111               --kernel-make*)
112                       CMD_KERNEL_MAKE=`parse_opt "$*"`
113                       print_info 2 "CMD_KERNEL_MAKE: $CMD_KERNEL_MAKE"
114               ;;
115               --utils-cc*)
116                       CMD_UTILS_CC=`parse_opt "$*"`
117                       print_info 2 "CMD_UTILS_CC: $CMD_UTILS_CC"
118               ;;
119               --utils-ld*)
120                       CMD_UTILS_LD=`parse_opt "$*"`
121                       print_info 2 "CMD_UTILS_LD: $CMD_UTILS_LD"
122               ;;
123               --utils-as*)
124                       CMD_UTILS_AS=`parse_opt "$*"`
125                       print_info 2 "CMD_UTILS_AS: $CMD_UTILS_AS"
126               ;;
127               --utils-make*)
128                       CMD_UTILS_MAKE=`parse_opt "$*"`
129                       print_info 2 "CMD_UTILS_MAKE: $CMD_UTILS_MAKE"
130               ;;
131               --makeopts*)
132                       CMD_MAKEOPTS=`parse_opt "$*"`
133                       print_info 2 "CMD_MAKEOPTS: $CMD_MAKEOPTS"
134               ;;
135               --mountboot)
136                       CMD_MOUNTBOOT=1
137                       print_info 2 "CMD_MOUNTBOOT: $CMD_MOUNTBOOT"
138               ;;
139               --no-mountboot)
140                       CMD_MOUNTBOOT=0
141                       print_info 2 "CMD_MOUNTBOOT: $CMD_MOUNTBOOT"
142               ;;
143               --do-keymap-auto)
144                       CMD_DOKEYMAPAUTO=1
145                       print_info 2 "CMD_DOKEYMAPAUTO: $CMD_DOKEYMAPAUTO"
146               ;;
147               --no-lvm-2)
148                       CMD_NOLVM2=1
149                       print_info 2 'CMD_NOLVM2: 1'
150               ;;
151               --bootloader*)
152                       CMD_BOOTLOADER=`parse_opt "$*"`
153                       print_info 2 "CMD_BOOTLOADER: $CMD_BOOTLOADER"
154               ;;
155               --debuglevel*)
156                       CMD_DEBUGLEVEL=`parse_opt "$*"`
157                       DEBUGLEVEL="${CMD_DEBUGLEVEL}"
158                       print_info 2 "CMD_DEBUGLEVEL: $CMD_DEBUGLEVEL"
159               ;;
160               --menuconfig)
161                       TERM_LINES=`stty -a | head -n 1 | cut -d\  -f5 | cut -d\; -f1`
162                       TERM_COLUMNS=`stty -a | head -n 1 | cut -d\  -f7 | cut -d\; -f1`
163
164                       if [[ TERM_LINES -lt 19 || TERM_COLUMNS -lt 80 ]]
165                       then
166                               echo "Error: You need a terminal with at least 80 columns"
167                               echo "       and 19 lines for --menuconfig; try --nomenuconfig..."
168                               exit 1
169                       fi
170                       CMD_MENUCONFIG=1
171                       print_info 2 "CMD_MENUCONFIG: $CMD_MENUCONFIG"
172               ;;
173               --no-menuconfig)
174                       CMD_MENUCONFIG=0
175                       print_info 2 "CMD_MENUCONFIG: $CMD_MENUCONFIG"
176               ;;
177               --gconfig)
178                       CMD_GCONFIG=1
179                       print_info 2 "CMD_GCONFIG: $CMD_GCONFIG"
180               ;;
181               --xconfig)
182                       CMD_XCONFIG=1
183                       print_info 2 "CMD_XCONFIG: $CMD_XCONFIG"
184               ;;
185               --save-config)
186                       CMD_SAVE_CONFIG=1
187                       print_info 2 "CMD_SAVE_CONFIG: $CMD_SAVE_CONFIG"
188               ;;
189               --no-save-config)
190                       CMD_SAVE_CONFIG=0
191                       print_info 2 "CMD_SAVE_CONFIG: $CMD_SAVE_CONFIG"
192               ;;
193               --mrproper)
194                       CMD_MRPROPER=1
195                       print_info 2 "CMD_MRPROPER: $CMD_MRPROPER"
196               ;;
197               --no-mrproper)
198                       CMD_MRPROPER=0
199                       print_info 2 "CMD_MRPROPER: $CMD_MRPROPER"
200               ;;
201               --clean)
202                       CMD_CLEAN=1
203                       print_info 2 "CMD_CLEAN: $CMD_CLEAN"
204               ;;
205               --no-clean)
206                       CMD_CLEAN=0
207                       print_info 2 "CMD_CLEAN: $CMD_CLEAN"
208               ;;
209               --oldconfig)
210                       CMD_CLEAN=0
211                       CMD_OLDCONFIG=1
212                       print_info 2 "CMD_CLEAN: $CMD_CLEAN"
213                       print_info 2 "CMD_OLDCONFIG: $CMD_OLDCONFIG"
214               ;;
215               --bootsplash=*)
216                       CMD_BOOTSPLASH=1
217                       BOOTSPLASH_THEME=`parse_opt "$*"`
218                       print_info 2 "CMD_BOOTSPLASH: $CMD_BOOTSPLASH"
219                       print_info 2 "BOOTSPLASH_THEME: $BOOTSPLASH_THEME"
220               ;;
221               --bootsplash)
222                       CMD_BOOTSPLASH=1
223                       print_info 2 "CMD_BOOTSPLASH: $CMD_BOOTSPLASH"
224               ;;
225               --no-bootsplash)
226                       CMD_BOOTSPLASH=0
227                       print_info 2 "CMD_BOOTSPLASH: $CMD_BOOTSPLASH"
228               ;;
229               --install)
230                       CMD_NOINSTALL=0
231                       print_info 2 "CMD_NOINSTALL: $CMD_NOINSTALL"
232               ;;
233               --no-install)
234                       CMD_NOINSTALL=1
235                       print_info 2 "CMD_NOINSTALL: $CMD_NOINSTALL"
236               ;;
237               --no-initrdmodules)
238                       CMD_NOINITRDMODULES=1
239                       print_info 2 "CMD_NOINITRDMODULES: $CMD_NOINITRDMODULES"
240               ;;
241               --callback*)
242                       CMD_CALLBACK=`parse_opt "$*"`
243                       print_info 2 "CMD_CALLBACK: $CMD_CALLBACK/$*"
244               ;;
245               --tempdir*)
246                 TEMP=`parse_opt "$*"`
247                 print_info 2 "TEMP: $TEMP"
248               ;; 
249               --arch-override*)
250                       CMD_ARCHOVERRIDE=`parse_opt "$*"`
251                       print_info 2 "CMD_ARCHOVERRIDE: $CMD_ARCHOVERRIDE"
252               ;;
253               --color)
254                       CMD_USECOLOR=1
255                       print_info 2 "CMD_USECOLOR: $CMD_USECOLOR"
256               ;;
257               --no-color)
258                       CMD_USECOLOR=0
259                       print_info 2 "CMD_USECOLOR: $CMD_USECOLOR"
260               ;;
261               --debugfile*)
262                       CMD_DEBUGFILE=`parse_opt "$*"`
263                       DEBUGFILE=`parse_opt "$*"`
264                       print_info 2 "CMD_DEBUGFILE: $CMD_DEBUGFILE"
265                       print_info 2 "DEBUGFILE: $CMD_DEBUGFILE"
266               ;;
267               --kerneldir*)
268                       CMD_KERNELDIR=`parse_opt "$*"`
269                       print_info 2 "CMD_KERNELDIR: $CMD_KERNELDIR"
270               ;;
271               --kernel-config*)
272                       CMD_KERNEL_CONFIG=`parse_opt "$*"`
273                       print_info 2 "CMD_KERNEL_CONFIG: $CMD_KERNEL_CONFIG"
274               ;;
275               --module-prefix*)
276                       CMD_INSTALL_MOD_PATH=`parse_opt "$*"`
277                       print_info 2 "CMD_INSTALL_MOD_PATH: $CMD_INSTALL_MOD_PATH"
278               ;;
279               --busybox-config*)
280                       CMD_BUSYBOX_CONFIG=`parse_opt "$*"`
281                       print_info 2 "CMD_BUSYBOX_CONFIG: $CMD_BUSYBOX_CONFIG"
282               ;;
283               --busybox-bin*)
284                       CMD_BUSYBOX_BIN=`parse_opt "$*"`
285                       print_info 2 "CMD_BUSYBOX_BIN: $CMD_BUSYBOX_BIN"
286               ;;
287               --minkernpackage*)
288                       CMD_MINKERNPACKAGE=`parse_opt "$*"`
289                       print_info 2 "MINKERNPACKAGE: $CMD_MINKERNPACKAGE"
290               ;;
291               all)
292                       BUILD_KERNEL=1
293                       BUILD_INITRD=1
294               ;;
295               initrd)
296                       BUILD_INITRD=1
297               ;;
298               kernel)
299                       BUILD_KERNEL=1
300               ;;
301               --help)
302                       longusage
303                       exit 1
304               ;;
305               --version)
306                       echo "${GK_V}"
307                       exit 0
308               ;;
309               *)
310                       echo "Error: Unknown option '$*'!"
311                       exit 1
312               ;;
313         esac
314 }