Rob Landley | 2896480 | 2008-01-19 17:08:39 -0600 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Rob Landley | 7c04f01 | 2008-01-20 19:00:16 -0600 | [diff] [blame] | 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 | |
Rob Landley | 2896480 | 2008-01-19 17:08:39 -0600 | [diff] [blame] | 6 | mkdir -p generated |
| 7 | |
Rob Landley | 2bd3a5d | 2012-02-13 08:44:32 -0600 | [diff] [blame] | 8 | source configure |
| 9 | |
Rob Landley | 76e1cb3 | 2014-04-16 07:49:32 -0500 | [diff] [blame] | 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 |
| 12 | probesymbol() |
| 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 Landley | 1b7ad01 | 2012-02-23 21:03:18 -0600 | [diff] [blame] | 21 | probeconfig() |
Rob Landley | 2896480 | 2008-01-19 17:08:39 -0600 | [diff] [blame] | 22 | { |
Rob Landley | 27f5779 | 2012-02-03 23:16:28 -0600 | [diff] [blame] | 23 | # Probe for container support on target |
Rob Landley | 76e1cb3 | 2014-04-16 07:49:32 -0500 | [diff] [blame] | 24 | probesymbol TOYBOX_CONTAINER << EOF |
Georgi Chorbadzhiyski | 2c27fcf | 2012-03-04 01:24:06 -0600 | [diff] [blame] | 25 | #include <linux/sched.h> |
Rob Landley | 27f5779 | 2012-02-03 23:16:28 -0600 | [diff] [blame] | 26 | int x=CLONE_NEWNS|CLONE_NEWUTS|CLONE_NEWIPC|CLONE_NEWNET; |
Rob Landley | f9fdd3c | 2012-03-19 20:15:08 -0500 | [diff] [blame] | 27 | |
| 28 | int main(int argc, char *argv[]) { return unshare(x); } |
Rob Landley | 27f5779 | 2012-02-03 23:16:28 -0600 | [diff] [blame] | 29 | EOF |
Rob Landley | 76e1cb3 | 2014-04-16 07:49:32 -0500 | [diff] [blame] | 30 | |
| 31 | probesymbol TOYBOX_FIFREEZE -c << EOF |
| 32 | #include <linux/fs.h> |
| 33 | #ifndef FIFREEZE |
| 34 | #error nope |
| 35 | #endif |
| 36 | EOF |
Rob Landley | 5fe77cf | 2014-04-23 08:38:29 -0500 | [diff] [blame] | 37 | |
Rob Landley | 434cefb | 2014-06-28 20:16:11 -0500 | [diff] [blame] | 38 | # Work around some uClibc limitations |
Rob Landley | 5fe77cf | 2014-04-23 08:38:29 -0500 | [diff] [blame] | 39 | probesymbol TOYBOX_ICONV -c << EOF |
| 40 | #include "iconv.h" |
| 41 | EOF |
Rob Landley | 434cefb | 2014-06-28 20:16:11 -0500 | [diff] [blame] | 42 | probesymbol TOYBOX_FALLOCATE << EOF |
| 43 | #include <fcntl.h> |
| 44 | |
| 45 | int main(int argc, char *argv[]) { return posix_fallocate(0,0,0); } |
| 46 | EOF |
Isaac Dunham | 46ddf0e | 2014-11-19 16:38:46 -0600 | [diff] [blame^] | 47 | |
| 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 | } |
| 59 | EOF |
| 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 | } |
| 67 | EOF |
| 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 | } |
| 74 | EOF |
Rob Landley | 1b7ad01 | 2012-02-23 21:03:18 -0600 | [diff] [blame] | 75 | } |
Rob Landley | f9fdd3c | 2012-03-19 20:15:08 -0500 | [diff] [blame] | 76 | |
Rob Landley | 1b7ad01 | 2012-02-23 21:03:18 -0600 | [diff] [blame] | 77 | genconfig() |
| 78 | { |
Rob Landley | f9070f3 | 2014-04-23 17:23:09 -0500 | [diff] [blame] | 79 | # Reverse sort puts posix first, examples last. |
| 80 | for j in $(ls toys/*/README | sort -r) |
Rob Landley | 2896480 | 2008-01-19 17:08:39 -0600 | [diff] [blame] | 81 | do |
Rob Landley | b1c002a | 2012-12-10 21:08:42 -0600 | [diff] [blame] | 82 | DIR="$(dirname "$j")" |
| 83 | |
| 84 | [ $(ls "$DIR" | wc -l) -lt 2 ] && continue |
| 85 | |
Rob Landley | aa777fe | 2012-12-08 21:10:10 -0600 | [diff] [blame] | 86 | echo "menu \"$(head -n 1 $j)\"" |
Rob Landley | 2896480 | 2008-01-19 17:08:39 -0600 | [diff] [blame] | 87 | echo |
Rob Landley | 3a9241a | 2012-08-25 14:25:22 -0500 | [diff] [blame] | 88 | |
Rob Landley | 3a9241a | 2012-08-25 14:25:22 -0500 | [diff] [blame] | 89 | # extract config stanzas from each source file, in alphabetical order |
Rob Landley | aa777fe | 2012-12-08 21:10:10 -0600 | [diff] [blame] | 90 | for i in $(ls -1 $DIR/*.c) |
Rob Landley | 3a9241a | 2012-08-25 14:25:22 -0500 | [diff] [blame] | 91 | 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 Landley | 2896480 | 2008-01-19 17:08:39 -0600 | [diff] [blame] | 99 | done |
| 100 | } |
| 101 | |
Rob Landley | 1b7ad01 | 2012-02-23 21:03:18 -0600 | [diff] [blame] | 102 | probeconfig > generated/Config.probed || rm generated/Config.probed |
| 103 | genconfig > generated/Config.in || rm generated/Config.in |