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 | a913d92 | 2015-05-09 17:07:22 -0500 | [diff] [blame] | 10 | probecc() |
| 11 | { |
| 12 | ${CROSS_COMPILE}${CC} $CFLAGS -xc -o /dev/null $1 - |
| 13 | } |
| 14 | |
Rob Landley | 76e1cb3 | 2014-04-16 07:49:32 -0500 | [diff] [blame] | 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 | { |
Rob Landley | a913d92 | 2015-05-09 17:07:22 -0500 | [diff] [blame] | 19 | probecc $2 2>/dev/null && DEFAULT=y || DEFAULT=n |
Rob Landley | 76e1cb3 | 2014-04-16 07:49:32 -0500 | [diff] [blame] | 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 | |
Rob Landley | 1b7ad01 | 2012-02-23 21:03:18 -0600 | [diff] [blame] | 25 | probeconfig() |
Rob Landley | 2896480 | 2008-01-19 17:08:39 -0600 | [diff] [blame] | 26 | { |
Rob Landley | a913d92 | 2015-05-09 17:07:22 -0500 | [diff] [blame] | 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 | |
Rob Landley | 27f5779 | 2012-02-03 23:16:28 -0600 | [diff] [blame] | 34 | # Probe for container support on target |
Rob Landley | 76e1cb3 | 2014-04-16 07:49:32 -0500 | [diff] [blame] | 35 | probesymbol TOYBOX_CONTAINER << EOF |
Georgi Chorbadzhiyski | 2c27fcf | 2012-03-04 01:24:06 -0600 | [diff] [blame] | 36 | #include <linux/sched.h> |
Rob Landley | 27f5779 | 2012-02-03 23:16:28 -0600 | [diff] [blame] | 37 | int x=CLONE_NEWNS|CLONE_NEWUTS|CLONE_NEWIPC|CLONE_NEWNET; |
Rob Landley | f9fdd3c | 2012-03-19 20:15:08 -0500 | [diff] [blame] | 38 | |
| 39 | int main(int argc, char *argv[]) { return unshare(x); } |
Rob Landley | 27f5779 | 2012-02-03 23:16:28 -0600 | [diff] [blame] | 40 | EOF |
Rob Landley | 76e1cb3 | 2014-04-16 07:49:32 -0500 | [diff] [blame] | 41 | |
| 42 | probesymbol TOYBOX_FIFREEZE -c << EOF |
| 43 | #include <linux/fs.h> |
| 44 | #ifndef FIFREEZE |
| 45 | #error nope |
| 46 | #endif |
| 47 | EOF |
Rob Landley | 5fe77cf | 2014-04-23 08:38:29 -0500 | [diff] [blame] | 48 | |
Rob Landley | 434cefb | 2014-06-28 20:16:11 -0500 | [diff] [blame] | 49 | # Work around some uClibc limitations |
Rob Landley | 5fe77cf | 2014-04-23 08:38:29 -0500 | [diff] [blame] | 50 | probesymbol TOYBOX_ICONV -c << EOF |
| 51 | #include "iconv.h" |
| 52 | EOF |
Rob Landley | 434cefb | 2014-06-28 20:16:11 -0500 | [diff] [blame] | 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 |
Isaac Dunham | 46ddf0e | 2014-11-19 16:38:46 -0600 | [diff] [blame] | 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 | |
Elliott Hughes | c2415d1 | 2015-01-16 13:49:23 -0600 | [diff] [blame] | 72 | # Android is missing shadow.h |
Isaac Dunham | 46ddf0e | 2014-11-19 16:38:46 -0600 | [diff] [blame] | 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 |
Rob Landley | 5b493dc | 2015-04-19 21:50:51 -0500 | [diff] [blame] | 79 | |
| 80 | # Some commands are android-specific |
| 81 | probesymbol TOYBOX_ON_ANDROID -c << EOF |
| 82 | #ifndef __ANDROID__ |
| 83 | #error nope |
| 84 | #endif |
| 85 | EOF |
Rob Landley | 1b7ad01 | 2012-02-23 21:03:18 -0600 | [diff] [blame] | 86 | } |
Rob Landley | f9fdd3c | 2012-03-19 20:15:08 -0500 | [diff] [blame] | 87 | |
Rob Landley | 1b7ad01 | 2012-02-23 21:03:18 -0600 | [diff] [blame] | 88 | genconfig() |
| 89 | { |
Rob Landley | f9070f3 | 2014-04-23 17:23:09 -0500 | [diff] [blame] | 90 | # Reverse sort puts posix first, examples last. |
| 91 | for j in $(ls toys/*/README | sort -r) |
Rob Landley | 2896480 | 2008-01-19 17:08:39 -0600 | [diff] [blame] | 92 | do |
Rob Landley | b1c002a | 2012-12-10 21:08:42 -0600 | [diff] [blame] | 93 | DIR="$(dirname "$j")" |
| 94 | |
| 95 | [ $(ls "$DIR" | wc -l) -lt 2 ] && continue |
| 96 | |
Rob Landley | aa777fe | 2012-12-08 21:10:10 -0600 | [diff] [blame] | 97 | echo "menu \"$(head -n 1 $j)\"" |
Rob Landley | 2896480 | 2008-01-19 17:08:39 -0600 | [diff] [blame] | 98 | echo |
Rob Landley | 3a9241a | 2012-08-25 14:25:22 -0500 | [diff] [blame] | 99 | |
Rob Landley | 3a9241a | 2012-08-25 14:25:22 -0500 | [diff] [blame] | 100 | # extract config stanzas from each source file, in alphabetical order |
Rob Landley | aa777fe | 2012-12-08 21:10:10 -0600 | [diff] [blame] | 101 | for i in $(ls -1 $DIR/*.c) |
Rob Landley | 3a9241a | 2012-08-25 14:25:22 -0500 | [diff] [blame] | 102 | do |
| 103 | # Grab the config block for Config.in |
| 104 | echo "# $i" |
| 105 | sed -n '/^\*\//q;/^config [A-Z]/,$p' $i || return 1 |
| 106 | echo |
| 107 | done |
| 108 | |
| 109 | echo endmenu |
Rob Landley | 2896480 | 2008-01-19 17:08:39 -0600 | [diff] [blame] | 110 | done |
| 111 | } |
| 112 | |
Rob Landley | 1b7ad01 | 2012-02-23 21:03:18 -0600 | [diff] [blame] | 113 | probeconfig > generated/Config.probed || rm generated/Config.probed |
| 114 | genconfig > generated/Config.in || rm generated/Config.in |