#!/bin/bash # Fetch latest version of source as recommended by nacl installation page if [ ! -e nacl-source.tar.bz2 ]; then `wget -q -O - http://nacl.cr.yp.to/install.html | grep wget | sed -e 's/^ *//g' -e 's/^wget /wget -q -O nacl-source.tar.bz2 /'` fi # Extract tarball mkdir -p nacl-source arlist=`find . -name libnacl.a` arcount=`echo $arlist | wc -w` if [ $arcount -eq 0 ]; then cd nacl-source bzip2 -d ../nacl-source.tar | tar xvf - nacldir=`echo *` cd ${nacldir} ./do cd .. fi # Test which one works for us include=`find . -name crypto_box.h | head -1` cat <test.c #include #include "${include}" #include #include #include #include /* it's really stupid that there isn't a syscall for this */ static int fd = -1; void randombytes(unsigned char *x,unsigned long long xlen) { int i; if (fd == -1) { for (;;) { fd = open("/dev/urandom",O_RDONLY); if (fd != -1) break; sleep(1); } } while (xlen > 0) { if (xlen < 1048576) i = xlen; else i = 1048576; i = read(fd,x,i); if (i < 1) { sleep(1); continue; } x += i; xlen -= i; } } unsigned char pk[crypto_box_PUBLICKEYBYTES]; unsigned char sk[crypto_box_SECRETKEYBYTES]; int main(int argc,char **argv) { crypto_box_keypair(pk,sk); printf("The compilation worked.\n"); } EOF for ar in $arlist do if [ -e test ]; then rm test fi gcc -o test test.c $ar >/dev/null 2>&1 if [ -e test ]; then naclbuilddir=`echo $ar | sed -e s,/libnacl.a,,` echo "${naclbuilddir}" > naclbuilddir.txt fi done if [ -e test ]; then rm test fi includedir=`cat naclbuilddir.txt | sed s,/lib/,/include/,` ls -1 ${includedir} | sed -e 's,^,#include "'"${includedir}"'/,' -e 's,$,",' > nacl.h