blob: 41f1a17390334b1ff668961bb835a591eec463b5 [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 Landley1b7ad012012-02-23 21:03:18 -060037}
Rob Landleyf9fdd3c2012-03-19 20:15:08 -050038
Rob Landley1b7ad012012-02-23 21:03:18 -060039genconfig()
40{
Rob Landley3a9241a2012-08-25 14:25:22 -050041 # I could query the directory here, but I want to control the order
42 # and capitalization in the menu
Rob Landleyaa777fe2012-12-08 21:10:10 -060043 for j in toys/*/README
Rob Landley28964802008-01-19 17:08:39 -060044 do
Rob Landleyb1c002a2012-12-10 21:08:42 -060045 DIR="$(dirname "$j")"
46
47 [ $(ls "$DIR" | wc -l) -lt 2 ] && continue
48
Rob Landleyaa777fe2012-12-08 21:10:10 -060049 echo "menu \"$(head -n 1 $j)\""
Rob Landley28964802008-01-19 17:08:39 -060050 echo
Rob Landley3a9241a2012-08-25 14:25:22 -050051
Rob Landley3a9241a2012-08-25 14:25:22 -050052 # extract config stanzas from each source file, in alphabetical order
Rob Landleyaa777fe2012-12-08 21:10:10 -060053 for i in $(ls -1 $DIR/*.c)
Rob Landley3a9241a2012-08-25 14:25:22 -050054 do
55 # Grab the config block for Config.in
56 echo "# $i"
57 sed -n '/^\*\//q;/^config [A-Z]/,$p' $i || return 1
58 echo
59 done
60
61 echo endmenu
Rob Landley28964802008-01-19 17:08:39 -060062 done
63}
64
Rob Landley1b7ad012012-02-23 21:03:18 -060065probeconfig > generated/Config.probed || rm generated/Config.probed
66genconfig > generated/Config.in || rm generated/Config.in