blob: e040aea58a44a438b2db91ad9517a6fd1d413783 [file] [log] [blame]
Rob Landley28964802008-01-19 17:08:39 -06001#!/bin/bash
2
Rob Landley7c04f012008-01-20 19:00:16 -06003# 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
Rob Landley28964802008-01-19 17:08:39 -06006mkdir -p generated
7
Rob Landley2bd3a5d2012-02-13 08:44:32 -06008source configure
9
Rob Landley76e1cb32014-04-16 07:49:32 -050010# 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
Rob Landley1b7ad012012-02-23 21:03:18 -060021probeconfig()
Rob Landley28964802008-01-19 17:08:39 -060022{
Rob Landley27f57792012-02-03 23:16:28 -060023 # Probe for container support on target
Rob Landley76e1cb32014-04-16 07:49:32 -050024 probesymbol TOYBOX_CONTAINER << EOF
Georgi Chorbadzhiyski2c27fcf2012-03-04 01:24:06 -060025 #include <linux/sched.h>
Rob Landley27f57792012-02-03 23:16:28 -060026 int x=CLONE_NEWNS|CLONE_NEWUTS|CLONE_NEWIPC|CLONE_NEWNET;
Rob Landleyf9fdd3c2012-03-19 20:15:08 -050027
28 int main(int argc, char *argv[]) { return unshare(x); }
Rob Landley27f57792012-02-03 23:16:28 -060029EOF
Rob Landley76e1cb32014-04-16 07:49:32 -050030
31 probesymbol TOYBOX_FIFREEZE -c << EOF
32 #include <linux/fs.h>
33 #ifndef FIFREEZE
34 #error nope
35 #endif
36EOF
Rob Landley5fe77cf2014-04-23 08:38:29 -050037
Rob Landley434cefb2014-06-28 20:16:11 -050038 # Work around some uClibc limitations
Rob Landley5fe77cf2014-04-23 08:38:29 -050039 probesymbol TOYBOX_ICONV -c << EOF
40 #include "iconv.h"
41EOF
Rob Landley434cefb2014-06-28 20:16:11 -050042 probesymbol TOYBOX_FALLOCATE << EOF
43 #include <fcntl.h>
44
45 int main(int argc, char *argv[]) { return posix_fallocate(0,0,0); }
46EOF
Isaac Dunham46ddf0e2014-11-19 16:38:46 -060047
48 # Android and some other platforms miss utmpx
49 probesymbol TOYBOX_UTMPX -c << EOF
50 #include <utmpx.h>
51 #ifndef BOOT_TIME
52 #error nope
53 #endif
54 int main(int argc, char *argv[]) {
55 struct utmpx *a;
56 if (0 != (a = getutxent())) return 0;
57 return 1;
58 }
59EOF
60
61 # Android is missing shadow.h and pty.h
62 probesymbol TOYBOX_PTY -c << EOF
63 #include <pty.h>
64 int main(int argc, char *argv[]) {
65 int master; return forkpty(&master, NULL, NULL, NULL);
66 }
67EOF
68
69 probesymbol TOYBOX_SHADOW -c << EOF
70 #include <shadow.h>
71 int main(int argc, char *argv[]) {
72 struct spwd *a = getspnam("root"); return 0;
73 }
74EOF
Rob Landley1b7ad012012-02-23 21:03:18 -060075}
Rob Landleyf9fdd3c2012-03-19 20:15:08 -050076
Rob Landley1b7ad012012-02-23 21:03:18 -060077genconfig()
78{
Rob Landleyf9070f32014-04-23 17:23:09 -050079 # Reverse sort puts posix first, examples last.
80 for j in $(ls toys/*/README | sort -r)
Rob Landley28964802008-01-19 17:08:39 -060081 do
Rob Landleyb1c002a2012-12-10 21:08:42 -060082 DIR="$(dirname "$j")"
83
84 [ $(ls "$DIR" | wc -l) -lt 2 ] && continue
85
Rob Landleyaa777fe2012-12-08 21:10:10 -060086 echo "menu \"$(head -n 1 $j)\""
Rob Landley28964802008-01-19 17:08:39 -060087 echo
Rob Landley3a9241a2012-08-25 14:25:22 -050088
Rob Landley3a9241a2012-08-25 14:25:22 -050089 # extract config stanzas from each source file, in alphabetical order
Rob Landleyaa777fe2012-12-08 21:10:10 -060090 for i in $(ls -1 $DIR/*.c)
Rob Landley3a9241a2012-08-25 14:25:22 -050091 do
92 # Grab the config block for Config.in
93 echo "# $i"
94 sed -n '/^\*\//q;/^config [A-Z]/,$p' $i || return 1
95 echo
96 done
97
98 echo endmenu
Rob Landley28964802008-01-19 17:08:39 -060099 done
100}
101
Rob Landley1b7ad012012-02-23 21:03:18 -0600102probeconfig > generated/Config.probed || rm generated/Config.probed
103genconfig > generated/Config.in || rm generated/Config.in