1 | AC_PREREQ(2.59) |
1 | AC_PREREQ([2.61]) |
2 | AC_INIT(sandbox, 1.2.2, dev-portage@gentoo.org) |
2 | AC_INIT([sandbox], [1.3.0], [sandbox@gentoo.org]) |
3 | AM_INIT_AUTOMAKE |
3 | AM_INIT_AUTOMAKE |
4 | AC_CONFIG_HEADER([config.h]) |
4 | AC_CONFIG_HEADER([config.h]) |
5 | |
5 | |
6 | # Checks for programs. |
6 | dnl Checks for programs. |
7 | AC_PROG_CC |
7 | AC_PROG_CC |
|
|
8 | AM_PROG_CC_C_O |
8 | AC_ISC_POSIX |
9 | AC_ISC_POSIX |
9 | AC_PROG_INSTALL |
10 | AC_PROG_INSTALL |
10 | AC_PROG_MAKE_SET |
11 | AC_PROG_MAKE_SET |
11 | AC_PROG_AWK |
12 | AC_PROG_AWK |
|
|
13 | AC_CHECK_PROGS([READELF], [readelf eu-readelf], [false]) |
|
|
14 | AM_MISSING_PROG([AUTOM4TE], [autom4te]) |
12 | |
15 | |
13 | AC_ENABLE_SHARED |
16 | AC_ENABLE_SHARED |
14 | AC_DISABLE_STATIC |
17 | AC_DISABLE_STATIC |
|
|
18 | dnl Next four lines is a hack to prevent libtool checking for CXX/F77 |
|
|
19 | m4_undefine([AC_PROG_CXX]) |
|
|
20 | m4_defun([AC_PROG_CXX],[]) |
|
|
21 | m4_undefine([AC_PROG_F77]) |
|
|
22 | m4_defun([AC_PROG_F77],[]) |
15 | AC_PROG_LIBTOOL |
23 | AC_PROG_LIBTOOL |
16 | |
24 | |
17 | AC_PREFIX_DEFAULT([/usr]) |
25 | AC_PREFIX_DEFAULT([/usr]) |
18 | |
26 | |
19 | # Checks for libraries. |
27 | dnl Checks for libraries. |
20 | # Checks for header files. |
28 | dnl Checks for header files. |
21 | AC_FUNC_ALLOCA |
29 | AC_FUNC_ALLOCA |
22 | AC_HEADER_DIRENT |
30 | AC_HEADER_DIRENT |
23 | AC_HEADER_STDC |
31 | AC_HEADER_STDC |
24 | AC_HEADER_SYS_WAIT |
32 | AC_HEADER_SYS_WAIT |
25 | AC_CHECK_HEADERS([ \ |
33 | AC_CHECK_HEADERS_ONCE([ \ |
26 | fcntl.h limits.h memory.h stddef.h \ |
34 | dirent.h \ |
27 | stdlib.h string.h strings.h sys/file.h \ |
35 | dlfcn.h \ |
28 | sys/param.h sys/time.h unistd.h utime.h \ |
36 | elf.h \ |
|
|
37 | errno.h \ |
|
|
38 | execinfo.h \ |
|
|
39 | fcntl.h \ |
|
|
40 | libgen.h \ |
|
|
41 | limits.h \ |
|
|
42 | memory.h \ |
|
|
43 | signal.h \ |
|
|
44 | stdarg.h \ |
|
|
45 | stdbool.h \ |
|
|
46 | stddef.h \ |
|
|
47 | stdio.h \ |
|
|
48 | stdlib.h \ |
|
|
49 | string.h \ |
|
|
50 | strings.h \ |
|
|
51 | syscall.h \ |
|
|
52 | unistd.h \ |
|
|
53 | utime.h \ |
|
|
54 | sys/file.h \ |
|
|
55 | sys/mman.h \ |
|
|
56 | sys/param.h \ |
|
|
57 | sys/stat.h \ |
|
|
58 | sys/time.h \ |
|
|
59 | sys/types.h \ |
|
|
60 | sys/wait.h \ |
29 | ]) |
61 | ]) |
30 | |
62 | |
31 | # Checks for typedefs, structures, and compiler characteristics. |
63 | dnl Checks for typedefs, structures, and compiler characteristics. |
32 | AC_C_CONST |
64 | AC_C_CONST |
33 | AC_TYPE_UID_T |
65 | AC_TYPE_UID_T |
34 | AC_TYPE_MODE_T |
66 | AC_TYPE_MODE_T |
35 | AC_TYPE_SIZE_T |
67 | AC_TYPE_SIZE_T |
36 | AC_CHECK_TYPES([ptrdiff_t]) |
68 | AC_CHECK_TYPES([ptrdiff_t]) |
37 | |
69 | |
38 | # Checks for library functions. |
70 | dnl Checks for library functions. |
39 | AC_FUNC_CHOWN |
71 | AC_FUNC_CHOWN |
40 | AC_FUNC_FORK |
72 | AC_FUNC_FORK |
41 | AC_FUNC_LSTAT |
73 | AC_FUNC_LSTAT |
42 | AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK |
74 | AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK |
43 | AC_FUNC_MALLOC |
|
|
44 | AC_FUNC_REALLOC |
|
|
45 | AC_TYPE_SIGNAL |
75 | AC_TYPE_SIGNAL |
46 | AC_FUNC_STAT |
76 | AC_FUNC_STAT |
47 | AC_CHECK_FUNCS([ \ |
77 | AC_CHECK_FUNCS_ONCE([ \ |
48 | bzero ftruncate getcwd lchown memmove \ |
78 | backtrace \ |
49 | mempcpy memset mkdir pathconf realpath \ |
79 | ftruncate \ |
50 | rmdir setenv strcasecmp strchr strdup \ |
80 | getcwd \ |
51 | strerror strndup strrchr strspn strstr \ |
81 | lchown \ |
|
|
82 | memmove \ |
|
|
83 | memcpy \ |
|
|
84 | memset \ |
|
|
85 | mkdir \ |
|
|
86 | pathconf \ |
|
|
87 | realpath \ |
|
|
88 | rmdir \ |
|
|
89 | setenv \ |
|
|
90 | strcasecmp \ |
|
|
91 | strchr \ |
|
|
92 | strdup \ |
|
|
93 | strerror \ |
|
|
94 | strndup \ |
|
|
95 | strrchr \ |
|
|
96 | strspn \ |
|
|
97 | strstr \ |
|
|
98 | strtok_r \ |
52 | ]) |
99 | ]) |
|
|
100 | dnl For librcutil |
|
|
101 | AC_CHECK_FUNCS([remove]) |
53 | |
102 | |
54 | dnl |
103 | dnl Check if gcc provides va_copy or __va_copy (for librcutil) |
55 | dnl FIXME: the following needs to be made portable |
104 | AC_MSG_CHECKING([for va_copy]) |
56 | dnl |
105 | AC_TRY_COMPILE([ |
|
|
106 | #include <stdarg.h> |
|
|
107 | ], [ |
|
|
108 | va_list ap, aq; |
|
|
109 | va_copy(ap, aq); |
|
|
110 | ], |
|
|
111 | [va_copy="va_copy"], |
|
|
112 | [AC_TRY_COMPILE([ |
|
|
113 | #include <stdarg.h> |
|
|
114 | ], [ |
|
|
115 | va_list ap, aq; |
|
|
116 | __va_copy(ap, aq); |
|
|
117 | ], |
|
|
118 | [va_copy="__va_copy"], |
|
|
119 | [AC_MSG_ERROR([Unable to determine name of va_copy macro])] |
|
|
120 | )] |
|
|
121 | ) |
|
|
122 | AC_MSG_RESULT([$va_copy]) |
|
|
123 | if test x"$va_copy" != xva_copy ; then |
|
|
124 | AC_DEFINE_UNQUOTED([va_copy], [$va_copy], |
|
|
125 | [Define to name of va_copy macro proviced by gcc if its not `va_copy'.] |
|
|
126 | ) |
|
|
127 | fi |
|
|
128 | |
|
|
129 | dnl Verify people aren't doing stupid shit |
|
|
130 | if test x"$enable_static" != xno ; then |
|
|
131 | AC_MSG_ERROR([dont be a Kumba, building a libsandbox.a is stupid]) |
|
|
132 | fi |
|
|
133 | if test x"$enable_shared" != xyes ; then |
|
|
134 | AC_MSG_ERROR([dont be a Kumba, omitting a libsandbox.so is stupid]) |
|
|
135 | fi |
|
|
136 | if echo $CFLAGS | $EGREP -e -static >/dev/null 2>&1; then |
|
|
137 | AC_MSG_ERROR([dont be a Kumba, using -static in CFLAGS is stupid]) |
|
|
138 | fi |
|
|
139 | if echo $LDFLAGS | $EGREP -e -static >/dev/null 2>&1; then |
|
|
140 | AC_MSG_ERROR([dont be a Kumba, using -static in LDFLAGS is stupid]) |
|
|
141 | fi |
|
|
142 | |
|
|
143 | dnl Some libc's like those on bsd have dlopen() in libc, and not libdl |
|
|
144 | AC_CHECK_LIB([dl], [dlopen], |
|
|
145 | [have_libdl="yes"], |
|
|
146 | [have_libdl="no"] |
|
|
147 | ) |
|
|
148 | if test x"$have_libdl" = xyes ; then |
|
|
149 | LIBDL="-ldl" |
|
|
150 | AC_SUBST([LIBDL]) |
|
|
151 | DL_LIB="dl" |
|
|
152 | else |
|
|
153 | DL_LIB="c" |
|
|
154 | AC_CHECK_LIB([c], [dlopen], |
|
|
155 | [], |
|
|
156 | [AC_MSG_ERROR([Unable to determine library providing dlopen])] |
|
|
157 | ) |
|
|
158 | fi |
|
|
159 | |
|
|
160 | dnl uClibc doesn't currently provide dlvsym() so lets |
|
|
161 | dnl verify the toolchain supports it |
|
|
162 | AC_CHECK_LIB([$DL_LIB], [dlvsym], |
|
|
163 | [AC_DEFINE([HAVE_DLVSYM], [1], [libdl supports dlvsym])], |
|
|
164 | [AC_DEFINE([HAVE_DLVSYM], [0], [libdl does not support dlvsym])] |
|
|
165 | ) |
57 | |
166 | |
58 | dnl when using libc5, (f)trucate's offset argument type is size_t with |
167 | dnl when using libc5, (f)trucate's offset argument type is size_t with |
59 | dnl libc5, but it's off_t with libc6 (glibc2). |
168 | dnl libc5, but it's off_t with libc6 (glibc2). |
60 | AC_MSG_CHECKING(truncate argument type) |
169 | AC_MSG_CHECKING([truncate argument type]) |
61 | if grep -q 'truncate.*size_t' /usr/include/unistd.h ; then |
170 | TRUNC_ARG_TYPE=`echo '#include <unistd.h>' | $CC -E - | grep -q 'truncate.*size_t'` |
|
|
171 | if test "$TRUNC_ARG_TYPE"x != x ; then |
62 | AC_MSG_RESULT(size_t) |
172 | AC_MSG_RESULT([size_t]) |
63 | AC_DEFINE(TRUNCATE_T, size_t, [truncate arg type]) |
173 | AC_DEFINE([TRUNCATE_T], [size_t], [truncate arg type]) |
64 | else |
174 | else |
65 | AC_MSG_RESULT(off_t) |
175 | AC_MSG_RESULT([off_t]) |
66 | AC_DEFINE(TRUNCATE_T, off_t, [truncate arg type]) |
176 | AC_DEFINE([TRUNCATE_T], [off_t], [truncate arg type]) |
67 | fi |
177 | fi |
68 | |
178 | |
69 | AC_MSG_CHECKING(Checking libc version) |
179 | dnl Check if libc provides RTLD_NEXT |
|
|
180 | AC_MSG_CHECKING([for RTLD_NEXT]) |
|
|
181 | AC_TRY_COMPILE([ |
|
|
182 | #define _GNU_SOURCE |
|
|
183 | #include <dlfcn.h> |
|
|
184 | ], [ |
|
|
185 | #if !defined(RTLD_NEXT) |
|
|
186 | # error no RTLD_NEXT |
|
|
187 | #endif |
|
|
188 | ], |
|
|
189 | [have_rtld_next="yes"], |
|
|
190 | [have_rtld_next="no"] |
|
|
191 | ) |
|
|
192 | AC_MSG_RESULT([$have_rtld_next]) |
|
|
193 | if test x"$have_rtld_next" = xyes ; then |
|
|
194 | CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE" |
|
|
195 | AC_DEFINE([HAVE_RTLD_NEXT], [1], [Have RTLD_NEXT enabled libc]) |
|
|
196 | fi |
|
|
197 | |
|
|
198 | dnl we need to handle symbols differently based upon their version, |
|
|
199 | dnl but we have to know which symbols the libc supports first |
|
|
200 | AC_MSG_CHECKING([libc path]) |
70 | echo "int main(void) { return 0; }" > libctest.c |
201 | echo "int main(void) { return 0; }" > libctest.c |
71 | gcc -Wall -o libctest libctest.c |
202 | $CC $CFLAGS $CPPFLAGS $LDFLAGS -Wl,-verbose -o libctest libctest.c > libctest.log 2>&1 |
72 | LIBC_VERSION=`ldd libctest | grep libc\\.so | grep -v 'ld-uClibc' | ${AWK} '{print $1}'` |
203 | cat libctest.log 1>&AS_MESSAGE_LOG_FD |
73 | LIBC_PATH=`ldd libctest | grep libc\\.so | grep -v 'ld-uClibc' | ${AWK} '{print $3}'` |
204 | LIBC_PATH=$( |
|
|
205 | $AWK '/attempt to open/ { if (($4 ~ /\/libc\.so/) && ($5 == "succeeded")) LIBC = $4; }; END {print LIBC}' libctest.log |
|
|
206 | ) |
74 | rm -f libctest |
207 | rm -f libctest* |
75 | AC_SUBST(LIBC_VERSION) |
208 | if test x"$LIBC_PATH" = x || ! test -r "$LIBC_PATH" ; then |
|
|
209 | AC_MSG_ERROR([Unable to determine LIBC PATH ($LIBC_PATH)]) |
|
|
210 | fi |
|
|
211 | AC_MSG_RESULT([$LIBC_PATH]) |
76 | AC_SUBST(LIBC_PATH) |
212 | AC_SUBST([LIBC_PATH]) |
|
|
213 | |
|
|
214 | dnl when intercepting libc calls, we have to know the name of the |
|
|
215 | dnl libc to load and search with dl*() calls |
|
|
216 | AC_MSG_CHECKING([libc version]) |
|
|
217 | dnl the sed script at the end here looks funny but it's ok ... |
|
|
218 | echo "int main(void) { return 0; }" > libctest.c |
|
|
219 | $CC $CFLAGS $CPPFLAGS $LDFLAGS -Wall -o libctest libctest.c |
|
|
220 | LIBC_VERSION=$( |
|
|
221 | $READELF -d libctest | \ |
|
|
222 | grep NEEDED.*libc\\.so | \ |
|
|
223 | $AWK '{print $NF}' | sed -e ['s:\[::' -e 's:\]::'] |
|
|
224 | ) |
|
|
225 | rm -f libctest* |
|
|
226 | if test "$LIBC_VERSION"x = x ; then |
|
|
227 | AC_MSG_ERROR([Unable to determine LIBC VERSION]) |
|
|
228 | fi |
77 | AC_MSG_RESULT(${LIBC_VERSION}) |
229 | AC_MSG_RESULT([$LIBC_VERSION]) |
|
|
230 | AC_DEFINE_UNQUOTED([LIBC_VERSION], ["$LIBC_VERSION"], [Name of libc to hook into]) |
78 | |
231 | |
79 | AC_OUTPUT([Makefile]) |
232 | dnl We add to CPPFLAGS rather than doing AC_DEFINE_UNQUOTED |
|
|
233 | dnl so we dont have to worry about fully expanding all of |
|
|
234 | dnl the variables ($sysconfdir defaults to "$prefix/etc") |
|
|
235 | SANDBOX_DEFINES='-DETCDIR="\"$(sysconfdir)\"" -DLIBSANDBOX_PATH="\"$(libdir)\"" -DSANDBOX_BASHRC_PATH="\"$(pkgdatadir)\""' |
|
|
236 | AC_SUBST([SANDBOX_DEFINES]) |
|
|
237 | |
|
|
238 | CPPFLAGS="$CPPFLAGS -D_REENTRANT" |
|
|
239 | if test "$GCC" = yes; then |
|
|
240 | CFLAGS="$CFLAGS -Wall" |
|
|
241 | fi |
|
|
242 | |
|
|
243 | AC_CONFIG_TESTDIR([tests]) |
|
|
244 | |
|
|
245 | AC_OUTPUT([ |
|
|
246 | Makefile |
|
|
247 | scripts/Makefile |
|
|
248 | etc/Makefile |
|
|
249 | data/Makefile |
|
|
250 | libsbutil/Makefile |
|
|
251 | libsandbox/Makefile |
|
|
252 | src/Makefile |
|
|
253 | tests/atlocal |
|
|
254 | tests/Makefile |
|
|
255 | tests/package.m4 |
|
|
256 | ]) |