2011-10-16 11:41:43 +00:00
|
|
|
#!/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 <<EOF > ${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" \
|
2011-10-18 11:53:45 +00:00
|
|
|
| grep /ref/ \
|
2011-10-16 11:41:43 +00:00
|
|
|
| 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$' || :`
|
2011-10-18 09:09:01 +00:00
|
|
|
|
2011-10-18 11:53:45 +00:00
|
|
|
mkdir -p "${work}/${opi}"
|
|
|
|
cp -p "$o"/*.c "$work/${opi}"
|
2011-10-16 11:41:43 +00:00
|
|
|
|
2011-10-18 11:53:45 +00:00
|
|
|
cp -pr "$implementationdir"/* "$work/${opi}"
|
2011-10-18 09:09:01 +00:00
|
|
|
|
2011-10-18 11:53:45 +00:00
|
|
|
rm ${work}/${opi}/{measure,try}.c
|
2011-10-16 11:41:43 +00:00
|
|
|
|
|
|
|
cp -p MACROS "$work/MACROS"
|
2011-10-18 09:09:01 +00:00
|
|
|
cp -p PROTOTYPES.c "$work/PROTOTYPES.c"
|
|
|
|
cp -p PROTOTYPES.cpp "$work/PROTOTYPES.cpp"
|
|
|
|
cp $implementationdir/api.h "$work"
|
2011-10-16 11:41:43 +00:00
|
|
|
|
|
|
|
(
|
|
|
|
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/"
|
2011-10-18 11:53:45 +00:00
|
|
|
echo "/* CHEESEBURGER ${mop} */"
|
2011-10-16 11:41:43 +00:00
|
|
|
done
|
|
|
|
echo "#define ${o}_PRIMITIVE \"${p}\""
|
|
|
|
echo "#define ${o}_IMPLEMENTATION ${op}_IMPLEMENTATION"
|
|
|
|
echo "#define ${o}_VERSION ${op}_VERSION"
|
|
|
|
echo ""
|
|
|
|
echo "#endif"
|
2011-10-18 11:53:45 +00:00
|
|
|
) > "${opi}/$o.h"
|
2011-10-18 09:09:01 +00:00
|
|
|
|
2011-10-16 11:41:43 +00:00
|
|
|
(
|
|
|
|
echo "#ifndef ${op}_H"
|
|
|
|
echo "#define ${op}_H"
|
|
|
|
echo ""
|
|
|
|
sed 's/[ ]CRYPTO_/ '"${opi}"'_/g' < api.h
|
|
|
|
echo '#ifdef __cplusplus'
|
|
|
|
echo '#include <string>'
|
|
|
|
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/"
|
2011-10-18 11:53:45 +00:00
|
|
|
echo "/* POTATO ${mopi} $opi $op */"
|
2011-10-16 11:41:43 +00:00
|
|
|
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"
|
2011-10-18 11:53:45 +00:00
|
|
|
|
2011-10-16 11:41:43 +00:00
|
|
|
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"
|