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