configure 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. # Checks for os
  74. echo "checking for os..."
  75. HOST_OS=`uname -s`
  76. HOST_ARCH=`uname -m`
  77. TARGET_PLATFORM=`$CC -v 2>&1 | grep Target | sed 's/Target: //'`
  78. TARGET_ARCH=`echo $TARGET_PLATFORM | awk -F'-' '{print $1}'`
  79. case $TARGET_PLATFORM in
  80. *mingw*) TARGET_OS=Windows ;;
  81. *android*) TARGET_OS=Android ;;
  82. *darwin*) TARGET_OS=Darwin ;;
  83. *) TARGET_OS=Linux ;;
  84. esac
  85. echo "HOST_OS = $HOST_OS"
  86. echo "HOST_ARCH = $HOST_ARCH"
  87. echo "TARGET_PLATFORM = $TARGET_PLATFORM"
  88. echo "TARGET_OS = $TARGET_OS"
  89. echo "TARGET_ARCH = $TARGET_ARCH"
  90. # Checks for programs
  91. # Checks for libraries
  92. # Checks for header files
  93. header=stdbool.h && check_header
  94. header=stdint.h && check_header
  95. header=sys/types.h && check_header
  96. header=sys/stat.h && check_header
  97. header=sys/time.h && check_header
  98. header=fcntl.h && check_header
  99. header=pthread.h && check_header
  100. # Checks for functions
  101. function=gettid && header=unistd.h && check_function
  102. function=strlcpy && header=string.h && check_function
  103. function=strlcat && header=string.h && check_function
  104. function=clock_gettime && header=time.h && check_function
  105. function=gettimeofday && header=sys/time.h && check_function
  106. function=pthread_spin_lock && header=pthread.h && check_function
  107. function=pthread_mutex_timedlock && header=pthread.h && check_function
  108. function=sem_timedwait && header=semaphore.h && check_function
  109. # end confile
  110. cat << END >> $confile
  111. #endif // HV_CONFIG_H_
  112. END
  113. echo "configure done."