aboutsummaryrefslogtreecommitdiff
blob: acc3f15115ba41db13ff8712bc403770ac0bd511 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/sh

# This is a quick'n'dirty hack to make the program behave correctly
# under different systems.
# Example:
# when using libc5, (f)trucate's offset argument type is size_t with
# libc5, but it's off_t with libc6 (glibc2).
#
# Uhm... time to learn GNU autoconf :-)
#
# $Header$

OUTFILE='localdecls.h'

# if your arch needs to dlopen() glibc, add it here separated by space :]
BROKEN_RTLD_ARCHLIST="mips"

echo '/* This file is automatically generated     *' > $OUTFILE
echo ' * Modify create-localdecls instead of this */' >> $OUTFILE
echo >> $OUTFILE
echo '#ifndef __LOCALDECLS_H_' >> $OUTFILE
echo '#define __LOCALDECLS_H_' >> $OUTFILE
echo >> $OUTFILE

###
###
###

echo -n 'Checking truncate argument type... '
if grep -q 'truncate.*size_t' /usr/include/unistd.h ; then
	echo 'size_t'
	echo '#define TRUNCATE_T size_t' >> $OUTFILE
else
	echo 'off_t' # At least, I HOPE it's off_t :-)
	echo '#define TRUNCATE_T off_t' >> $OUTFILE
fi

###
###
###

echo -n 'Checking libc version... '
gcc -Wall -o libctest libctest.c
VERSION=`ldd libctest | grep libc\\.so | grep -v 'ld-uClibc' | awk '{print $1}'`

echo $VERSION
echo "#define LIBC_VERSION \"$VERSION\"" >> $OUTFILE
if test "$VERSION" = 'libc.so.5' ; then
	echo '#define BROKEN_RTLD_NEXT' >> $OUTFILE
	echo '#define LIBC 5' >> $OUTFILE
else
	# for the arch's that need to dlopen() libc to fetch real funcs!
	# 16.12.02 -Torgeir Hansen <torgeir@trenger.ro>
	MYARCH=`/bin/uname -m`
	for x in $BROKEN_RTLD_ARCHLIST; do
		if [ $x = $MYARCH ]; then
			echo '#define BROKEN_RTLD_NEXT' >> $OUTFILE
		fi
	done

fi

if test "$VERSION" = 'libc.so.6' ; then
	echo -n 'Checking glibc subversion...'
	tmp="$(ldd libctest 2>/dev/null | grep libc.so 2>/dev/null | head -n 1)"
	LibcPath=`expr "$tmp" : '[^/]*\(/[^ ]*\)'`
	tmp="`strings $LibcPath | grep -i 'c library'`"
	OsLibcMajor=`expr "$tmp" : '.* \([0-9][0-9]*\)'`
	OsLibcMinor=`expr "$tmp" : '.* [0-9][0-9]*\.\([0-9][0-9]*\)'`
	echo " ${OsLibcMajor}.${OsLibcMinor}"
	case "$OsLibcMajor" in
	2)
		# 2 is the glibc version
		case "$OsLibcMinor" in
		0)
			echo '#define GLIBC_MINOR 0' >> $OUTFILE
			SUBVERSION='glibc-2.0' ;;
		1)
			echo '#define GLIBC_MINOR 1' >> $OUTFILE
			SUBVERSION='glibc-2.1' ;;
		2)
			echo '#define GLIBC_MINOR 2' >> $OUTFILE
			SUBVERSION='glibc-2.2' ;;
		3)
			echo '#define GLIBC_MINOR 3' >> $OUTFILE
			SUBVERSION='glibc-2.3' ;;
		*)
			echo 'Treated as glibc >= 2.1 (finger crossed)'
			echo '#define GLIBC_MINOR 1' >> $OUTFILE
			SUBVERSION='glibc-2.1' ;;
	        esac
		;;
	esac
fi

rm libctest

echo '
#ifdef PATH_MAX
# define SB_PATH_MAX PATH_MAX * 2
# if (SB_PATH_MAX >= INT_MAX) || (SB_PATH_MAX < PATH_MAX)
#  undef SB_PATH_MAX
#  define SB_PATH_MAX PATH_MAX + 25
#  if (SB_PATH_MAX >= INT_MAX) || (SB_PATH_MAX < PATH_MAX)
#   error SB_PATH_MAX too big!
#  endif
# endif
#else
# error PATH_MAX not defined!
#endif' >> $OUTFILE

echo >> $OUTFILE
echo '#endif' >> $OUTFILE
echo