#!/bin/sh # Prepare NaCl source files and include files for compilation with Serval DNA, # possibly using the Android NDK to produce a JNI compatible library. # Android and JNI complicate matters substantially, and prevent us just building # the .a the way that NaCl was intended. The cross compilation environment # will play havoc for a start. # Derived from: # nacl/do # D. J. Bernstein # Public domain. version=`cat version` project=nacl work=nacl-source # and work around bug in GNU sort LANG=C export LANG rm -rf "$work" mkdir -p "$work" # PGS - Create a couple of missing files needed cp randombytes/devurandom.h ${work}/randombytes.h cat < ${work}/crypto_uint32.h #ifndef CRYPTO_UINT32 #define CRYPTO_UINT32 typedef unsigned int crypto_uint32; #endif EOF # loop over operations cat OPERATIONS \ | while read o do [ -d "$o" ] || continue selected='' [ -f "$o/selected" ] && selected=`cat "$o/selected"` # for each operation, loop over primitives ls "$o" \ | sort \ | while read p do [ -d "$o/$p" ] || continue expectedchecksum='' [ -f "$o/$p/checksum" ] && expectedchecksum=`cat "$o/$p/checksum"` op="${o}_${p}" startdate=`date +%Y%m%d` # for each operation primitive abi, loop over implementations find "$o/$p" -follow -name "api.h" \ | grep /ref/ \ | sort \ | while read doth do implementationdir=`dirname $doth` opi=`echo "$implementationdir" | tr ./- ___` echo "=== `date` === $abi $implementationdir" cfiles=`ls "$implementationdir" | grep '\.c$' || :` sfiles=`ls "$implementationdir" | grep '\.[sS]$' || :` cppfiles=`ls "$o" | grep '\.cpp$' || :` mkdir -p "${work}/${opi}" cp -p "$o"/*.c "$work/${opi}" cp -pr "$implementationdir"/* "$work/${opi}" rm ${work}/${opi}/{measure,try}.c cp -p MACROS "$work/MACROS" cp -p PROTOTYPES.c "$work/PROTOTYPES.c" cp -p PROTOTYPES.cpp "$work/PROTOTYPES.cpp" cp $implementationdir/api.h "$work" ( cd "$work" ( echo "#ifndef ${o}_H" echo "#define ${o}_H" echo "" echo "#include \"${op}.h\"" echo "" egrep "${o}"'$|'"${o}"'\(|'"${o}"'_' < MACROS \ | sed "s/$o/$op/" | while read mop do echo "#define ${mop} ${mop}" | sed "s/$op/$o/" echo "/* CHEESEBURGER ${mop} */" done echo "#define ${o}_PRIMITIVE \"${p}\"" echo "#define ${o}_IMPLEMENTATION ${op}_IMPLEMENTATION" echo "#define ${o}_VERSION ${op}_VERSION" echo "" echo "#endif" ) > "${opi}/$o.h" ( echo "#ifndef ${op}_H" echo "#define ${op}_H" echo "" sed 's/[ ]CRYPTO_/ '"${opi}"'_/g' < api.h echo '#ifdef __cplusplus' echo '#include ' egrep "${o}"'$|'"${o}"'\(|'"${o}"'_' < PROTOTYPES.cpp \ | sed "s/$o/$opi/" echo 'extern "C" {' echo '#endif' egrep "${o}"'$|'"${o}"'\(|'"${o}"'_' < PROTOTYPES.c \ | sed "s/$o/$opi/" echo '#ifdef __cplusplus' echo '}' echo '#endif' echo "" egrep "${o}"'$|'"${o}"'\(|'"${o}"'_' < MACROS \ | sed "s/$o/$opi/" | while read mopi do echo "#define ${mopi} ${mopi}" | sed "s/$opi/$op/" echo "/* POTATO ${mopi} $opi $op */" done echo "#define ${op}_IMPLEMENTATION \"${implementationdir}\"" echo "#ifndef ${opi}_VERSION" echo "#define ${opi}_VERSION \"-\"" echo "#endif" echo "#define ${op}_VERSION ${opi}_VERSION" echo "" echo "#endif" ) > "$op.h" cd .. ) done echo "=== `date` === $abi $o/$p measuring" done done # PGS - Remove testing files that we don't care about. rm ${work}/measure.c ${work}/try.c echo "=== `date` === finishing"