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 | |
Rob Landley | c99cbd1 | 2016-09-28 14:22:34 -0500 | [diff] [blame] | 39 | int main(int argc, char *argv[]) { setns(0,0); 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 | 9933273 | 2015-07-03 15:17:25 -0500 | [diff] [blame] | 86 | |
Rob Landley | be3e318 | 2017-04-30 02:46:36 -0500 | [diff] [blame] | 87 | probesymbol TOYBOX_ANDROID_SCHEDPOLICY << EOF |
| 88 | #include <cutils/sched_policy.h> |
| 89 | |
| 90 | int main(int argc,char *argv[]) { get_sched_policy_name(0); } |
| 91 | EOF |
| 92 | |
Rob Landley | 9933273 | 2015-07-03 15:17:25 -0500 | [diff] [blame] | 93 | # nommu support |
| 94 | probesymbol TOYBOX_FORK << EOF |
| 95 | #include <unistd.h> |
| 96 | int main(int argc, char *argv[]) { return fork(); } |
| 97 | EOF |
Rob Landley | 8c588d8 | 2015-08-29 22:12:56 -0500 | [diff] [blame] | 98 | echo -e '\tdepends on !TOYBOX_MUSL_NOMMU_IS_BROKEN' |
Rob Landley | 323819c | 2016-03-01 23:50:23 -0600 | [diff] [blame] | 99 | |
| 100 | probesymbol TOYBOX_PRLIMIT << EOF |
| 101 | #include <sys/time.h> |
| 102 | #include <sys/resource.h> |
| 103 | |
| 104 | int main(int argc, char *argv[]) { prlimit(0, 0, 0, 0); } |
| 105 | EOF |
Rob Landley | 1b7ad01 | 2012-02-23 21:03:18 -0600 | [diff] [blame] | 106 | } |
Rob Landley | f9fdd3c | 2012-03-19 20:15:08 -0500 | [diff] [blame] | 107 | |
Rob Landley | 1b7ad01 | 2012-02-23 21:03:18 -0600 | [diff] [blame] | 108 | genconfig() |
| 109 | { |
Rob Landley | f9070f3 | 2014-04-23 17:23:09 -0500 | [diff] [blame] | 110 | # Reverse sort puts posix first, examples last. |
Elliott Hughes | 0ca829c | 2016-05-25 14:43:56 -0700 | [diff] [blame] | 111 | for j in $(ls toys/*/README | sort -s -r) |
Rob Landley | 2896480 | 2008-01-19 17:08:39 -0600 | [diff] [blame] | 112 | do |
Rob Landley | b1c002a | 2012-12-10 21:08:42 -0600 | [diff] [blame] | 113 | DIR="$(dirname "$j")" |
| 114 | |
| 115 | [ $(ls "$DIR" | wc -l) -lt 2 ] && continue |
| 116 | |
Rob Landley | aa777fe | 2012-12-08 21:10:10 -0600 | [diff] [blame] | 117 | echo "menu \"$(head -n 1 $j)\"" |
Rob Landley | 2896480 | 2008-01-19 17:08:39 -0600 | [diff] [blame] | 118 | echo |
Rob Landley | 3a9241a | 2012-08-25 14:25:22 -0500 | [diff] [blame] | 119 | |
Rob Landley | 3a9241a | 2012-08-25 14:25:22 -0500 | [diff] [blame] | 120 | # extract config stanzas from each source file, in alphabetical order |
Rob Landley | aa777fe | 2012-12-08 21:10:10 -0600 | [diff] [blame] | 121 | for i in $(ls -1 $DIR/*.c) |
Rob Landley | 3a9241a | 2012-08-25 14:25:22 -0500 | [diff] [blame] | 122 | do |
| 123 | # Grab the config block for Config.in |
| 124 | echo "# $i" |
| 125 | sed -n '/^\*\//q;/^config [A-Z]/,$p' $i || return 1 |
| 126 | echo |
| 127 | done |
| 128 | |
| 129 | echo endmenu |
Rob Landley | 2896480 | 2008-01-19 17:08:39 -0600 | [diff] [blame] | 130 | done |
| 131 | } |
| 132 | |
Rob Landley | 1b7ad01 | 2012-02-23 21:03:18 -0600 | [diff] [blame] | 133 | probeconfig > generated/Config.probed || rm generated/Config.probed |
| 134 | genconfig > generated/Config.in || rm generated/Config.in |
Rob Landley | 712e43e | 2016-02-07 18:15:53 -0600 | [diff] [blame] | 135 | |
| 136 | # Find names of commands that can be built standalone in these C files |
| 137 | toys() |
| 138 | { |
Rob Landley | 05b7529 | 2016-02-14 14:04:21 -0600 | [diff] [blame] | 139 | grep 'TOY(.*)' "$@" | grep -v TOYFLAG_NOFORK | grep -v "0))" | \ |
Rob Landley | 712e43e | 2016-02-07 18:15:53 -0600 | [diff] [blame] | 140 | sed -rn 's/([^:]*):.*(OLD|NEW)TOY\( *([a-zA-Z][^,]*) *,.*/\1:\3/p' |
| 141 | } |
| 142 | |
| 143 | WORKING= |
| 144 | PENDING= |
| 145 | toys toys/*/*.c | ( |
| 146 | while IFS=":" read FILE NAME |
| 147 | do |
| 148 | [ "$NAME" == help ] && continue |
| 149 | [ "$NAME" == install ] && continue |
Rob Landley | 9b14cb6a | 2016-02-07 19:09:39 -0600 | [diff] [blame] | 150 | echo -e "$NAME: $FILE *.[ch] lib/*.[ch]\n\tscripts/single.sh $NAME\n" |
Rob Landley | 5ec9f52 | 2016-02-19 17:56:01 -0600 | [diff] [blame] | 151 | echo -e "test_$NAME:\n\tscripts/test.sh $NAME\n" |
Rob Landley | 712e43e | 2016-02-07 18:15:53 -0600 | [diff] [blame] | 152 | [ "${FILE/pending//}" != "$FILE" ] && |
| 153 | PENDING="$PENDING $NAME" || |
| 154 | WORKING="$WORKING $NAME" |
Rob Landley | a8d0d13 | 2016-03-23 03:25:37 -0500 | [diff] [blame] | 155 | done && |
| 156 | echo -e "clean::\n\trm -f $WORKING $PENDING" && |
Rob Landley | a599514 | 2016-04-20 00:47:05 -0500 | [diff] [blame] | 157 | echo -e "list:\n\t@echo $(echo $WORKING | tr ' ' '\n' | sort | xargs)" && |
Rob Landley | a8d0d13 | 2016-03-23 03:25:37 -0500 | [diff] [blame] | 158 | echo -e "list_pending:\n\t@echo $(echo $PENDING | tr ' ' '\n' | sort | xargs)" && |
| 159 | echo -e ".PHONY: $WORKING $PENDING" | sed 's/ \([^ ]\)/ test_\1/g' |
| 160 | ) > .singlemake |