1
0

configure 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #!/bin/bash
  2. confile=hconfig.h
  3. # start confile
  4. cat << END > $confile
  5. #ifndef HV_CONFIG_H_
  6. #define HV_CONFIG_H_
  7. END
  8. # Checks for compiler
  9. echo "checking for compiler..."
  10. if [ $CROSS_COMPILE ]; then
  11. CC=${CROSS_COMPILE}gcc
  12. CXX=${CROSS_COMPILE}g++
  13. fi
  14. if [ ! $CC ]; then
  15. CC=gcc
  16. CXX=g++
  17. fi
  18. CC_VERSION=`$CC --version 2>&1 | head -n 1`
  19. echo "CC = $CC"
  20. echo "CXX = $CXX"
  21. echo "$CC_VERSION"
  22. # shell functions
  23. write_define() {
  24. cat << END >> hconfig.h
  25. #ifndef $macro
  26. #define $macro $value
  27. #endif
  28. END
  29. }
  30. mkdir tmp 2>/dev/null
  31. check_header() {
  32. echo -n "checking for $header... "
  33. rm tmp/check 2>/dev/null
  34. cat << END > tmp/check.c
  35. #include <$header>
  36. int main() {
  37. return 0;
  38. }
  39. END
  40. $CC -o tmp/check tmp/check.c 2>/dev/null
  41. if [ -x tmp/check ]; then
  42. value=1
  43. echo "yes"
  44. else
  45. value=0
  46. echo "no"
  47. fi
  48. macro=HAVE_$(echo $header | tr a-z./ A-Z__)
  49. write_define
  50. }
  51. check_function() {
  52. echo -n "checking for $function... "
  53. rm tmp/check 2>/dev/null
  54. cat << END > tmp/check.c
  55. #include <$header>
  56. int $function(void** pp) {return 0;}
  57. int main() {
  58. void* p;
  59. return $function(&p);
  60. }
  61. END
  62. $CC -o tmp/check tmp/check.c 2>/dev/null
  63. if [ -x tmp/check ]; then
  64. value=0
  65. echo "no"
  66. else
  67. value=1
  68. echo "yes"
  69. fi
  70. macro=HAVE_$(echo $function | tr a-z A-Z)
  71. write_define
  72. }
  73. check_option() {
  74. value=$(eval echo \$$option)
  75. echo "checking for $option=$value"
  76. if [ "$value" == "yes" ]; then
  77. cat << END >> $confile
  78. #define $option 1
  79. END
  80. else
  81. cat << END >> $confile
  82. /* #undef $option */
  83. END
  84. fi
  85. }
  86. # Checks for os
  87. echo "checking for os..."
  88. HOST_OS=`uname -s`
  89. HOST_ARCH=`uname -m`
  90. TARGET_PLATFORM=`$CC -v 2>&1 | grep Target | sed 's/Target: //'`
  91. TARGET_ARCH=`echo $TARGET_PLATFORM | awk -F'-' '{print $1}'`
  92. case $TARGET_PLATFORM in
  93. *mingw*) TARGET_OS=Windows ;;
  94. *android*) TARGET_OS=Android ;;
  95. *darwin*) TARGET_OS=Darwin ;;
  96. *) TARGET_OS=Linux ;;
  97. esac
  98. echo "HOST_OS = $HOST_OS"
  99. echo "HOST_ARCH = $HOST_ARCH"
  100. echo "TARGET_PLATFORM = $TARGET_PLATFORM"
  101. echo "TARGET_OS = $TARGET_OS"
  102. echo "TARGET_ARCH = $TARGET_ARCH"
  103. # Checks for programs
  104. # Checks for libraries
  105. # Checks for header files
  106. header=stdbool.h && check_header
  107. header=stdint.h && check_header
  108. header=stdatomic.h && check_header
  109. header=sys/types.h && check_header
  110. header=sys/stat.h && check_header
  111. header=sys/time.h && check_header
  112. header=fcntl.h && check_header
  113. header=pthread.h && check_header
  114. # Checks for functions
  115. function=gettid && header=unistd.h && check_function
  116. function=strlcpy && header=string.h && check_function
  117. function=strlcat && header=string.h && check_function
  118. function=clock_gettime && header=time.h && check_function
  119. function=gettimeofday && header=sys/time.h && check_function
  120. function=pthread_spin_lock && header=pthread.h && check_function
  121. function=pthread_mutex_timedlock && header=pthread.h && check_function
  122. function=sem_timedwait && header=semaphore.h && check_function
  123. # Checks for options
  124. source config.mk
  125. option=ENABLE_UDS && check_option
  126. option=USE_MULTIMAP && check_option
  127. # end confile
  128. cat << END >> $confile
  129. #endif // HV_CONFIG_H_
  130. END
  131. echo "configure done."