do-openwrt 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #!/bin/sh
  2. set -e
  3. # nacl/do
  4. # D. J. Bernstein
  5. # Public domain.
  6. version=`cat version`
  7. project=nacl
  8. top="`pwd`/build"
  9. bin="$top/bin"
  10. lib="$top/lib"
  11. include="$top/include"
  12. work="$top/work"
  13. # and work around bug in GNU sort
  14. LANG=C
  15. export LANG
  16. rm -rf "$top"
  17. mkdir -p "$top"
  18. mkdir -p "$bin"
  19. mkdir -p "$lib"
  20. mkdir -p "$include"
  21. exec >"$top/log"
  22. exec 2>&1
  23. exec 5>"$top/data"
  24. exec </dev/null
  25. echo "=== `date` === starting"
  26. echo "=== `date` === building inttypes"
  27. for target in int8 int16 int32 int64 uint8 uint16 uint32 uint64; do
  28. (
  29. echo "#ifndef crypto_${target}_h"
  30. echo "#define crypto_${target}_h"
  31. echo ""
  32. echo "#include <stdint.h>"
  33. echo ""
  34. echo "typedef ${target}_t crypto_${target};"
  35. echo ""
  36. echo "#endif"
  37. ) > "$include/crypto_$target.h"
  38. done
  39. echo "=== `date` === building randombytes"
  40. rm -rf "$work"
  41. mkdir -p "$work"
  42. cp -pr randombytes/* "$work"
  43. (
  44. cd "$work"
  45. cp devurandom.c randombytes-impl.c
  46. cp devurandom.h randombytes-impl.h
  47. $CC $CFLAGS -c randombytes-impl.c
  48. mkdir -p lib
  49. mv randombytes-impl.o lib/randombytes.o
  50. mkdir -p include
  51. mv randombytes-impl.h include/randombytes.h
  52. )
  53. cp -pr "$work"/lib/* "$lib"
  54. cp -pr "$work"/include/* "$include"
  55. rm -rf "$work"
  56. mkdir -p "$work"
  57. echo 'void crypto_'"$project"'_base(void) { ; }' > "$work/${project}_base.c"
  58. ( cd "$work" && $CC $CFLAGS -c ${project}_base.c )
  59. $AR cr "$lib/lib${project}.a" "$work/${project}_base.o"
  60. ( $RANLIB "$lib/lib${project}.a" || exit 0 )
  61. # loop over operations
  62. cat OPERATIONS \
  63. | while read o
  64. do
  65. [ -d "$o" ] || continue
  66. # for each operation, loop over primitives
  67. ls "$o" \
  68. | sort \
  69. | while read p
  70. do
  71. [ -d "$o/$p" ] || continue
  72. op="${o}_${p}"
  73. startdate=`date +%Y%m%d`
  74. echo "=== `date` === $o/$p"
  75. rm -rf "$work"
  76. mkdir -p "$work"
  77. if [ -d "$o/$p/ref" ]; then
  78. implementationdir="$o/$p/ref"
  79. else
  80. implementationdir="$o/$p/portable"
  81. fi
  82. opi=`echo "$implementationdir" | tr ./- ___`
  83. echo "=== `date` === $implementationdir"
  84. cfiles=`ls "$implementationdir" | grep '\.c$' || :`
  85. sfiles=`ls "$implementationdir" | grep '\.[sS]$' || :`
  86. cp -p "$o"/*.c "$work"
  87. cp -pr "$implementationdir"/* "$work"
  88. cp -p MACROS "$work/MACROS"
  89. cp -p PROTOTYPES.c "$work/PROTOTYPES.c"
  90. (
  91. cd "$work"
  92. (
  93. echo "#ifndef ${o}_H"
  94. echo "#define ${o}_H"
  95. echo ""
  96. echo "#include \"${op}.h\""
  97. echo ""
  98. egrep "${o}"'$|'"${o}"'\(|'"${o}"'_' < MACROS \
  99. | sed "s/$o/$op/" | while read mop
  100. do
  101. echo "#define ${mop} ${mop}" | sed "s/$op/$o/"
  102. done
  103. echo "#define ${o}_PRIMITIVE \"${p}\""
  104. echo "#define ${o}_IMPLEMENTATION ${op}_IMPLEMENTATION"
  105. echo "#define ${o}_VERSION ${op}_VERSION"
  106. echo ""
  107. echo "#endif"
  108. ) > "$o.h"
  109. (
  110. echo "#ifndef ${op}_H"
  111. echo "#define ${op}_H"
  112. echo ""
  113. sed 's/[ ]CRYPTO_/ '"${opi}"'_/g' < api.h
  114. echo '#ifdef __cplusplus'
  115. #echo '#include <string>'
  116. #egrep "${o}"'$|'"${o}"'\(|'"${o}"'_' < PROTOTYPES.cpp \
  117. # | sed "s/$o/$opi/"
  118. echo 'extern "C" {'
  119. echo '#endif'
  120. egrep "${o}"'$|'"${o}"'\(|'"${o}"'_' < PROTOTYPES.c \
  121. | sed "s/$o/$opi/"
  122. echo '#ifdef __cplusplus'
  123. echo '}'
  124. echo '#endif'
  125. echo ""
  126. egrep "${o}"'$|'"${o}"'\(|'"${o}"'_' < MACROS \
  127. | sed "s/$o/$opi/" | while read mopi
  128. do
  129. echo "#define ${mopi} ${mopi}" | sed "s/$opi/$op/"
  130. done
  131. echo "#define ${op}_IMPLEMENTATION \"${implementationdir}\""
  132. echo "#ifndef ${opi}_VERSION"
  133. echo "#define ${opi}_VERSION \"-\""
  134. echo "#endif"
  135. echo "#define ${op}_VERSION ${opi}_VERSION"
  136. echo ""
  137. echo "#endif"
  138. ) > "$op.h"
  139. echo "=== `date` === $implementationdir $CC $CFLAGS"
  140. for f in $cfiles $sfiles
  141. do
  142. ok=1
  143. $CC $CFLAGS \
  144. -I. -I"$include" \
  145. -c "$f" >errors 2>&1 || ok=0
  146. ( if [ `wc -l < errors` -lt 25 ]
  147. then
  148. cat errors
  149. else
  150. head errors
  151. echo ...
  152. tail errors
  153. fi
  154. ) \
  155. | while read err
  156. do
  157. echo "$version $startdate $o $p fromcompiler $implementationdir $f $err" >&5
  158. done
  159. [ "$ok" = 1 ]
  160. done
  161. for f in *.o
  162. do
  163. mv "$f" "${opi}-$f"
  164. done
  165. )
  166. echo "=== `date` === $implementationdir $CC $CFLAGS finishing"
  167. $AR cr "$lib/lib${project}.a" "$work"/*.o \
  168. && ( $RANLIB "$lib/lib${project}.a" || exit 0 ) \
  169. && cp -p "$work/$op.h" "$include/$op.h" \
  170. && [ -f "$o/$p/selected" ] \
  171. && cp -p "$work/$o.h" "$include/$o.h" \
  172. || :
  173. done
  174. done
  175. echo "=== `date` === finishing"