OSDN Git Service

du: 32 bit systems were maxing out at 2GB when they should max out at 2TB (1<<32...
[android-x86/external-toybox.git] / scripts / genconfig.sh
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
6 mkdir -p generated
7
8 source configure
9
10 probecc()
11 {
12   ${CROSS_COMPILE}${CC} $CFLAGS -xc -o /dev/null $1 -
13 }
14
15 # Probe for a single config symbol with a "compiles or not" test.
16 # Symbol name is first argument, flags second, feed C file to stdin
17 probesymbol()
18 {
19   probecc $2 2>/dev/null && DEFAULT=y || DEFAULT=n
20   rm a.out 2>/dev/null
21   echo -e "config $1\n\tbool" || exit 1
22   echo -e "\tdefault $DEFAULT\n" || exit 1
23 }
24
25 probeconfig()
26 {
27   > generated/cflags
28   # llvm produces its own really stupid warnings about things that aren't wrong,
29   # and although you can turn the warning off, gcc reacts badly to command line
30   # arguments it doesn't understand. So probe.
31   [ -z "$(probecc -Wno-string-plus-int <<< \#warn warn 2>&1 | grep string-plus-int)" ] &&
32     echo -Wno-string-plus-int >> generated/cflags
33
34   # Probe for container support on target
35   probesymbol TOYBOX_CONTAINER << EOF
36     #include <linux/sched.h>
37     int x=CLONE_NEWNS|CLONE_NEWUTS|CLONE_NEWIPC|CLONE_NEWNET;
38
39     int main(int argc, char *argv[]) { return unshare(x); }
40 EOF
41
42   probesymbol TOYBOX_FIFREEZE -c << EOF
43     #include <linux/fs.h>
44     #ifndef FIFREEZE
45     #error nope
46     #endif
47 EOF
48
49   # Work around some uClibc limitations
50   probesymbol TOYBOX_ICONV -c << EOF
51     #include "iconv.h"
52 EOF
53   probesymbol TOYBOX_FALLOCATE << EOF
54     #include <fcntl.h>
55
56     int main(int argc, char *argv[]) { return posix_fallocate(0,0,0); }
57 EOF
58   
59   # Android and some other platforms miss utmpx
60   probesymbol TOYBOX_UTMPX -c << EOF
61     #include <utmpx.h>
62     #ifndef BOOT_TIME
63     #error nope
64     #endif
65     int main(int argc, char *argv[]) {
66       struct utmpx *a; 
67       if (0 != (a = getutxent())) return 0;
68       return 1;
69     }
70 EOF
71
72   # Android is missing shadow.h
73   probesymbol TOYBOX_SHADOW -c << EOF
74     #include <shadow.h>
75     int main(int argc, char *argv[]) {
76       struct spwd *a = getspnam("root"); return 0;
77     }
78 EOF
79
80   # Some commands are android-specific
81   probesymbol TOYBOX_ON_ANDROID -c << EOF
82     #ifndef __ANDROID__
83     #error nope
84     #endif
85 EOF
86
87   # nommu support
88   probesymbol TOYBOX_FORK << EOF
89     #include <unistd.h>
90     int main(int argc, char *argv[]) { return fork(); }
91 EOF
92   echo -e '\tdepends on !TOYBOX_MUSL_NOMMU_IS_BROKEN'
93 }
94
95 genconfig()
96 {
97   # Reverse sort puts posix first, examples last.
98   for j in $(ls toys/*/README | sort -r)
99   do
100     DIR="$(dirname "$j")"
101
102     [ $(ls "$DIR" | wc -l) -lt 2 ] && continue
103
104     echo "menu \"$(head -n 1 $j)\""
105     echo
106
107     # extract config stanzas from each source file, in alphabetical order
108     for i in $(ls -1 $DIR/*.c)
109     do
110       # Grab the config block for Config.in
111       echo "# $i"
112       sed -n '/^\*\//q;/^config [A-Z]/,$p' $i || return 1
113       echo
114     done
115
116     echo endmenu
117   done
118 }
119
120 probeconfig > generated/Config.probed || rm generated/Config.probed
121 genconfig > generated/Config.in || rm generated/Config.in
122
123 # Find names of commands that can be built standalone in these C files
124 toys()
125 {
126   grep 'TOY(.*)' "$@" | grep -v TOYFLAG_NOFORK | grep -v "0))" | \
127     sed -rn 's/([^:]*):.*(OLD|NEW)TOY\( *([a-zA-Z][^,]*) *,.*/\1:\3/p'
128 }
129
130 WORKING=
131 PENDING=
132 toys toys/*/*.c | (
133 while IFS=":" read FILE NAME
134 do
135   [ "$NAME" == help ] && continue
136   [ "$NAME" == install ] && continue
137   echo -e "$NAME: $FILE *.[ch] lib/*.[ch]\n\tscripts/single.sh $NAME\n"
138   echo -e "test_$NAME:\n\tscripts/test.sh $NAME\n"
139   [ "${FILE/pending//}" != "$FILE" ] &&
140     PENDING="$PENDING $NAME" ||
141     WORKING="$WORKING $NAME"
142 done > .singlemake &&
143 echo -e "clean::\n\trm -f $WORKING $PENDING" >> .singlemake &&
144 echo -e "list:\n\t@echo $(echo $WORKING $PENDING | tr ' ' '\n' | sort | xargs)"\
145   >> .singlemake &&
146 echo -e "list_working:\n\t@echo $(echo $WORKING | tr ' ' '\n' | sort | xargs)" \
147   >> .singlemake &&
148 echo -e "list_pending:\n\t@echo $(echo $PENDING | tr ' ' '\n' | sort | xargs)" \
149   >> .singlemake
150 )