configure 5.3 KB

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