configure 5.2 KB

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