configure.ac 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. AC_PREREQ(2.69)
  2. AC_INIT([ptunnel-ng], [1.41], [], [], [])
  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. dnl `--disable-pcap`: Enabled if found.
  108. AC_ARG_ENABLE([pcap],
  109. [AS_HELP_STRING([--disable-pcap], [Disable pcap support. (default: enabled if found)])],,[pcap_enabled=yes])
  110. pcap_enabled=$(echo ${pcap_enabled})
  111. case ${pcap_enabled} in
  112. 1|y|yes) pcap_enabled=yes ;;
  113. ''|0|n|no) pcap_enabled= ;;
  114. *) AC_MSG_ERROR([Unknown option \`${pcap_enabled}\` for --disable-pcap]) ;;
  115. esac
  116. dnl `--disable-selinux`: Enabled if found.
  117. AC_ARG_ENABLE([selinux],
  118. [AS_HELP_STRING([--disable-selinux], [Disable SELINUX support. (default: enabled if found)])],,[selinux_enabled=yes])
  119. selinux_enabled=$(echo ${selinux_enabled})
  120. case ${selinux_enabled} in
  121. 1|y|yes) selinux_enabled=yes ;;
  122. ''|0|n|no) selinux_enabled= ;;
  123. *) AC_MSG_ERROR([Unknown option \`${selinux_enabled}\` for --disable-selinux]) ;;
  124. esac
  125. dnl `--with-randomdev`: Default value /dev/random
  126. use_customrng=no
  127. AC_MSG_CHECKING([for random device])
  128. AC_ARG_WITH([rngdev],
  129. [AS_HELP_STRING([--with-rngdev], [Set an alternative random device. (default: /dev/random)])],
  130. [use_customrng=yes], [with_rngdev="/dev/random"])
  131. case ${with_rngdev} in
  132. yes) with_rngdev="/dev/random" ;;
  133. /dev/random) ;;
  134. /dev/urandom) ;;
  135. *) 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.]) ;;
  136. esac
  137. AC_MSG_RESULT([${with_rngdev}])
  138. AC_DEFINE_UNQUOTED([RNGDEV], ["${with_rngdev}"],
  139. [set the path to the random device you want to use for pt_random])
  140. dnl Check libcap headers/functions.
  141. if test x"${pcap_enabled}" != x -a \
  142. x"${use_msw}" != xyes; then
  143. AC_CHECK_HEADERS([pcap.h],,
  144. [pcap_enabled=])
  145. AC_SEARCH_LIBS([pcap_lookupnet], [pcap],,
  146. [pcap_enabled=],)
  147. AC_CHECK_FUNCS([pcap_compile pcap_close pcap_setfilter pcap_dispatch],,
  148. [pcap_enabled=])
  149. fi
  150. dnl Check for more secure randomization functions
  151. if test x"${use_customrng}" != xyes; then
  152. AC_CHECK_HEADERS([bsd/stdlib.h],,)
  153. AC_SEARCH_LIBS([arc4random], [bsd],,,)
  154. AC_CHECK_FUNCS([arc4random], [arc4random_enabled=yes],)
  155. fi
  156. dnl Check for SELINUX
  157. if test x"${selinux_enabled}" != x; then
  158. AC_CHECK_HEADERS([selinux/selinux.h],,
  159. [selinux_enabled=])
  160. AC_SEARCH_LIBS([setcon], [selinux],,[selinux_enabled=],)
  161. fi
  162. dnl Check for ICMP_FILTER
  163. AC_MSG_CHECKING([for working ICMP_FILTER])
  164. AC_COMPILE_IFELSE(
  165. [AC_LANG_PROGRAM([[
  166. #include <netinet/in.h>
  167. #include <sys/socket.h>
  168. #include <linux/icmp.h>
  169. void foo() {
  170. struct icmp_filter filt;
  171. int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
  172. filt.data = ~((1<<ICMP_ECHO) | (1<<ICMP_ECHOREPLY));
  173. setsockopt(sockfd, SOL_RAW, ICMP_FILTER, &filt, sizeof filt);
  174. }
  175. ]], [])]
  176. ,[AC_MSG_RESULT([yes])
  177. with_icmp_filter="yes"]
  178. ,[AC_MSG_RESULT([no])
  179. with_icmp_filter="no"])
  180. dnl Check for Android liblog.so
  181. AC_SEARCH_LIBS([__android_log_vprint], [log],,,)
  182. dnl Set automake conf vars
  183. AM_CONDITIONAL([HAVE_PCAP], [test x"${pcap_enabled}" = xyes])
  184. AM_CONDITIONAL([HAVE_SELINUX], [test x"${selinux_enabled}" = xyes])
  185. AM_CONDITIONAL([IS_WINDOWS], [test x"${use_msw}" = xyes])
  186. AM_CONDITIONAL([HAVE_ICMPFILTER], [test x"${with_icmp_filter}" = xyes])
  187. AM_CONDITIONAL([HAVE_ARC4RANDOM], [test x"${arc4random_enabled}" = xyes])
  188. AM_CONDITIONAL([USE_CUSTOMRNG], [test x"${use_customrng}" = xyes])
  189. dnl output config headers
  190. AC_CONFIG_HEADERS([src/config.h:src/config.h.in])
  191. AC_OUTPUT