2008-01-19 15:08:39 -08:00
|
|
|
#!/bin/bash
|
|
|
|
|
2008-01-20 17:00:16 -08:00
|
|
|
# This has to be a separate file from scripts/make.sh so it can be called
|
|
|
|
# before menuconfig. (It's called again from scripts/make.sh just to be sure.)
|
|
|
|
|
2008-01-19 15:08:39 -08:00
|
|
|
mkdir -p generated
|
|
|
|
|
2019-01-19 14:58:04 -08:00
|
|
|
source scripts/portability.sh
|
2012-02-13 06:44:32 -08:00
|
|
|
|
2015-05-09 15:07:22 -07:00
|
|
|
probecc()
|
|
|
|
{
|
|
|
|
${CROSS_COMPILE}${CC} $CFLAGS -xc -o /dev/null $1 -
|
|
|
|
}
|
|
|
|
|
2014-04-16 05:49:32 -07:00
|
|
|
# Probe for a single config symbol with a "compiles or not" test.
|
|
|
|
# Symbol name is first argument, flags second, feed C file to stdin
|
|
|
|
probesymbol()
|
|
|
|
{
|
2015-05-09 15:07:22 -07:00
|
|
|
probecc $2 2>/dev/null && DEFAULT=y || DEFAULT=n
|
2014-04-16 05:49:32 -07:00
|
|
|
rm a.out 2>/dev/null
|
|
|
|
echo -e "config $1\n\tbool" || exit 1
|
|
|
|
echo -e "\tdefault $DEFAULT\n" || exit 1
|
|
|
|
}
|
|
|
|
|
2012-02-23 19:03:18 -08:00
|
|
|
probeconfig()
|
2008-01-19 15:08:39 -08:00
|
|
|
{
|
2015-05-09 15:07:22 -07:00
|
|
|
> generated/cflags
|
|
|
|
# llvm produces its own really stupid warnings about things that aren't wrong,
|
|
|
|
# and although you can turn the warning off, gcc reacts badly to command line
|
|
|
|
# arguments it doesn't understand. So probe.
|
|
|
|
[ -z "$(probecc -Wno-string-plus-int <<< \#warn warn 2>&1 | grep string-plus-int)" ] &&
|
|
|
|
echo -Wno-string-plus-int >> generated/cflags
|
|
|
|
|
2012-02-03 21:16:28 -08:00
|
|
|
# Probe for container support on target
|
2014-04-16 05:49:32 -07:00
|
|
|
probesymbol TOYBOX_CONTAINER << EOF
|
2019-08-21 14:51:08 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/syscall.h>
|
2012-03-03 23:24:06 -08:00
|
|
|
#include <linux/sched.h>
|
2012-02-03 21:16:28 -08:00
|
|
|
int x=CLONE_NEWNS|CLONE_NEWUTS|CLONE_NEWIPC|CLONE_NEWNET;
|
2012-03-19 18:15:08 -07:00
|
|
|
|
2019-08-21 14:51:08 -07:00
|
|
|
int main(int argc, char *argv[]){printf("%d", x+SYS_unshare+ SYS_setns);}
|
2012-02-03 21:16:28 -08:00
|
|
|
EOF
|
2014-04-16 05:49:32 -07:00
|
|
|
|
|
|
|
probesymbol TOYBOX_FIFREEZE -c << EOF
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#ifndef FIFREEZE
|
|
|
|
#error nope
|
|
|
|
#endif
|
|
|
|
EOF
|
2014-04-23 06:38:29 -07:00
|
|
|
|
2014-06-28 18:16:11 -07:00
|
|
|
# Work around some uClibc limitations
|
2014-04-23 06:38:29 -07:00
|
|
|
probesymbol TOYBOX_ICONV -c << EOF
|
|
|
|
#include "iconv.h"
|
2014-06-28 18:16:11 -07:00
|
|
|
EOF
|
2014-11-19 14:38:46 -08:00
|
|
|
|
|
|
|
# Android and some other platforms miss utmpx
|
|
|
|
probesymbol TOYBOX_UTMPX -c << EOF
|
|
|
|
#include <utmpx.h>
|
|
|
|
#ifndef BOOT_TIME
|
|
|
|
#error nope
|
|
|
|
#endif
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
struct utmpx *a;
|
|
|
|
if (0 != (a = getutxent())) return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
2015-01-16 11:49:23 -08:00
|
|
|
# Android is missing shadow.h
|
2014-11-19 14:38:46 -08:00
|
|
|
probesymbol TOYBOX_SHADOW -c << EOF
|
|
|
|
#include <shadow.h>
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
struct spwd *a = getspnam("root"); return 0;
|
|
|
|
}
|
|
|
|
EOF
|
2015-04-19 19:50:51 -07:00
|
|
|
|
|
|
|
# Some commands are android-specific
|
|
|
|
probesymbol TOYBOX_ON_ANDROID -c << EOF
|
|
|
|
#ifndef __ANDROID__
|
|
|
|
#error nope
|
|
|
|
#endif
|
|
|
|
EOF
|
2015-07-03 13:17:25 -07:00
|
|
|
|
2017-04-30 00:46:36 -07:00
|
|
|
probesymbol TOYBOX_ANDROID_SCHEDPOLICY << EOF
|
2019-05-01 15:28:21 -07:00
|
|
|
#include <processgroup/sched_policy.h>
|
2017-04-30 00:46:36 -07:00
|
|
|
|
|
|
|
int main(int argc,char *argv[]) { get_sched_policy_name(0); }
|
|
|
|
EOF
|
|
|
|
|
2015-07-03 13:17:25 -07:00
|
|
|
# nommu support
|
|
|
|
probesymbol TOYBOX_FORK << EOF
|
|
|
|
#include <unistd.h>
|
|
|
|
int main(int argc, char *argv[]) { return fork(); }
|
|
|
|
EOF
|
2020-02-17 02:11:07 -08:00
|
|
|
echo -e '\tdepends on !TOYBOX_FORCE_NOMMU'
|
2016-03-01 21:50:23 -08:00
|
|
|
|
|
|
|
probesymbol TOYBOX_PRLIMIT << EOF
|
2018-06-26 21:04:11 -07:00
|
|
|
#include <sys/types.h>
|
2016-03-01 21:50:23 -08:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/resource.h>
|
2018-06-26 21:04:11 -07:00
|
|
|
int prlimit(pid_t pid, int resource, const struct rlimit *new_limit,
|
|
|
|
struct rlimit *old_limit);
|
2016-03-01 21:50:23 -08:00
|
|
|
int main(int argc, char *argv[]) { prlimit(0, 0, 0, 0); }
|
|
|
|
EOF
|
2018-07-04 16:49:03 -07:00
|
|
|
|
|
|
|
probesymbol TOYBOX_GETRANDOM << EOF
|
|
|
|
#include <sys/random.h>
|
|
|
|
int main(void) { char buf[100]; getrandom(buf, 100, 0); }
|
|
|
|
EOF
|
2020-06-01 01:31:14 -07:00
|
|
|
|
|
|
|
probesymbol TOYBOX_COPYFILERANGE << EOF
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
int main(void) { copyfilerange(0, 0, 1, 0, 123, 0); }
|
|
|
|
EOF
|
2012-02-23 19:03:18 -08:00
|
|
|
}
|
2012-03-19 18:15:08 -07:00
|
|
|
|
2012-02-23 19:03:18 -08:00
|
|
|
genconfig()
|
|
|
|
{
|
2014-04-23 15:23:09 -07:00
|
|
|
# Reverse sort puts posix first, examples last.
|
2016-05-25 14:43:56 -07:00
|
|
|
for j in $(ls toys/*/README | sort -s -r)
|
2008-01-19 15:08:39 -08:00
|
|
|
do
|
2012-12-10 19:08:42 -08:00
|
|
|
DIR="$(dirname "$j")"
|
|
|
|
|
|
|
|
[ $(ls "$DIR" | wc -l) -lt 2 ] && continue
|
|
|
|
|
2012-12-08 19:10:10 -08:00
|
|
|
echo "menu \"$(head -n 1 $j)\""
|
2008-01-19 15:08:39 -08:00
|
|
|
echo
|
2012-08-25 12:25:22 -07:00
|
|
|
|
|
|
|
# extract config stanzas from each source file, in alphabetical order
|
2012-12-08 19:10:10 -08:00
|
|
|
for i in $(ls -1 $DIR/*.c)
|
2012-08-25 12:25:22 -07:00
|
|
|
do
|
|
|
|
# Grab the config block for Config.in
|
|
|
|
echo "# $i"
|
2019-01-19 14:58:04 -08:00
|
|
|
$SED -n '/^\*\//q;/^config [A-Z]/,$p' $i || return 1
|
2012-08-25 12:25:22 -07:00
|
|
|
echo
|
|
|
|
done
|
|
|
|
|
|
|
|
echo endmenu
|
2008-01-19 15:08:39 -08:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2012-02-23 19:03:18 -08:00
|
|
|
probeconfig > generated/Config.probed || rm generated/Config.probed
|
|
|
|
genconfig > generated/Config.in || rm generated/Config.in
|
2016-02-07 16:15:53 -08:00
|
|
|
|
|
|
|
# Find names of commands that can be built standalone in these C files
|
|
|
|
toys()
|
|
|
|
{
|
2016-02-14 12:04:21 -08:00
|
|
|
grep 'TOY(.*)' "$@" | grep -v TOYFLAG_NOFORK | grep -v "0))" | \
|
2019-01-19 14:58:04 -08:00
|
|
|
$SED -En 's/([^:]*):.*(OLD|NEW)TOY\( *([a-zA-Z][^,]*) *,.*/\1:\3/p'
|
2016-02-07 16:15:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
WORKING=
|
|
|
|
PENDING=
|
|
|
|
toys toys/*/*.c | (
|
|
|
|
while IFS=":" read FILE NAME
|
|
|
|
do
|
|
|
|
[ "$NAME" == help ] && continue
|
|
|
|
[ "$NAME" == install ] && continue
|
2020-05-18 23:54:15 -07:00
|
|
|
[ "$NAME" == sh ] && FILE="toys/*/*.c"
|
2016-02-07 17:09:39 -08:00
|
|
|
echo -e "$NAME: $FILE *.[ch] lib/*.[ch]\n\tscripts/single.sh $NAME\n"
|
2016-02-19 15:56:01 -08:00
|
|
|
echo -e "test_$NAME:\n\tscripts/test.sh $NAME\n"
|
2016-02-07 16:15:53 -08:00
|
|
|
[ "${FILE/pending//}" != "$FILE" ] &&
|
|
|
|
PENDING="$PENDING $NAME" ||
|
|
|
|
WORKING="$WORKING $NAME"
|
2016-03-23 01:25:37 -07:00
|
|
|
done &&
|
2019-08-22 07:29:45 -07:00
|
|
|
echo -e "clean::\n\t@rm -f $WORKING $PENDING" &&
|
2016-04-19 22:47:05 -07:00
|
|
|
echo -e "list:\n\t@echo $(echo $WORKING | tr ' ' '\n' | sort | xargs)" &&
|
2016-03-23 01:25:37 -07:00
|
|
|
echo -e "list_pending:\n\t@echo $(echo $PENDING | tr ' ' '\n' | sort | xargs)" &&
|
2019-01-19 14:58:04 -08:00
|
|
|
echo -e ".PHONY: $WORKING $PENDING" | $SED 's/ \([^ ]\)/ test_\1/g'
|
2016-03-23 01:25:37 -07:00
|
|
|
) > .singlemake
|