| 1 |
#!/bin/sh |
| 2 |
# |
| 3 |
# Generate feature.{c|flags} |
| 4 |
# |
| 5 |
|
| 6 |
top_srcdir=$1 |
| 7 |
top_builddir=$2 |
| 8 |
host=$3 |
| 9 |
|
| 10 |
if [ -z "$1" -o -z "$2" -o -z "$3" ]; then |
| 11 |
echo "Usage: gen-features.sh TOP_SRCDIR TOP_BUILDDIR HOST" |
| 12 |
exit 1 |
| 13 |
fi |
| 14 |
|
| 15 |
config=${top_builddir}/src/gauche/config.h |
| 16 |
|
| 17 |
features_c=${top_builddir}/src/features.c |
| 18 |
features_c_tmp=${features_c}.$$ |
| 19 |
features_flags=${top_builddir}/src/features.flags |
| 20 |
features_flags_tmp=${features_flags}.$$ |
| 21 |
host_tmp=gen-features.tmp.$$ |
| 22 |
|
| 23 |
clean () { |
| 24 |
rm -f ${features_c_tmp} |
| 25 |
rm -f ${features_flags_tmp} |
| 26 |
rm -f ${host_tmp} |
| 27 |
} |
| 28 |
|
| 29 |
trap clean EXIT |
| 30 |
|
| 31 |
# add_feature feature_name [module_name] |
| 32 |
add_feature() { |
| 33 |
feature_name=$1 |
| 34 |
module_name=$2 |
| 35 |
if [ -z "$module_name" -o "$module_name" = NULL ]; then |
| 36 |
echo " { \"$feature_name\", NULL }," >> $features_c_tmp |
| 37 |
else |
| 38 |
echo " { \"$feature_name\", \"$module_name\" }," >> $features_c_tmp |
| 39 |
fi |
| 40 |
echo " -F$feature_name" >> $features_flags_tmp |
| 41 |
} |
| 42 |
|
| 43 |
# remove_feature feature_name |
| 44 |
remove_feature() { |
| 45 |
feature_name=$1 |
| 46 |
echo " -F-$feature_name" >> $features_flags_tmp |
| 47 |
} |
| 48 |
|
| 49 |
set_cpu_os_features() { |
| 50 |
# set up cpu and os from autoconf triplet |
| 51 |
echo $host | tr -- '-' ' ' > $host_tmp |
| 52 |
read cputype manufacturer kernel os < $host_tmp |
| 53 |
|
| 54 |
if [ -n "$cputype" ]; then |
| 55 |
add_feature "$cputype" |
| 56 |
fi |
| 57 |
|
| 58 |
if [ -n "$kernel" ]; then |
| 59 |
# kernel part may contain release number. We set both the full name |
| 60 |
# and the name without release number. |
| 61 |
kernel_sans_rel=`echo $kernel | sed -e 's/[0-9.]*$//'` |
| 62 |
|
| 63 |
add_feature "$kernel" |
| 64 |
if [ "$kernel" != "$kernel_sans_rel" ]; then |
| 65 |
add_feature "$kernel_sans_rel" |
| 66 |
fi |
| 67 |
case $kernel_sans_rel in |
| 68 |
freebsd|openbsd|netbsd|netbsdelf|darwin) |
| 69 |
add_feature "bsd";; |
| 70 |
esac |
| 71 |
|
| 72 |
if [ -n "$os" ]; then |
| 73 |
# e.g. 'linux-gnu' |
| 74 |
add_feature "$kernel-$os" |
| 75 |
if [ "$kernel" != "$kernel_sans_rel" ]; then |
| 76 |
add_feature "$kernel_sans_rel-$os" |
| 77 |
fi |
| 78 |
fi |
| 79 |
fi |
| 80 |
} |
| 81 |
|
| 82 |
# check feature_name definition ... |
| 83 |
# Search definition ... in config.h, and if found, add feature_name. |
| 84 |
check () { |
| 85 |
feature_name=$1 |
| 86 |
module_name=$2 |
| 87 |
have_feature=no |
| 88 |
shift 2 |
| 89 |
while [ $# -gt 0 ]; do |
| 90 |
definition=$1 |
| 91 |
shift |
| 92 |
if grep "#define $definition" $config > /dev/null; then |
| 93 |
have_feature=yes |
| 94 |
break |
| 95 |
fi |
| 96 |
done |
| 97 |
|
| 98 |
if [ $have_feature = yes ]; then |
| 99 |
add_feature "$feature_name" "$module_name" |
| 100 |
else |
| 101 |
remove_feature "$feature_name" |
| 102 |
fi |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
clean |
| 107 |
set_cpu_os_features |
| 108 |
check gauche.sys.sigwait NULL HAVE_SIGWAIT |
| 109 |
check gauche.sys.setenv NULL HAVE_PUTENV HAVE_SETENV |
| 110 |
check gauche.sys.unsetenv NULL HAVE_UNSETENV |
| 111 |
check gauche.sys.clearenv NULL HAVE_CLEARENV |
| 112 |
check gauche.sys.getloadavg NULL HAVE_GETLOADAVG |
| 113 |
check gauche.sys.getrlimit NULL HAVE_SYS_RESOURCE_H |
| 114 |
check gauche.sys.lchown NULL HAVE_LCHOWN |
| 115 |
check gauche.sys.getpgid NULL HAVE_GETPGID |
| 116 |
check gauche.sys.setgroups NULL HAVE_SETGROUPS |
| 117 |
check gauche.sys.nanosleep NULL HAVE_NANOSLEEP GAUCHE_WINDOWS |
| 118 |
check gauche.sys.crypt NULL HAVE_CRYPT |
| 119 |
check gauche.sys.symlink NULL HAVE_SYMLINK |
| 120 |
check gauche.sys.readlink NULL HAVE_READLINK |
| 121 |
check gauche.sys.select NULL HAVE_SELECT |
| 122 |
|
| 123 |
check gauche.net.ipv6 gauche.net HAVE_IPV6 |
| 124 |
check gauche.sys.openpty gauche.termios HAVE_OPENPTY |
| 125 |
check gauche.sys.forkpty gauche.termios HAVE_FORKPTY |
| 126 |
check gauche.sys.syslog gauche.syslog HAVE_SYSLOG |
| 127 |
check gauche.sys.setlogmask gauche.syslog HAVE_SETLOGMASK |
| 128 |
check gauche.sys.fcntl gauche.fcntl HAVE_FCNTL |
| 129 |
check gauche.sys.statvfs gauche.fcntl HAVE_SYS_STATVFS_H |
| 130 |
|
| 131 |
mv $features_c_tmp $features_c |
| 132 |
mv $features_flags_tmp $features_flags |