#!/bin/sh -e

okabi | (
  while read abi
  do
    (
      echo 'int8 int8_t'
      echo 'int16 int16_t'
      echo 'int32 int32_t'
      echo 'int64 int64_t'
      echo 'uint8 uint8_t'
      echo 'uint16 uint16_t'
      echo 'uint32 uint32_t'
      echo 'uint64 uint64_t'
    ) | (
      while read target source
      do
        okc-$abi | (
          while read c
	  do
            [ -f include/$abi/crypto_$target.h ] && continue
            echo "=== `date` === $abi trying $source as $target under $c..." >&2
            rm -f crypto_$target crypto_$target.h
            (
              echo "#ifndef crypto_${target}_h"
              echo "#define crypto_${target}_h"
              echo ""
              echo "#include <stdint.h>"
              echo ""
              echo "typedef ${source} crypto_${target};"
              echo ""
              echo "#endif"
            ) > crypto_$target.h
            $c -o crypto_$target crypto_$target.c || continue
            mkdir -p include/$abi
            cp crypto_$target.h include/$abi/crypto_$target.h
	  done
	)
      done
    )
  done
)
