1
0

configure 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. features:
  22. --enable-ipv6 enable IPv6? (DEFAULT: $ENABLE_IPV6)
  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. check_header() {
  140. echo -n "checking for $header... "
  141. rm tmp/check 2>/dev/null
  142. cat << END > tmp/check.c
  143. #include <$header>
  144. int main() {
  145. return 0;
  146. }
  147. END
  148. $CC -o tmp/check tmp/check.c 2>/dev/null
  149. if [ -x tmp/check ]; then
  150. value=1
  151. echo "yes"
  152. else
  153. value=0
  154. echo "no"
  155. fi
  156. macro=HAVE_$(echo $header | tr a-z./ A-Z__)
  157. write_define
  158. }
  159. check_function() {
  160. echo -n "checking for $function... "
  161. rm tmp/check 2>/dev/null
  162. cat << END > tmp/check.c
  163. #include <$header>
  164. int $function(void** pp) {return 0;}
  165. int main() {
  166. void* p;
  167. return $function(&p);
  168. }
  169. END
  170. $CC -o tmp/check tmp/check.c 2>/dev/null
  171. if [ -x tmp/check ]; then
  172. value=0
  173. echo "no"
  174. else
  175. value=1
  176. echo "yes"
  177. fi
  178. macro=HAVE_$(echo $function | tr a-z A-Z)
  179. write_define
  180. }
  181. check_option() {
  182. value=$(eval echo \$$option)
  183. echo "checking for $option=$value"
  184. if [ "$value" == "yes" ]; then
  185. cat << END >> $confile
  186. #define $option 1
  187. END
  188. else
  189. cat << END >> $confile
  190. /* #undef $option */
  191. END
  192. fi
  193. }
  194. # Checks for programs
  195. # Checks for libraries
  196. # Checks for header files
  197. header=stdbool.h && check_header
  198. header=stdint.h && check_header
  199. header=stdatomic.h && check_header
  200. header=sys/types.h && check_header
  201. header=sys/stat.h && check_header
  202. header=sys/time.h && check_header
  203. header=fcntl.h && check_header
  204. header=pthread.h && check_header
  205. # Checks for functions
  206. function=gettid && header=unistd.h && check_function
  207. function=strlcpy && header=string.h && check_function
  208. function=strlcat && header=string.h && check_function
  209. function=clock_gettime && header=time.h && check_function
  210. function=gettimeofday && header=sys/time.h && check_function
  211. function=pthread_spin_lock && header=pthread.h && check_function
  212. function=pthread_mutex_timedlock && header=pthread.h && check_function
  213. function=sem_timedwait && header=semaphore.h && check_function
  214. # Checks for options
  215. source config.mk 2>/dev/null
  216. option=WITH_OPENSSL && check_option
  217. option=WITH_GNUTLS && check_option
  218. option=WITH_MBEDTLS && check_option
  219. option=ENABLE_UDS && check_option
  220. option=USE_MULTIMAP && check_option
  221. option=WITH_KCP && check_option
  222. # end confile
  223. cat << END >> $confile
  224. #endif // HV_CONFIG_H_
  225. END
  226. echo "configure done."