serval-dna/nacl/nacl-prepare-sources
Daniel O'Connor 6102dc0ccb - Move nacl-prepare-sources to nacl.
- Alter nacl-prepare-sources to do some of what nacl-jni-prep did.
- Commit nacl.h and sources.mk created by nacl-prepare-sources for
  nacl-20110221. This lets you build the Android version out of the
  box. The native version can still be built after 'do' script is
  run (necessary to build the libraries and create includes).
2012-02-27 12:45:50 +10:30

161 lines
4.1 KiB
Bash
Executable File

#!/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.
if [ ! -e OPERATIONS ]; then
echo "OPERATIONS file not found, are you in the right directory?"
exit 1
fi
project=nacl
work=build_android
# 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" \
| 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.c
rm ${work}/${opi}/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 <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/"
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 -f ${work}/measure.c ${work}/try.c
# DOC - Create nacl.h for lazy programmers
(cd ${work} ; find . -maxdepth 1 -name \*.h -a \! -name mphlr.h -a \! -name nacl.h | sed -Ee 's,\./(.*),#include <\1>,') >${work}/nacl.h
# DOC - Create source list suitable for inclusion into a makefile
echo "NACL_SOURCES := \\" >${work}/sources.mk
(cd ${work} ; find . -mindepth 2 -name \*.c | sed -Ee 's,\./(.*),$(NACL_BASE)/\1,' | sort | xargs echo ) >>${work}/sources.mk
echo "=== `date` === finishing"