Added code to build NaCl in with Serval DNA when doing a JNI build.

This commit is contained in:
gardners 2011-10-16 22:11:43 +10:30
parent 60e391ecd5
commit fff5c5ddae
3 changed files with 209 additions and 0 deletions

42
Android-without-NaCl.mk Normal file
View File

@ -0,0 +1,42 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
client.c \
export.c \
overlay.c \
overlay_abbreviations.c \
overlay_advertise.c \
overlay_buffer.c \
overlay_interface.c \
overlay_packetformats.c \
overlay_payload.c \
overlay_route.c \
responses.c \
srandomdev.c \
batman.c \
dataformats.c \
gateway.c \
packetformats.c \
server.c \
ciphers.c \
dna.c \
hlrdata.c \
peers.c \
simulate.c
LOCAL_MODULE:= dna
LOCAL_CFLAGS += \
-DSHELL -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" \
-DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" \
-DHAVE_LIBC=1 -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 \
-DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 \
-DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_STDIO_H=1 \
-DHAVE_ERRNO_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRINGS_H=1 -DHAVE_UNISTD_H=1 \
-DHAVE_STRING_H=1 -DHAVE_ARPA_INET_H=1 -DHAVE_SYS_SOCKET_H=1 \
-DHAVE_SYS_MMAN_H=1 -DHAVE_SYS_TIME_H=1 -DHAVE_POLL_H=1 -DHAVE_NETDB_H=1
include $(BUILD_EXECUTABLE)

25
nacl-jni-prep Executable file
View File

@ -0,0 +1,25 @@
# Fetch latest version of source as recommended by nacl installation page
[ -e nacl-source.tar.bz2 ] || \
`wget -q -O - http://nacl.cr.yp.to/install.html | grep wget | sed -e 's/^ *//g' -e 's/^wget /wget -O nacl-source.tar.bz2 /'`
# Extract tarball
bzip2 -d nacl-source.tar.bz2
mkdir nacl-source
cd nacl-source
tar xvf ../nacl-source.tar
nacldir=`echo *`
cd ${nacldir}
# Now build the actual compilable sources using our
# hacked version of NaCl's 'do' script
cp ../../nacl-prepare-sources .
chmod 755 nacl-prepare-sources
./nacl-prepare-sources
cd nacl-source
# Now build Android.mk with the extra .c files listed
sources=`echo -n *.c`
cat ../../../Android-without-nacl.mk | sed -e 's/LOCAL_SRC_FILES:= \\/LOCAL_SRC_FILES:= '"${sources}"' \\/' > ../../../Android.mk
ls -1 *.c *.h >../../../nacl-sources.list
mv *.c *.h ../../../

142
nacl-prepare-sources Executable file
View File

@ -0,0 +1,142 @@
#!/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" \
| 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$' || :`
cp -p "$o"/*.c "$work"
cp -p "$o"/*.cpp "$work"
cp -pr "$implementationdir"/* "$work"
cp -p MACROS "$work/MACROS"
cp -p PROTOTYPES.c "$work/compile/PROTOTYPES.c"
cp -p PROTOTYPES.cpp "$work/compile/PROTOTYPES.cpp"
(
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/"
done
echo "#define ${o}_PRIMITIVE \"${p}\""
echo "#define ${o}_IMPLEMENTATION ${op}_IMPLEMENTATION"
echo "#define ${o}_VERSION ${op}_VERSION"
echo ""
echo "#endif"
) > "$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/"
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"