configure 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. END
  32. }
  33. mkdir tmp 2>/dev/null
  34. while [ -n "$1" ]
  35. do
  36. opt="$1"
  37. KEY=""
  38. VAL=yes
  39. case $opt in
  40. --help)
  41. print_help
  42. exit 0
  43. ;;
  44. --prefix=*)
  45. KEY="PREFIX"
  46. VAL=${opt:9}
  47. ;;
  48. --incdir=*)
  49. KEY="INSTALL_INCDIR"
  50. VAL=${opt:9}
  51. ;;
  52. --libdir=*)
  53. KEY="INSTALL_LIBDIR"
  54. VAL=${opt:9}
  55. ;;
  56. --with-*)
  57. KEY="WITH_${opt:7}"
  58. ;;
  59. --without-*)
  60. KEY="WITH_${opt:10}"
  61. VAL=no
  62. ;;
  63. --enable-*)
  64. KEY="ENABLE_${opt:9}"
  65. ;;
  66. --disable-*)
  67. KEY="ENABLE_${opt:10}"
  68. VAL=no
  69. ;;
  70. *)
  71. print_help
  72. exit 255
  73. ;;
  74. esac
  75. if [ -n $KEY ]; then
  76. FEATURE=$(echo "$KEY" | tr "a-z-" "A-Z_")
  77. if [ ! -f tmp/config.mk ]; then
  78. cp config.ini tmp/config.mk
  79. fi
  80. shini_write "tmp/config.mk" "" "$FEATURE" "$VAL"
  81. fi
  82. shift 1
  83. done
  84. # config.mk
  85. echo "[config.mk]"
  86. if [ -f tmp/config.mk ]; then
  87. mv tmp/config.mk config.mk
  88. shini_write "config.mk" "" "CONFIG_DATE" "$(date +%Y%m%d)"
  89. fi
  90. cat config.mk
  91. echo ""
  92. # Checks for compiler
  93. echo -e "\nchecking for compiler..."
  94. if [ $CROSS_COMPILE ]; then
  95. CC=${CROSS_COMPILE}gcc
  96. CXX=${CROSS_COMPILE}g++
  97. fi
  98. if [ ! $CC ]; then
  99. CC=gcc
  100. CXX=g++
  101. fi
  102. CC_VERSION=`$CC --version 2>&1 | head -n 1`
  103. echo "CC = $CC"
  104. echo "CXX = $CXX"
  105. echo "$CC_VERSION"
  106. # Checks for os
  107. echo -e "\nchecking for os..."
  108. HOST_OS=`uname -s`
  109. HOST_ARCH=`uname -m`
  110. TARGET_PLATFORM=`$CC -v 2>&1 | grep Target | sed 's/Target: //'`
  111. TARGET_ARCH=`echo $TARGET_PLATFORM | awk -F'-' '{print $1}'`
  112. case $TARGET_PLATFORM in
  113. *mingw*) TARGET_OS=Windows ;;
  114. *android*) TARGET_OS=Android ;;
  115. *darwin*) TARGET_OS=Darwin ;;
  116. *) TARGET_OS=Linux ;;
  117. esac
  118. echo "HOST_OS = $HOST_OS"
  119. echo "HOST_ARCH = $HOST_ARCH"
  120. echo "TARGET_PLATFORM = $TARGET_PLATFORM"
  121. echo "TARGET_OS = $TARGET_OS"
  122. echo "TARGET_ARCH = $TARGET_ARCH"
  123. # hconfig.h
  124. echo -e "\n>> hconfig.h"
  125. confile=hconfig.h
  126. cat << END > $confile
  127. #ifndef HV_CONFIG_H_
  128. #define HV_CONFIG_H_
  129. END
  130. write_define() {
  131. cat << END >> hconfig.h
  132. #ifndef $macro
  133. #define $macro $value
  134. #endif
  135. END
  136. }
  137. check_header() {
  138. echo -n "checking for $header... "
  139. rm tmp/check 2>/dev/null
  140. cat << END > tmp/check.c
  141. #include <$header>
  142. int main() {
  143. return 0;
  144. }
  145. END
  146. $CC -o tmp/check tmp/check.c 2>/dev/null
  147. if [ -x tmp/check ]; then
  148. value=1
  149. echo "yes"
  150. else
  151. value=0
  152. echo "no"
  153. fi
  154. macro=HAVE_$(echo $header | tr a-z./ A-Z__)
  155. write_define
  156. }
  157. check_function() {
  158. echo -n "checking for $function... "
  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. echo "no"
  172. else
  173. value=1
  174. echo "yes"
  175. fi
  176. macro=HAVE_$(echo $function | tr a-z A-Z)
  177. write_define
  178. }
  179. check_option() {
  180. value=$(eval echo \$$option)
  181. echo "checking for $option=$value"
  182. if [ "$value" == "yes" ]; then
  183. cat << END >> $confile
  184. #define $option 1
  185. END
  186. else
  187. cat << END >> $confile
  188. /* #undef $option */
  189. END
  190. fi
  191. }
  192. # Checks for programs
  193. # Checks for libraries
  194. # Checks for header files
  195. header=stdbool.h && check_header
  196. header=stdint.h && check_header
  197. header=stdatomic.h && check_header
  198. header=sys/types.h && check_header
  199. header=sys/stat.h && check_header
  200. header=sys/time.h && check_header
  201. header=fcntl.h && check_header
  202. header=pthread.h && check_header
  203. # Checks for functions
  204. function=gettid && header=unistd.h && check_function
  205. function=strlcpy && header=string.h && check_function
  206. function=strlcat && header=string.h && check_function
  207. function=clock_gettime && header=time.h && check_function
  208. function=gettimeofday && header=sys/time.h && check_function
  209. function=pthread_spin_lock && header=pthread.h && check_function
  210. function=pthread_mutex_timedlock && header=pthread.h && check_function
  211. function=sem_timedwait && header=semaphore.h && check_function
  212. # Checks for options
  213. source config.mk 2>/dev/null
  214. option=WITH_OPENSSL && check_option
  215. option=WITH_GNUTLS && check_option
  216. option=WITH_MBEDTLS && check_option
  217. option=ENABLE_UDS && check_option
  218. option=USE_MULTIMAP && check_option
  219. # end confile
  220. cat << END >> $confile
  221. #endif // HV_CONFIG_H_
  222. END
  223. echo "configure done."