blob: 4425328d5f59032306ebf31804683ede0914fc7b [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 Landley5fe77cf2014-04-23 08:38:29 -050037
38 # Hard to come by in uClibc.
39 probesymbol TOYBOX_ICONV -c << EOF
40 #include "iconv.h"
41EOF
Rob Landley1b7ad012012-02-23 21:03:18 -060042}
Rob Landleyf9fdd3c2012-03-19 20:15:08 -050043
Rob Landley1b7ad012012-02-23 21:03:18 -060044genconfig()
45{
Rob Landley3a9241a2012-08-25 14:25:22 -050046 # I could query the directory here, but I want to control the order
47 # and capitalization in the menu
Rob Landleyaa777fe2012-12-08 21:10:10 -060048 for j in toys/*/README
Rob Landley28964802008-01-19 17:08:39 -060049 do
Rob Landleyb1c002a2012-12-10 21:08:42 -060050 DIR="$(dirname "$j")"
51
52 [ $(ls "$DIR" | wc -l) -lt 2 ] && continue
53
Rob Landleyaa777fe2012-12-08 21:10:10 -060054 echo "menu \"$(head -n 1 $j)\""
Rob Landley28964802008-01-19 17:08:39 -060055 echo
Rob Landley3a9241a2012-08-25 14:25:22 -050056
Rob Landley3a9241a2012-08-25 14:25:22 -050057 # extract config stanzas from each source file, in alphabetical order
Rob Landleyaa777fe2012-12-08 21:10:10 -060058 for i in $(ls -1 $DIR/*.c)
Rob Landley3a9241a2012-08-25 14:25:22 -050059 do
60 # Grab the config block for Config.in
61 echo "# $i"
62 sed -n '/^\*\//q;/^config [A-Z]/,$p' $i || return 1
63 echo
64 done
65
66 echo endmenu
Rob Landley28964802008-01-19 17:08:39 -060067 done
68}
69
Rob Landley1b7ad012012-02-23 21:03:18 -060070probeconfig > generated/Config.probed || rm generated/Config.probed
71genconfig > generated/Config.in || rm generated/Config.in