configure.ac 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. AC_PREREQ(2.69)
  2. AC_INIT([ptunnel-ng], [1.42], [], [], [])
  3. AC_CONFIG_SRCDIR([src/config.h.in])
  4. AC_CONFIG_FILES([Makefile src/Makefile])
  5. AC_CANONICAL_BUILD
  6. AC_CANONICAL_HOST
  7. case x"${host}" in
  8. x*-*-cygwin* | x*-*-mingw32*)
  9. dnl Some Windows includes required by third-party modules.
  10. use_msw=yes
  11. PROGRAM_EXT=".exe"
  12. ;;
  13. *-androideabi)
  14. use_android=yes
  15. ;;
  16. esac
  17. AM_SILENT_RULES([yes])
  18. AM_INIT_AUTOMAKE
  19. AC_PROG_INSTALL
  20. AC_PROG_CC
  21. AC_PROG_CC_STDC
  22. AC_USE_SYSTEM_EXTENSIONS
  23. AC_C_CONST
  24. AC_C_INLINE
  25. AC_TYPE_SIZE_T
  26. AC_CHECK_HEADER_STDBOOL
  27. AC_FUNC_VPRINTF
  28. AC_FUNC_MEMCMP
  29. dnl Check for -std=gnu99
  30. if test x"${ac_cv_prog_cc_stdc}" = x"no"; then
  31. AC_MSG_ERROR([Your compiler does not support \`-std=gnu99\`. This is fatal.])
  32. fi
  33. dnl Check for std includes.
  34. AC_CHECK_HEADERS([stdarg.h stdio.h unistd.h stdlib.h string.h stdint.h time.h signal.h assert.h],,
  35. [AC_MSG_ERROR([Missing essential std headers.])])
  36. if test x"${use_msw}" != x"yes"; then
  37. AC_CHECK_HEADERS([sys/unistd.h],,)
  38. AC_CHECK_HEADERS([sys/types.h sys/socket.h netinet/in.h arpa/inet.h netdb.h pthread.h errno.h net/ethernet.h syslog.h pwd.h grp.h],,
  39. [AC_MSG_ERROR([Missing essential non-Windows std headers.])])
  40. AC_SEARCH_LIBS([pthread_create], [pthread],,
  41. [AC_MSG_ERROR([Missing pthread library.])],)
  42. if test x"${use_android}" != x"yes"; then
  43. AC_CHECK_FUNCS([signal],,[AC_MSG_ERROR([Missing essential non-Android std functions.])])
  44. fi
  45. AC_CHECK_FUNCS([pthread_mutex_init pthread_mutex_lock pthread_mutex_unlock syslog getaddrinfo freeaddrinfo gai_strerror],,
  46. [AC_MSG_ERROR([Missing essential Linux std functions.])])
  47. else
  48. AC_CHECK_TOOL([DLLTOOL], [dlltool], [:])
  49. if test x"${DLLTOOL}" = x":"; then
  50. AC_MSG_ERROR([Missing dlltool which is required to build the import library!])
  51. fi
  52. AC_CHECK_HEADERS([winsock2.h windows.h ws2tcpip.h],,
  53. [AC_MSG_ERROR([Missing essential Windows std headers.])])
  54. AC_CHECK_LIB([ws2_32],[main])
  55. fi
  56. AC_MSG_CHECKING([for GNU getopt_long])
  57. AC_COMPILE_IFELSE(
  58. [AC_LANG_PROGRAM([[
  59. #include <stdlib.h>
  60. #include <getopt.h>
  61. struct option long_options[] = {
  62. {"opt1", required_argument, 0, 'a'},
  63. {"opt2", optional_argument, 0, 'b'},
  64. {"opt3", no_argument, 0, 'c'}
  65. };
  66. void parse_opts(int argc, char **argv) {
  67. getopt_long(argc, argv, "a:b::c", &long_options[0], &optind);
  68. }
  69. ]], [])]
  70. ,[AC_MSG_RESULT([yes])]
  71. ,[AC_MSG_ERROR([Your compiler does not support \`_GNU_SOURCE\`.])])
  72. dnl Check timeval struct members.
  73. AC_CHECK_MEMBER([struct timeval.tv_sec], [],
  74. [AC_MSG_ERROR([Invalid \`struct timeval\` structure.])],
  75. [[#include <sys/time.h>]])
  76. AC_CHECK_MEMBER([struct timeval.tv_usec], [],
  77. [AC_MSG_ERROR([Invalid \`struct timeval\` structure.])],
  78. [[#include <sys/time.h>]])
  79. dnl Check size
  80. AC_CHECK_SIZEOF(char)
  81. AC_CHECK_SIZEOF(uint8_t)
  82. AC_CHECK_SIZEOF(uint16_t)
  83. AC_CHECK_SIZEOF(uint32_t)
  84. AC_CHECK_SIZEOF(int)
  85. if test $ac_cv_sizeof_char != "1" -o \
  86. $ac_cv_sizeof_uint8_t != "1" -o \
  87. $ac_cv_sizeof_uint16_t != "2" -o \
  88. $ac_cv_sizeof_uint32_t != "4" -o \
  89. $ac_cv_sizeof_int != "4"; then
  90. AC_MSG_ERROR([Invalid type size.])
  91. fi
  92. AC_MSG_CHECKING([for __attribute__ ((packed))])
  93. AC_COMPILE_IFELSE(
  94. [AC_LANG_PROGRAM([[
  95. #include <stdlib.h>
  96. struct foo {
  97. int num;
  98. char *str;
  99. void *ptr;
  100. } __attribute__ ((packed));
  101. ]], [])]
  102. ,[AC_MSG_RESULT([yes])]
  103. ,[AC_MSG_ERROR([Your compiler does not support \`__attribute__ ((packed))\`.])])
  104. dnl Check for std functions.
  105. AC_CHECK_FUNCS([malloc calloc free memcpy memset printf sprintf vsnprintf strerror strlen strncmp strstr strtol strtoul fopen fprintf gettimeofday close fclose exit getopt_long],,
  106. [AC_MSG_ERROR([Missing essential std functions.])])
  107. if test x"${use_msw}" = x; then
  108. AC_CHECK_FUNCS([inet_ntoa],,
  109. [AC_MSG_ERROR([Missing essential std functions.])])
  110. fi
  111. dnl `--disable-pcap`: Enabled if found.
  112. AC_ARG_ENABLE([pcap],
  113. [AS_HELP_STRING([--disable-pcap], [Disable pcap support. (default: enabled if found)])],,[pcap_enabled=yes])
  114. pcap_enabled=$(echo ${pcap_enabled})
  115. case ${pcap_enabled} in
  116. 1|y|yes) pcap_enabled=yes ;;
  117. ''|0|n|no) pcap_enabled= ;;
  118. *) AC_MSG_ERROR([Unknown option \`${pcap_enabled}\` for --disable-pcap]) ;;
  119. esac
  120. dnl `--disable-ssl`: Enabled if found.
  121. AC_ARG_ENABLE([ssl],
  122. [AS_HELP_STRING([--disable-ssl], [Disable ssl support. (default: enabled if found)])],,[ssl_enabled=yes])
  123. ssl_enabled=$(echo ${ssl_enabled})
  124. case ${ssl_enabled} in
  125. 1|y|yes) ssl_enabled=yes ;;
  126. ''|0|n|no) ssl_enabled= ;;
  127. *) AC_MSG_ERROR([Unknown option \`${ssl_enabled}\' for --disable-ssl]) ;;
  128. esac
  129. dnl `--enable-npcap`: Enable npcap interface (Windows only!)
  130. AC_ARG_ENABLE([npcap],
  131. [AS_HELP_STRING([--enable-npcap], [Enable npcap support. (Windows only; default: disabled)])],[npcap_enabled=yes],)
  132. npcap_enabled=$(echo ${npcap_enabled})
  133. case ${npcap_enabled} in
  134. 1|y|yes) pcap_enabled=yes ;;
  135. ''|0|n|no) pcap_enabled= ;;
  136. *) AC_MSG_ERROR([Unknown option \`${npcap_enabled}\` for --enable-npcap]) ;;
  137. esac
  138. dnl `--disable-selinux`: Enabled if found.
  139. AC_ARG_ENABLE([selinux],
  140. [AS_HELP_STRING([--disable-selinux], [Disable SELINUX support. (default: enabled if found)])],,[selinux_enabled=yes])
  141. selinux_enabled=$(echo ${selinux_enabled})
  142. case ${selinux_enabled} in
  143. 1|y|yes) selinux_enabled=yes ;;
  144. ''|0|n|no) selinux_enabled= ;;
  145. *) AC_MSG_ERROR([Unknown option \`${selinux_enabled}\` for --disable-selinux]) ;;
  146. esac
  147. dnl `--with-randomdev`: Default value /dev/random
  148. use_customrng=no
  149. AC_MSG_CHECKING([for random device])
  150. AC_ARG_WITH([rngdev],
  151. [AS_HELP_STRING([--with-rngdev], [Set an alternative random device. (default: /dev/random)])],
  152. [use_customrng=yes], [with_rngdev="/dev/random"])
  153. case ${with_rngdev} in
  154. yes) with_rngdev="/dev/random" ;;
  155. /dev/random) ;;
  156. /dev/urandom) ;;
  157. *) AC_MSG_ERROR([Unknown random device \`${with_rngdev}\` for --with-rngdev: Only \`/dev/random\` xor \`/dev/urandom\` allowed. This option is unused on Windows targets.]) ;;
  158. esac
  159. AC_MSG_RESULT([${with_rngdev}])
  160. AC_DEFINE_UNQUOTED([RNGDEV], ["${with_rngdev}"],
  161. [set the path to the random device you want to use for pt_random])
  162. dnl `--enable-asserts`: Disabled per default
  163. AC_ARG_ENABLE([asserts],
  164. [AS_HELP_STRING([--enable-asserts], [Enable asserts(). (default: disabled)])],[asserts_enabled=yes],)
  165. asserts_enabled=$(echo ${asserts_enabled})
  166. case ${asserts_enabled} in
  167. 1|y|yes) asserts_enabled=yes ;;
  168. ''|0|n|no) asserts_enabled=no ;;
  169. *) AC_MSG_ERROR([Unknown option \`${asserts_enabled}\` for --enable-asserts]) ;;
  170. esac
  171. dnl `--enable-sanitizer`: Disabled per default
  172. AC_ARG_ENABLE([sanitizer],
  173. [AS_HELP_STRING([--enable-sanitizer], [Enable ASAN, LSAN and UBSAN. (default: disabled)])],[sanitizer_enabled=yes],)
  174. sanitizer_enabled=$(echo ${sanitizer_enabled})
  175. case ${sanitizer_enabled} in
  176. 1|y|yes) sanitizer_enabled=yes ;;
  177. ''|0|n|no) sanitizer_enabled=no ;;
  178. *) AC_MSG_ERROR([Unknown option \`${sanitizer_enabled}\` for --enable-sanitizer]) ;;
  179. esac
  180. dnl Check libpcap headers/functions.
  181. if test x"${pcap_enabled}" != x -a \
  182. x"${use_msw}" != xyes; then
  183. AC_CHECK_HEADERS([pcap.h],,
  184. [pcap_enabled=])
  185. AC_SEARCH_LIBS([pcap_lookupnet], [pcap],,
  186. [pcap_enabled=],)
  187. AC_CHECK_FUNCS([pcap_compile pcap_close pcap_setfilter pcap_dispatch pcap_findalldevs pcap_freealldevs],,
  188. [pcap_enabled=])
  189. fi
  190. dnl Check openssl headers/functions.
  191. if test x"${ssl_enabled}" != x; then
  192. AC_CHECK_HEADERS([openssl/sha.h],,[ssl_enabled=])
  193. AC_SEARCH_LIBS([CRYPTO_new_ex_data],[crypto],,[ssl_enabled=])
  194. fi
  195. dnl Check for more secure randomization functions
  196. if test x"${use_customrng}" != xyes; then
  197. AC_CHECK_HEADERS([bsd/stdlib.h],,)
  198. AC_SEARCH_LIBS([arc4random], [bsd],,,)
  199. AC_CHECK_FUNCS([arc4random], [arc4random_enabled=yes],)
  200. fi
  201. dnl Check for SELINUX
  202. if test x"${selinux_enabled}" != x; then
  203. AC_CHECK_HEADERS([selinux/selinux.h],,
  204. [selinux_enabled=])
  205. AC_SEARCH_LIBS([setcon], [selinux],,[selinux_enabled=],)
  206. fi
  207. dnl Check for ICMP_FILTER
  208. AC_MSG_CHECKING([for working ICMP_FILTER])
  209. AC_COMPILE_IFELSE(
  210. [AC_LANG_PROGRAM([[
  211. #include <netinet/in.h>
  212. #include <sys/socket.h>
  213. #include <linux/icmp.h>
  214. void foo() {
  215. struct icmp_filter filt;
  216. int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
  217. filt.data = ~((1<<ICMP_ECHO) | (1<<ICMP_ECHOREPLY));
  218. setsockopt(sockfd, SOL_RAW, ICMP_FILTER, &filt, sizeof filt);
  219. }
  220. ]], [])]
  221. ,[AC_MSG_RESULT([yes])
  222. with_icmp_filter="yes"]
  223. ,[AC_MSG_RESULT([no])
  224. with_icmp_filter="no"])
  225. dnl Check for Android liblog.so
  226. AC_SEARCH_LIBS([__android_log_vprint], [log],,,)
  227. dnl Set automake conf vars
  228. AM_CONDITIONAL([HAVE_PCAP], [test x"${pcap_enabled}" = xyes])
  229. AM_CONDITIONAL([ENABLE_SHA512], [test x"${ssl_enabled}" = xyes])
  230. AM_CONDITIONAL([HAVE_NPCAP], [test x"${npcap_enabled}" = xyes])
  231. AM_CONDITIONAL([HAVE_SELINUX], [test x"${selinux_enabled}" = xyes])
  232. AM_CONDITIONAL([IS_WINDOWS], [test x"${use_msw}" = xyes])
  233. AM_CONDITIONAL([HAVE_ICMPFILTER], [test x"${with_icmp_filter}" = xyes])
  234. AM_CONDITIONAL([HAVE_ARC4RANDOM], [test x"${arc4random_enabled}" = xyes])
  235. AM_CONDITIONAL([USE_CUSTOMRNG], [test x"${use_customrng}" = xyes])
  236. AM_CONDITIONAL([DISABLE_ASSERTS], [test x"${asserts_enabled}" != xyes])
  237. AM_CONDITIONAL([ENABLE_SANITIZER], [test x"${sanitizer_enabled}" = xyes])
  238. dnl output config headers
  239. AC_CONFIG_HEADERS([src/config.h:src/config.h.in])
  240. AC_OUTPUT