blob: b50c32bb9fa92f9c9acf22d884d600c39aa450f7 [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
Rob Landley434cefb2014-06-28 20:16:11 -050038 # Work around some uClibc limitations
Rob Landley5fe77cf2014-04-23 08:38:29 -050039 probesymbol TOYBOX_ICONV -c << EOF
40 #include "iconv.h"
41EOF
Rob Landley434cefb2014-06-28 20:16:11 -050042 probesymbol TOYBOX_FALLOCATE << EOF
43 #include <fcntl.h>
44
45 int main(int argc, char *argv[]) { return posix_fallocate(0,0,0); }
46EOF
Rob Landley1b7ad012012-02-23 21:03:18 -060047}
Rob Landleyf9fdd3c2012-03-19 20:15:08 -050048
Rob Landley1b7ad012012-02-23 21:03:18 -060049genconfig()
50{
Rob Landleyf9070f32014-04-23 17:23:09 -050051 # Reverse sort puts posix first, examples last.
52 for j in $(ls toys/*/README | sort -r)
Rob Landley28964802008-01-19 17:08:39 -060053 do
Rob Landleyb1c002a2012-12-10 21:08:42 -060054 DIR="$(dirname "$j")"
55
56 [ $(ls "$DIR" | wc -l) -lt 2 ] && continue
57
Rob Landleyaa777fe2012-12-08 21:10:10 -060058 echo "menu \"$(head -n 1 $j)\""
Rob Landley28964802008-01-19 17:08:39 -060059 echo
Rob Landley3a9241a2012-08-25 14:25:22 -050060
Rob Landley3a9241a2012-08-25 14:25:22 -050061 # extract config stanzas from each source file, in alphabetical order
Rob Landleyaa777fe2012-12-08 21:10:10 -060062 for i in $(ls -1 $DIR/*.c)
Rob Landley3a9241a2012-08-25 14:25:22 -050063 do
64 # Grab the config block for Config.in
65 echo "# $i"
66 sed -n '/^\*\//q;/^config [A-Z]/,$p' $i || return 1
67 echo
68 done
69
70 echo endmenu
Rob Landley28964802008-01-19 17:08:39 -060071 done
72}
73
Rob Landley1b7ad012012-02-23 21:03:18 -060074probeconfig > generated/Config.probed || rm generated/Config.probed
75genconfig > generated/Config.in || rm generated/Config.in