1dnl Process this File with autoconf to produce a configure script.
2AC_PREREQ(2.61)
3AC_INIT([gsocket], 1.4.28)
4dnl AC_CONFIG_AUX_DIR(config-x86_64-apple-darwin19.6.0)
5AC_CONFIG_AUX_DIR(config)
6AC_CANONICAL_SYSTEM
7
8dnl we use automake
9AM_INIT_AUTOMAKE([foreign])
10AM_CONFIG_HEADER(config.h)
11AM_PROG_AR
12dnl for --enable-maintainer-mode fun use:
13dnl AM_MAINTAINER_MODE
14dnl AC_DISABLE_STATIC
15dnl LT_INIT([disable-static])
16
17dnl AC_CONFIG_MACRO_DIRS([m4])
18
19dnl Checks for programs.
20AC_PROG_CC
21AC_PROG_INSTALL
22AC_PROG_RANLIB
23
24dnl
25dnl Use these compiler flags if we have gcc.
26dnl
27if test $ac_cv_prog_gcc = yes; then
28  CCOPTS='-O2 -Wall'
29  CFLAGS="$CCOPTS $CFLAGS"
30fi
31test "x$prefix" != "xNONE" || prefix="/usr/local"
32test "x$exec_prefix" != "xNONE" || exec_prefix="${prefix}"
33trydir_i="${prefix}/include /usr/include"
34trydir_l="${prefix}/lib /usr/lib"
35
36if test "${prefix}" != "/usr/local" ; then
37	trydir_i="${trydir_i} /usr/local/include"
38	trydir_l="${trydir_l} /usr/local/lib"
39fi
40
41dnl Try include paths (especially on OSX)
42trydir_i="${trydir_i} /usr/local/opt/openssl/include"
43for xincdir in $trydir_i ; do
44	if test ! -d "$xincdir" ; then
45		continue;
46	fi
47	if test x"${INCLUDES}" = x; then
48		INCLUDES="-I${xincdir}";
49	else
50		INCLUDES="$INCLUDES -I${xincdir}";
51	fi
52done
53CPPFLAGS="-I${srcdir}/../include ${INCLUDES} $CPPFLAGS"
54
55dnl Try library paths...
56trydir_l="${trydir_l} /usr/local/opt/openssl/lib"
57for xlibdir in $trydir_l ; do
58	if test ! -d "$xlibdir" ; then
59		continue;
60	fi
61	if test x"${LIBDIR}" = x; then
62		LIBDIR="-L${xlibdir}";
63	else
64		LIBDIR="$LIBDIR -L${xlibdir}";
65	fi
66done
67LDFLAGS="${LIBDIR} $LDFLAGS"
68
69dnl default perm of .so is 644 but on cygwin must be 755.
70PERM_DSO="644"
71case "$host" in
72*-cygwin*)
73	PERM_DSO="755"
74	;;
75mips-sony-bsd|mips-sony-newsos4)
76        AC_DEFINE([NEED_SETPGRP], [1], [Need setpgrp to acquire controlling tty])
77	;;
78*-*-ultrix*)
79        AC_DEFINE([NEED_SETPGRP], [1], [Need setpgrp to acquire controlling tty])
80	;;
81*-*-darwin*|*-*-*bsd*)
82	AC_DEFINE([BSD_SCRIPT], [1], [/usr/bin/script is the bsd variant])
83	if test x"$(which ar)" != x'/usr/bin/ar'; then
84		ARDIRWARN=1
85	fi
86	;;
87esac
88
89dnl Checks for header files.
90AC_HEADER_STDC
91AC_HEADER_SYS_WAIT
92AC_CHECK_HEADERS(sys/time.h sys/endian.h unistd.h fnmatch.h string.h utmp.h utmpx.h pty.h openssl/srp.h util.h libutil.h netinet/in_systm.h sys/loadavg.h libproc.h)
93
94AC_CHECK_HEADER(openssl/srp.h, [], [AC_MSG_ERROR([openssl/srp.h not found. Update OpenSSL?])])
95
96dnl Checks for typedefs, structures, and compiler characteristics.
97AC_C_CONST
98AC_TYPE_PID_T
99AC_HEADER_TIME
100
101dnl Checks for library functions.
102AC_FUNC_MEMCMP
103
104AC_TYPE_SIGNAL
105dnl If size_t is not defined, define size_t to be unsigned.
106AC_TYPE_SIZE_T
107dnl If uid_t is not defined, define uid_t to be int and gid_t to be int.
108AC_TYPE_UID_T
109
110AC_ARG_ENABLE(static,
111[  --enable-static          Compile static binary],
112	[STATIC="yes"], [STATIC="no"]
113)
114
115if test x"$STATIC" = x"yes"; then
116	dnl static OpenSSL lib requires pthread
117	dnl AC_CHECK_LIB(pthread, pthread_once)
118	dnl LDADD_STATIC="" dnl -static"
119	CFLAGS_STATIC="-static "
120fi
121
122AC_CHECK_LIB(util, forkpty)
123AC_CHECK_LIB(socket, socket)
124AC_CHECK_LIB(nsl, gethostbyname)
125dnl AC_CHECK_LIB([net], [libnet_name_resolve], [AC_MSG_ERROR([libnet 1.0.x found. Requires libnet 1.1 or newer])])
126dnl AC_CHECK_LIB([net], [libnet_init], ,[AC_MSG_ERROR([libnet 1.1.x not found])])
127if test x"$STATIC" = xno; then
128	AC_CHECK_LIB(dl, dlopen)
129fi
130AC_CHECK_LIB(procstat, procstat_close)
131AC_CHECK_LIB([crypto], [ENGINE_init], [], [AC_MSG_ERROR([libcrypto not found])])
132AC_CHECK_LIB([ssl], [SRP_VBASE_get1_by_user], [], [AC_MSG_ERROR([SRP not supported. Please upgrade OpenSSL lib])])
133
134AC_CHECK_FUNCS(gettimeofday memcpy strchr strlcat forkpty openpty getline stat64 open64 statvfs64 accept4 connectx)
135
136AC_ARG_ENABLE([31337],
137	AS_HELP_STRING([--enable-31337], [Enable experimental features.]),
138	AC_DEFINE(D31337, 1, [Expermental feature])
139)
140
141AC_ARG_ENABLE([debug],
142	AS_HELP_STRING([--enable-debug], [Enable debug information.]),
143	[debug=true AC_DEFINE(DEBUG, 1, [Debug infos])]
144)
145
146AC_ARG_ENABLE([tests],
147	AS_HELP_STRING([--enable-tests], [Enable self-tests.]),
148	[selftests=true]
149)
150
151AS_IF([test x$enable_debug = xyes], AC_DEFINE(D31337, 1, [Expermental feature]))
152AS_IF([test x$enable_debug = xyes], [selftests=true])
153
154AS_IF([test x$selftests = xtrue], AC_DEFINE(SELFTESTS, 1, [Self Tests]))
155
156AC_ARG_ENABLE(dist,
157[  --enable-dist           Enable distribution mode, Use own libraries.],
158	[DIST="yes"], [DIST="no"]
159)
160
161AS_IF([test x$selftests = xtrue], AC_SUBST(PROGRAMS_TEST_LIB, "list-test${EXEEXT} event-test${EXEEXT}"))
162AS_IF([test x$selftests = xtrue], AC_SUBST(PROGRAMS_TEST_TOOLS, "packet-test${EXEEXT} readline-test${EXEEXT} console_display-test${EXEEXT} filetransfer-test${EXEEXT}"))
163
164AC_SUBST(LDADD_STATIC, "${LDADD_STATIC}")
165AC_SUBST(CFLAGS_STATIC, "${CFLAGS_STATIC}")
166AC_SUBST(PERM_DSO, "${PERM_DSO}")
167AC_OUTPUT([Makefile lib/Makefile tools/Makefile include/Makefile include/gsocket/Makefile tools/gsocket.conf man/Makefile examples/Makefile])
168
169
170echo "
171
172      \"If netcat is a swiss army knife then
173                        gs-netcat is a germanic battle axe\"
174
175	                        --acpizer/United Cracking Force
176"
177
178if test x"${STATIC}" = xyes; then
179echo "
180********************************** WARNING ***********************************
181* Your MUST compile OpenSSL like this:                                       *
182* openssl-src>                                                               *
183* ./Configure --prefix=\$HOME/usr no-dso no-threads no-shared linux-generic64 *
184* mkdir -p \$HOME/usr && make all install                                     *
185* Only then compile gsocket \(using the same --prefix=\):                    *
186* gsocket-src> ./configure --prefix=\$HOME/usr --enable-static                *
187* gsocket-src> make all install                                              *
188* gsocket-src> export PATH=\$HOME/usr/bin:\$PATH                               *
189******************************************************************************
190"
191fi
192
193echo "
194${PACKAGE_NAME}-${PACKAGE_VERSION} has been configured:
195
196 Host..............: ${host}
197 Compiler..........: ${CC}
198 Compiler flags....: ${CFLAGS_STATIC}${CFLAGS}
199 Preprocessor flags: ${CPPFLAGS}
200 Linker flags......: ${LDFLAGS}
201 Libraries.........: ${LIBS}
202
203Configuration complete. Now type: make all install"
204if test x"${ARDIRWARN}" = x1; then
205	AC_MSG_WARN([Build tools seem to be a mix of GNU and Apple.])
206	AC_MSG_WARN([Alex, try 'PATH=/usr/bin:\$PATH ./configure'.])
207fi
208
209