1
0

configure 5.6 KB

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