build 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #!/bin/sh
  2. CC=${CC-`../scripts/compiler`}
  3. MAKE=${MAKE-`../scripts/make`}
  4. OS=${OS-`../scripts/os`}
  5. TARGET=${TARGET-`../scripts/target`}
  6. BINDIR="../bin/${OS}"
  7. CONFIG="../bin/${OS}/`../scripts/config`"
  8. NULL=/dev/null
  9. BASE=/tmp/dummy
  10. for t in /usr/tmp /var/tmp /tmp; do
  11. if [ -d $t -a -w $t ]
  12. then BASE=${t}/dummy
  13. break
  14. fi
  15. done
  16. trap 'rm -f ${BASE}$$.s ${BASE}$$.c ${BASE}$$.o ${BASE}$$; exit 1' 1 2 15
  17. # check for HP-UX's ANSI compiler
  18. echo "main(int ac, char *av[]) { int i; }" > ${BASE}$$.c
  19. if ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c 1>${NULL} 2>${NULL}
  20. then
  21. true;
  22. else
  23. rm -f ${BASE}$$
  24. if ${CC} ${CFLAGS} -Ae -o ${BASE}$$ ${BASE}$$.c 1>${NULL} 2>${NULL}
  25. then
  26. CFLAGS="${CFLAGS} -Ae"
  27. fi
  28. fi
  29. rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
  30. # check for IA64 HP-UX w/ HP's ANSI compiler; may need pointer swizzling
  31. arch=`echo $OS | awk -F- '{print $1;}'`
  32. if [ X$CC = "Xcc" -a X$arch = "Xia64" ]
  33. then
  34. echo "#include <stdlib.h>" > ${BASE}$$.c
  35. echo "main(int ac, char *av[])" >> ${BASE}$$.c
  36. echo "{ long* p = (long*)malloc(sizeof(long));" >> ${BASE}$$.c
  37. echo "*p = 0; exit((int)*p); }" >> ${BASE}$$.c
  38. ${CC} ${CFLAGS} +DD64 -o ${BASE}$$ ${BASE}$$.c 1>${NULL} 2>${NULL} \
  39. && [ -x ${BASE}$$ ] \
  40. && ${BASE}$$ \
  41. && CFLAGS="${CFLAGS} +DD64"
  42. rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
  43. fi
  44. # check for bcopy (optionally set the SYS5 flag)
  45. echo "#include <string.h>" > ${BASE}$$.c
  46. echo "main() { char a[256], b[256]; bcopy(a, b, 256); }" >> ${BASE}$$.c
  47. ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c 1>${NULL} 2>${NULL} \
  48. || CFLAGS="${CFLAGS} -DSYS5"
  49. rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
  50. # check for valloc
  51. echo "#include <stdlib.h>" > ${BASE}$$.c
  52. echo "main() { char* buf = valloc(123); }" >> ${BASE}$$.c
  53. ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c 1>${NULL} 2>${NULL} \
  54. || CFLAGS="${CFLAGS} -Dvalloc=malloc"
  55. rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
  56. # check for getrusage
  57. if [ X$USE_RUSAGE = "X1" ]
  58. then
  59. echo "#include <sys/types.h>" > ${BASE}$$.c
  60. echo "#include <sys/time.h>" >> ${BASE}$$.c
  61. echo "#include <sys/resource.h>" >> ${BASE}$$.c
  62. echo "#ifndef RUSAGE_SELF" >> ${BASE}$$.c
  63. echo "#define RUSAGE_SELF 0" >> ${BASE}$$.c
  64. echo "#endif /* RUSAGE_SELF */" >> ${BASE}$$.c
  65. echo "main() { struct rusage ru; getrusage(RUSAGE_SELF, &ru); }" >> ${BASE}$$.c
  66. ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c 1>${NULL} 2>${NULL} \
  67. && CFLAGS="${CFLAGS} -DRUSAGE"
  68. rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
  69. fi
  70. # check for -lnsl
  71. echo "extern int pmap_getport(); main() { pmap_getport(); }" > ${BASE}$$.c
  72. if ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c 1>${NULL} 2>${NULL}; then
  73. true;
  74. else
  75. ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c -lnsl 1>${NULL} 2>${NULL} \
  76. && LDLIBS="${LDLIBS} -lnsl"
  77. fi
  78. rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
  79. # check for -lsocket
  80. echo "extern void* getservent(); main() { getservent(); }" > ${BASE}$$.c
  81. if ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c 1>${NULL} 2>${NULL}; then
  82. true;
  83. else
  84. ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c -lsocket 1>${NULL} 2>${NULL} \
  85. && LDLIBS="${LDLIBS} -lsocket"
  86. fi
  87. rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
  88. # check for -lrt (solaris)
  89. echo "extern int nanosleep(); main() { nanosleep(); }" >${BASE}$$.c
  90. if ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c 1>${NULL} 2>${NULL}; then
  91. true;
  92. else
  93. ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c -lrt 1>${NULL} 2>${NULL} \
  94. && LDLIBS="${LDLIBS} -lrt"
  95. fi
  96. rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
  97. # check for -lrpc (cygwin/Windows)
  98. echo "extern int pmap_set(); main() { pmap_set(); }" >${BASE}$$.c
  99. if ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c 1>${NULL} 2>${NULL}; then
  100. true;
  101. else
  102. ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c -lrpc 1>${NULL} 2>${NULL} \
  103. && LDLIBS="${LDLIBS} -lrpc"
  104. fi
  105. rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
  106. # check for OSs that have S_IFFIFO instead of S_IFIFO
  107. echo "#include <sys/stat.h>" > ${BASE}$$.c
  108. echo "main() { return (S_IFIFO); }" >> ${BASE}$$.c
  109. if ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c 1>${NULL} 2>${NULL}; then
  110. true;
  111. else
  112. rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
  113. echo "#include <sys/stat.h>" > ${BASE}$$.c
  114. echo "main() { return (S_IFFIFO); }" >> ${BASE}$$.c
  115. ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c 1>${NULL} 2>${NULL} \
  116. || CFLAGS="${CFLAGS} -DS_IFIFO=S_IFFIFO"
  117. fi
  118. rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
  119. # check that we have uint
  120. echo "#include <stdlib.h>" > ${BASE}$$.c
  121. echo "#include <sys/types.h>" >> ${BASE}$$.c
  122. echo "main() { uint i = 0; return (i); }" >> ${BASE}$$.c
  123. ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c 1>${NULL} 2>${NULL} \
  124. && CFLAGS="${CFLAGS} -DHAVE_uint=1";
  125. rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
  126. # check that we have uint64
  127. HAVE_uint64=0
  128. echo "#include <stdlib.h>" > ${BASE}$$.c
  129. echo "#include <sys/types.h>" >> ${BASE}$$.c
  130. echo "#include <rpc/types.h>" >> ${BASE}$$.c
  131. echo "main() { uint64 i = 0; return (int)(i); }" >> ${BASE}$$.c
  132. ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c 1>${NULL} 2>${NULL} \
  133. && CFLAGS="${CFLAGS} -DHAVE_uint64=1" && HAVE_uint64=1;
  134. rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
  135. # check that we have uint64_t
  136. if [ ${HAVE_uint64} = 0 ]; then
  137. echo "#include <stdlib.h>" > ${BASE}$$.c
  138. echo "#include <sys/types.h>" >> ${BASE}$$.c
  139. echo "main() { uint64_t i = 0; return (int)(i); }" >> ${BASE}$$.c
  140. ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c 1>${NULL} 2>${NULL} \
  141. && CFLAGS="${CFLAGS} -DHAVE_uint64_t=1";
  142. rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
  143. fi
  144. # check that we have int64
  145. HAVE_int64=0
  146. echo "#include <stdlib.h>" > ${BASE}$$.c
  147. echo "#include <sys/types.h>" >> ${BASE}$$.c
  148. echo "#include <rpc/types.h>" >> ${BASE}$$.c
  149. echo "main() { int64 i = 0; return (int)(i); }" >> ${BASE}$$.c
  150. ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c 1>${NULL} 2>${NULL} \
  151. && CFLAGS="${CFLAGS} -DHAVE_int64=1" && HAVE_int64=1;
  152. rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
  153. # check that we have int64_t
  154. if [ ${HAVE_int64} = 0 ]; then
  155. echo "#include <stdlib.h>" > ${BASE}$$.c
  156. echo "#include <sys/types.h>" >> ${BASE}$$.c
  157. echo "main() { int64_t i = 0; return (int)(i); }" >> ${BASE}$$.c
  158. ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c 1>${NULL} 2>${NULL} \
  159. && CFLAGS="${CFLAGS} -DHAVE_int64_t=1";
  160. rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
  161. fi
  162. # check that we have drand48 and srand48
  163. echo "#include <stdlib.h>" > ${BASE}$$.c
  164. echo "main() { srand48(973); return (int)(1.0E9 * drand48()); }" >> ${BASE}$$.c
  165. if ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c 1>${NULL} 2>${NULL}; then
  166. true;
  167. else
  168. rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
  169. echo "#include <stdlib.h>" > ${BASE}$$.c
  170. echo "main() { srand(973); return (10 * rand()) / RAND_MAX; }" >> ${BASE}$$.c
  171. if ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c 1>${NULL} 2>${NULL}; then
  172. CFLAGS="${CFLAGS} -DUSE_RAND"
  173. else
  174. rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
  175. echo "#include <stdlib.h>" > ${BASE}$$.c
  176. echo "main() { srandom(973); return (10 * random()) / RAND_MAX; }" >> ${BASE}$$.c
  177. ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c 1>${NULL} 2>${NULL} \
  178. || CFLAGS="${CFLAGS} -DUSE_RANDOM"
  179. fi
  180. fi
  181. rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
  182. # echo Building for $(TARGET)
  183. if [ ! -d ${BINDIR} ]; then mkdir -p ${BINDIR}; fi
  184. # now go ahead and build everything!
  185. ${MAKE} OS="${OS}" CC="${CC}" CFLAGS="${CFLAGS}" LDLIBS="${LDLIBS}" O="${BINDIR}" $*