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 6source scripts/portability.sh 7 8mkdir -p "$GENDIR" 9 10probecc() 11{ 12 ${CROSS_COMPILE}${CC} $CFLAGS $LDFLAGS -xc -o /dev/null - "$@" 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 17probesymbol() 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\n\tdefault $DEFAULT\n" || exit 1 22} 23 24probeconfig() 25{ 26 # Some commands are android-specific 27 probesymbol TOYBOX_ON_ANDROID -c << EOF 28 #ifndef __ANDROID__ 29 #error nope 30 #endif 31EOF 32 33 # nommu support 34 probesymbol TOYBOX_FORK << EOF 35 #include <unistd.h> 36 int main(int argc, char *argv[]) { return fork(); } 37EOF 38 echo -e '\tdepends on !TOYBOX_FORCE_NOMMU' 39} 40 41genconfig() 42{ 43 # Reverse sort puts posix first, examples last. 44 for j in $(ls toys/*/README | sort -s -r) 45 do 46 DIR="$(dirname "$j")" 47 48 [ $(ls "$DIR" | wc -l) -lt 2 ] && continue 49 50 echo "menu \"$(head -n 1 $j)\"" 51 echo 52 53 # extract config stanzas from each source file, in alphabetical order 54 for i in $(ls -1 $DIR/*.c) 55 do 56 # Grab the config block for Config.in 57 echo "# $i" 58 $SED -n '/^\*\//q;/^config [A-Z]/,$p' $i || return 1 59 echo 60 done 61 62 echo endmenu 63 done 64} 65 66probeconfig > "$GENDIR"/Config.probed || rm "$GENDIR"/Config.probed 67genconfig > "$GENDIR"/Config.in || rm "$GENDIR"/Config.in 68 69# Find names of commands that can be built standalone in these C files 70toys() 71{ 72 grep 'TOY(.*)' "$@" | grep -v TOYFLAG_NOFORK | grep -v "0))" | \ 73 $SED -En 's/([^:]*):.*(OLD|NEW)TOY\( *([a-zA-Z][^,]*) *,.*/\1:\3/p' 74} 75 76WORKING= PENDING= EXAMPLE= 77toys toys/*/*.c | ( 78while IFS=":" read FILE NAME 79do 80 [ "$NAME" == help ] && continue 81 [ "$NAME" == install ] && continue 82 [ "$NAME" == sh ] && FILE="toys/*/*.c" 83 echo -e "$NAME: $FILE *.[ch] lib/*.[ch]\n\tscripts/single.sh $NAME\n" 84 echo -e "test_$NAME:\n\tscripts/test.sh $NAME\n" 85 [ "${FILE/example//}" != "$FILE" ] && EXAMPLE="$EXAMPLE $NAME" || 86 [ "${FILE/pending//}" != "$FILE" ] && PENDING="$PENDING $NAME" || 87 WORKING="$WORKING $NAME" 88done && 89echo -e "clean::\n\t@rm -f $WORKING $PENDING" && 90echo -e "list:\n\t@echo $(echo $WORKING | tr ' ' '\n' | sort | xargs)" && 91echo -e "list_example:\n\t@echo $(echo $EXAMPLE | tr ' ' '\n' | sort | xargs)"&& 92echo -e "list_pending:\n\t@echo $(echo $PENDING | tr ' ' '\n' | sort | xargs)"&& 93echo -e ".PHONY: $WORKING $PENDING" | $SED 's/ \([^ ]\)/ test_\1/g' 94) > .singlemake 95