configure 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. #!/bin/bash
  2. . "$(dirname "$0")/scripts/shini.sh"
  3. print_help() {
  4. shini_parse "config.ini"
  5. cat << END
  6. Usage: ./configure [--option] ...
  7. options:
  8. --prefix=PREFIX (DEFAULT: $PREFIX)
  9. --incdir=INSTALL_INCDIR (DEFAULT: $PREFIX/include/hv)
  10. --libdir=INSTALL_LIBDIR (DEFAULT: $PREFIX/lib)
  11. --with-MODULE
  12. --without-MODULE
  13. --enable-FEATURE
  14. --disable-FEATURE
  15. modules:
  16. --with-protocol compile protocol module? (DEFAULT: $WITH_PROTOCOL)
  17. --with-evpp compile evpp module? (DEFAULT: $WITH_EVPP)
  18. --with-http compile http module? (DEFAULT: $WITH_HTTP)
  19. --with-http-client compile http client module? (DEFAULT: $WITH_HTTP_CLIENT)
  20. --with-http-server compile http server module? (DEFAULT: $WITH_HTTP_SERVER)
  21. --with-mqtt compile mqtt module? (DEFAULT: $WITH_MQTT)
  22. features:
  23. --enable-uds enable Unix Domain Socket? (DEFAULT: $ENABLE_UDS)
  24. --enable-windump enable Windows coredump? (DEFAULT: $ENABLE_WINDUMP)
  25. dependencies:
  26. --with-curl compile with curl? (DEFAULT: $WITH_CURL)
  27. --with-nghttp2 compile with nghttp2? (DEFAULT: $WITH_NGHTTP2)
  28. --with-openssl compile with openssl? (DEFAULT: $WITH_OPENSSL)
  29. --with-gnutls compile with gnutls? (DEFAULT: $WITH_GNUTLS)
  30. --with-mbedtls compile with mbedtls? (DEFAULT: $WITH_MBEDTLS)
  31. rudp:
  32. --with-kcp compile with kcp? (DEFAULT: $WITH_KCP)
  33. END
  34. }
  35. mkdir tmp 2>/dev/null
  36. while [ -n "$1" ]
  37. do
  38. opt="$1"
  39. KEY=""
  40. VAL=yes
  41. case $opt in
  42. --help)
  43. print_help
  44. exit 0
  45. ;;
  46. --prefix=*)
  47. KEY="PREFIX"
  48. VAL=${opt:9}
  49. ;;
  50. --incdir=*)
  51. KEY="INSTALL_INCDIR"
  52. VAL=${opt:9}
  53. ;;
  54. --libdir=*)
  55. KEY="INSTALL_LIBDIR"
  56. VAL=${opt:9}
  57. ;;
  58. --with-*)
  59. KEY="WITH_${opt:7}"
  60. ;;
  61. --without-*)
  62. KEY="WITH_${opt:10}"
  63. VAL=no
  64. ;;
  65. --enable-*)
  66. KEY="ENABLE_${opt:9}"
  67. ;;
  68. --disable-*)
  69. KEY="ENABLE_${opt:10}"
  70. VAL=no
  71. ;;
  72. *)
  73. print_help
  74. exit 255
  75. ;;
  76. esac
  77. if [ -n $KEY ]; then
  78. FEATURE=$(echo "$KEY" | tr "a-z-" "A-Z_")
  79. if [ ! -f tmp/config.mk ]; then
  80. cp config.ini tmp/config.mk
  81. fi
  82. shini_write "tmp/config.mk" "" "$FEATURE" "$VAL"
  83. fi
  84. shift 1
  85. done
  86. # config.mk
  87. echo "[config.mk]"
  88. if [ -f tmp/config.mk ]; then
  89. mv tmp/config.mk config.mk
  90. shini_write "config.mk" "" "CONFIG_DATE" "$(date +%Y%m%d)"
  91. fi
  92. cat config.mk
  93. echo ""
  94. # Checks for compiler
  95. echo -e "\nchecking for compiler..."
  96. if [ $CROSS_COMPILE ]; then
  97. CC=${CROSS_COMPILE}gcc
  98. CXX=${CROSS_COMPILE}g++
  99. fi
  100. if [ ! $CC ]; then
  101. CC=gcc
  102. CXX=g++
  103. fi
  104. CC_VERSION=`$CC --version 2>&1 | head -n 1`
  105. echo "CC = $CC"
  106. echo "CXX = $CXX"
  107. echo "$CC_VERSION"
  108. # Checks for os
  109. echo -e "\nchecking for os..."
  110. HOST_OS=`uname -s`
  111. HOST_ARCH=`uname -m`
  112. TARGET_PLATFORM=`$CC -v 2>&1 | grep Target | sed 's/Target: //'`
  113. TARGET_ARCH=`echo $TARGET_PLATFORM | awk -F'-' '{print $1}'`
  114. case $TARGET_PLATFORM in
  115. *mingw*) TARGET_OS=Windows ;;
  116. *android*) TARGET_OS=Android ;;
  117. *darwin*) TARGET_OS=Darwin ;;
  118. *) TARGET_OS=Linux ;;
  119. esac
  120. echo "HOST_OS = $HOST_OS"
  121. echo "HOST_ARCH = $HOST_ARCH"
  122. echo "TARGET_PLATFORM = $TARGET_PLATFORM"
  123. echo "TARGET_OS = $TARGET_OS"
  124. echo "TARGET_ARCH = $TARGET_ARCH"
  125. # hconfig.h
  126. echo -e "\n>> hconfig.h"
  127. confile=hconfig.h
  128. cat << END > $confile
  129. #ifndef HV_CONFIG_H_
  130. #define HV_CONFIG_H_
  131. END
  132. write_define() {
  133. cat << END >> hconfig.h
  134. #ifndef $macro
  135. #define $macro $value
  136. #endif
  137. END
  138. }
  139. CheckHeaderExists() {
  140. rm tmp/check 2>/dev/null
  141. cat << END > tmp/check.c
  142. #include <$header>
  143. int main() {
  144. return 0;
  145. }
  146. END
  147. $CC -o tmp/check tmp/check.c 2>/dev/null
  148. if [ -x tmp/check ]; then
  149. value=1
  150. else
  151. value=0
  152. fi
  153. }
  154. CheckSymbolExists() {
  155. CheckHeaderExists
  156. if [ $value -eq 0 ]; then
  157. return;
  158. fi
  159. rm tmp/check 2>/dev/null
  160. cat << END > tmp/check.c
  161. #include <$header>
  162. int $function(void** pp) {return 0;}
  163. int main() {
  164. void* p;
  165. return $function(&p);
  166. }
  167. END
  168. $CC -o tmp/check tmp/check.c 2>/dev/null
  169. if [ -x tmp/check ]; then
  170. value=0
  171. else
  172. value=1
  173. fi
  174. }
  175. check_header() {
  176. echo -n "checking for $header... "
  177. CheckHeaderExists
  178. if [ $value -eq 0 ]; then
  179. echo "no"
  180. else
  181. echo "yes"
  182. fi
  183. macro=HAVE_$(echo $header | tr a-z./ A-Z__)
  184. write_define
  185. }
  186. check_function() {
  187. echo -n "checking for $function... "
  188. CheckSymbolExists
  189. if [ $value -eq 0 ]; then
  190. echo "no"
  191. else
  192. echo "yes"
  193. fi
  194. macro=HAVE_$(echo $function | tr a-z A-Z)
  195. write_define
  196. }
  197. check_option() {
  198. value=$(eval echo \$$option)
  199. echo "checking for $option=$value"
  200. if [ "$value" == "yes" ]; then
  201. cat << END >> $confile
  202. #define $option 1
  203. END
  204. else
  205. cat << END >> $confile
  206. /* #undef $option */
  207. END
  208. fi
  209. }
  210. # Checks for programs
  211. # Checks for libraries
  212. # Checks for header files
  213. header=stdbool.h && check_header
  214. header=stdint.h && check_header
  215. header=stdatomic.h && check_header
  216. header=sys/types.h && check_header
  217. header=sys/stat.h && check_header
  218. header=sys/time.h && check_header
  219. header=fcntl.h && check_header
  220. header=pthread.h && check_header
  221. header=endian.h && check_header
  222. header=sys/endian.h && check_header
  223. # Checks for functions
  224. function=gettid && header=unistd.h && check_function
  225. function=strlcpy && header=string.h && check_function
  226. function=strlcat && header=string.h && check_function
  227. function=clock_gettime && header=time.h && check_function
  228. function=gettimeofday && header=sys/time.h && check_function
  229. function=pthread_spin_lock && header=pthread.h && check_function
  230. function=pthread_mutex_timedlock && header=pthread.h && check_function
  231. function=sem_timedwait && header=semaphore.h && check_function
  232. function=pipe && header=unistd.h && check_function
  233. function=socketpair && header=sys/socket.h && check_function
  234. function=eventfd && header=sys/eventfd.h && check_function
  235. function=setproctitle && header=unistd.h && check_function
  236. # Checks for options
  237. source config.mk 2>/dev/null
  238. option=WITH_OPENSSL && check_option
  239. option=WITH_GNUTLS && check_option
  240. option=WITH_MBEDTLS && check_option
  241. option=ENABLE_UDS && check_option
  242. option=USE_MULTIMAP && check_option
  243. option=WITH_KCP && check_option
  244. # end confile
  245. cat << END >> $confile
  246. #endif // HV_CONFIG_H_
  247. END
  248. echo "configure done."