1#
2#  Copyright (C) 2000-2021, Thomas Maier-Komor
3#
4#  This is the source code of mbuffer.
5#
6#  This program is free software: you can redistribute it and/or modify
7#  it under the terms of the GNU General Public License as published by
8#  the Free Software Foundation, either version 3 of the License, or
9#  (at your option) any later version.
10#
11#  This program is distributed in the hope that it will be useful,
12#  but WITHOUT ANY WARRANTY; without even the implied warranty of
13#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14#  GNU General Public License for more details.
15#
16#  You should have received a copy of the GNU General Public License
17#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18#
19
20AC_INIT([mbuffer])
21AC_CONFIG_HEADER([config.h])
22AC_CONFIG_SRCDIR([mbuffer.c])
23AC_LANG([C])
24
25AC_CANONICAL_SYSTEM
26AC_EXEEXT
27AC_USE_SYSTEM_EXTENSIONS
28
29if test "${LD_LIBRARY_PATH}" != "" ; then
30	echo ""
31	echo "    WARNING: LD_LIBRARY_PATH is set. This can cause severe problems!!!"
32	echo "    Please learn about using RUNPATH instead of LD_LIBRARY_PATH - e.g. here:"
33	echo "    - http://prefetch.net/articles/linkers.badldlibrary.html"
34	echo "    For gcc, you can pass LDFLAGS=\"-R/usr/local/lib\" to configure,"
35	echo "    instead of setting LD_LIBRARY_PATH."
36	echo ""
37	sleep 5
38fi
39
40AC_PREFIX_DEFAULT(/usr/local)
41test "$prefix" = NONE && prefix=/usr/local
42test "$exec_prefix" = NONE && exec_prefix=$prefix
43
44USRCFLAGS=${CFLAGS}
45
46AC_LANG_C
47AC_PROG_CC_C99(cc gcc)
48AC_PATH_PROG(TAR,[gtar tar])
49AC_C_RESTRICT
50AC_C_INLINE
51
52if test "${USRCFLAGS}" = "" ; then
53	if test "${GCC}" = "yes" ; then
54		CFLAGS="${CFLAGS} -O2 -Wall"
55		cflags_tmp="${CFLAGS}"
56		CFLAGS="${CFLAGS} -m64"
57		AC_MSG_CHECKING([whether $CC supports $CFLAGS])
58		AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
59			[AC_MSG_RESULT([yes])],
60			[AC_MSG_RESULT([no])]
61			CFLAGS="$cflags_tmp"
62		)
63	else
64		SUNCCVERSION=`${CC} -V 2>&1 | grep Sun`
65		SUNCC=$?
66		if test "${SUNCC}" == "0" ; then
67			CFLAGS="${CFLAGS} -O"
68			cflags_tmp="$CFLAGS"
69			HAS_M64=`${CC} -flags | grep m64`
70			if test "${HAS_M64}" != "" ; then
71				CFLAGS="${CFLAGS} -m64"
72				AC_MSG_CHECKING([whether $CC supports $CFLAGS])
73				AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
74					[AC_MSG_RESULT([yes])],
75					[AC_MSG_RESULT([no])]
76					CFLAGS="$cflags_tmp"
77				)
78			else
79				CFLAGS="${CFLAGS} -xarch=generic64"
80				AC_MSG_CHECKING([whether $CC supports $CFLAGS])
81				AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
82					[AC_MSG_RESULT([yes])],
83					[AC_MSG_RESULT([no])]
84					CFLAGS="$cflags_tmp"
85				)
86			fi
87		else
88			echo unknown cc
89			CFLAGS="${CFLAGS} -O"
90		fi
91	fi
92fi
93
94
95cflags_tmp="$CFLAGS"
96CFLAGS="$CFLAGS -Wno-unused-result"
97AC_MSG_CHECKING([whether $CC provides -Wunused-result])
98AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
99	[AC_MSG_RESULT([yes])],
100	[AC_MSG_RESULT([no])]
101	CFLAGS="$cflags_tmp"
102)
103
104AC_SUBST(CFLAGS)
105
106AC_PROG_INSTALL
107AC_PATH_PROG(SH,sh)
108AC_PATH_PROG(RM,rm)
109AC_PATH_PROG(CP,cp)
110AC_PATH_PROG(MT,mt,AC_MSG_WARN(could not find the program mt - you might need this if you want autoloader support))
111AC_PATH_PROGS(TAR,[gtar tar])
112AC_PATH_PROG(AWK,awk)
113AC_SYS_LARGEFILE
114AC_STRUCT_ST_BLKSIZE
115
116AC_CHECK_TARGET_TOOLS(OBJDUMP,gobjdump objdump llvm-objdump)
117
118AC_HEADER_ASSERT
119AC_CHECK_LIB(pthread, pthread_mutex_init)
120AC_SEARCH_LIBS(dlsym,dl)
121AC_SEARCH_LIBS(clock_gettime,rt,,AC_MSG_ERROR(could not find the library containing clock_gettime!))
122AC_SEARCH_LIBS(sem_init,rt posix,,AC_MSG_ERROR(could not find semaphore functions!))
123AC_SEARCH_LIBS(rint,m,,AC_MSG_ERROR(unable to find rint))
124AC_SEARCH_LIBS(seteuid,c,AC_DEFINE([HAVE_SETEUID], [1], [Define to 1 if you have the seteuid() function]),)
125AC_SEARCH_LIBS(hstrerror,resolv socket nsl,AC_DEFINE([HAVE_HSTRERROR], [1], [Define to 1 if you have the hstrerror() function]),)
126AC_SEARCH_LIBS(getaddrinfo,resolv socket nsl ,AC_DEFINE([HAVE_GETADDRINFO], [1], [Define to 1 if you have the getaddrinfo() function]) ,AC_MSG_WARN(support for systems without getaddrinfo is deprecated and will be removed in the future))
127AC_SEARCH_LIBS(socket,socket,,AC_MSG_ERROR(could not find the library containing network functions!))
128AC_SEARCH_LIBS(gethostbyname,nsl,,AC_MSG_ERROR(could not find the library containing name convertion functions!))
129AC_SEARCH_LIBS(sendfile,sendfile,AC_DEFINE([HAVE_SENDFILE],[1],[libsendfile is available]),)
130AC_CHECK_HEADER(sys/sendfile.h,AC_DEFINE([HAVE_SENDFILE_H],[1],[sendfile in sendfile.h]),)
131AC_FUNC_ALLOCA
132AC_CHECK_FUNCS(mkostemp)
133
134
135AC_ARG_ENABLE(debug,
136        [  --disable-debug         disable verbose logging to console for debugging purpose],
137        ,enable_debug=yes
138        )
139if test x$enable_debug = xyes ; then
140	AC_DEFINE([DEBUG], [1], [Define to 1 to build in debugging mode])
141fi
142
143AC_ARG_ENABLE(md5,
144        [  --disable-md5           disable md5 hash generation],
145	,enable_md5=auto
146	)
147if test x$enable_md5 != xno ; then
148	AC_SEARCH_LIBS(MD5Init,md5 md,AC_DEFINE([HAVE_LIBMD5], [1], [Define to 1 if you have the md5 library]),)
149	AC_CHECK_HEADER(md5.h,AC_DEFINE([HAVE_MD5_H],[1],[found md5.h]),)
150	AC_SEARCH_LIBS(MD5_Init,crypto,AC_DEFINE([HAVE_LIBCRYPTO], [1], [Define to 1 if you have the OpenSSL crypto library]),)
151fi
152
153
154AC_LANG(C)
155if test -z "$OBJDUMP"; then
156	AC_MSG_WARN([unable to find objdump, which is needed to run tests])
157else
158	AC_MSG_CHECKING([linking open() and write() to detect libc names])
159	AC_LINK_IFELSE([
160	AC_LANG_SOURCE([[
161		#define _LARGEFILE64_SOURCE
162		#include <unistd.h>
163		#include <fcntl.h>
164		#include <sys/stat.h>
165		int main(int argc, char **argv) {
166			unsigned x;
167			struct stat st;
168			open(*argv,O_RDONLY);
169			fstat(0,&st);
170			read(0,&x,sizeof(x));
171			write(1,"null",4);
172		}
173	]])],[
174	AC_MSG_RESULT([OK])
175	AC_MSG_CHECKING([name of open() in C library])
176	libc_open=`$OBJDUMP -T conftest | $AWK '/\*UND\*/ && $NF ~ /^open/ { print $NF }'`
177	AC_DEFINE_UNQUOTED([LIBC_OPEN], $libc_open, [name of open() in libc])
178	AC_MSG_RESULT($libc_open)
179	AC_MSG_CHECKING([name of read() in C library])
180	libc_read=`$OBJDUMP -T conftest | $AWK '/\*UND\*/ && $NF ~ /^read/ { print $NF }'`
181	AC_DEFINE_UNQUOTED([LIBC_READ], $libc_read, [name of write() in libc])
182	AC_MSG_RESULT($libc_read)
183	AC_MSG_CHECKING([name of write() in C library])
184	libc_write=`$OBJDUMP -T conftest | $AWK '/\*UND\*/ && $NF ~ /^write/ { print $NF }'`
185	AC_DEFINE_UNQUOTED([LIBC_WRITE], $libc_write, [name of write() in libc])
186	AC_MSG_RESULT($libc_write)
187	AC_MSG_CHECKING([name of fstat() in C library])
188	libc_fstat=`$OBJDUMP -T conftest | $AWK '/\*UND\*/ && $NF ~ /^_*fstat/ { print $NF }'`
189	AC_DEFINE_UNQUOTED([LIBC_FSTAT], $libc_fstat, [name of fstat() in libc])
190	AC_MSG_RESULT($libc_fstat)
191	],
192	[AC_MSG_FAILURE([failed to link open/write test])]
193	)
194fi
195
196
197AC_SUBST(DEBUG)
198AC_SUBST(OBJDUMP)
199AC_SUBST(TAR)
200AC_SUBST(prefix)
201AC_SUBST(AUTOCONF)
202AC_DEFINE(_REENTRANT,1,Needed for thread safe compilation)
203
204AC_OUTPUT(Makefile)
205
206# vim:tw=0
207