genconfig.sh revision 5fe77cf9ed586a84c5ccd289154d0b543d2b4949
1#!/bin/bash
2
3# This has to be a separate file from scripts/make.sh so it can be called
4# before menuconfig.  (It's called again from scripts/make.sh just to be sure.)
5
6mkdir -p generated
7
8source configure
9
10# Probe for a single config symbol with a "compiles or not" test.
11# Symbol name is first argument, flags second, feed C file to stdin
12probesymbol()
13{
14  ${CROSS_COMPILE}${CC} $CFLAGS -xc -o /dev/null $2 - 2>/dev/null
15  [ $? -eq 0 ] && DEFAULT=y || DEFAULT=n
16  rm a.out 2>/dev/null
17  echo -e "config $1\n\tbool" || exit 1
18  echo -e "\tdefault $DEFAULT\n" || exit 1
19}
20
21probeconfig()
22{
23  # Probe for container support on target
24  probesymbol TOYBOX_CONTAINER << EOF
25    #include <linux/sched.h>
26    int x=CLONE_NEWNS|CLONE_NEWUTS|CLONE_NEWIPC|CLONE_NEWNET;
27
28    int main(int argc, char *argv[]) { return unshare(x); }
29EOF
30
31  probesymbol TOYBOX_FIFREEZE -c << EOF
32    #include <linux/fs.h>
33    #ifndef FIFREEZE
34    #error nope
35    #endif
36EOF
37
38  # Hard to come by in uClibc.
39  probesymbol TOYBOX_ICONV -c << EOF
40    #include "iconv.h"
41EOF
42}
43
44genconfig()
45{
46  # I could query the directory here, but I want to control the order
47  # and capitalization in the menu
48  for j in toys/*/README
49  do
50    DIR="$(dirname "$j")"
51
52    [ $(ls "$DIR" | wc -l) -lt 2 ] && continue
53
54    echo "menu \"$(head -n 1 $j)\""
55    echo
56
57    # extract config stanzas from each source file, in alphabetical order
58    for i in $(ls -1 $DIR/*.c)
59    do
60      # Grab the config block for Config.in
61      echo "# $i"
62      sed -n '/^\*\//q;/^config [A-Z]/,$p' $i || return 1
63      echo
64    done
65
66    echo endmenu
67  done
68}
69
70probeconfig > generated/Config.probed || rm generated/Config.probed
71genconfig > generated/Config.in || rm generated/Config.in
72