#!/bin/sh -e

okabi | (
  while read abi
  do
    (
      echo 'int8 signed char'
      echo 'int16 short'
      echo 'int32 int'
      echo 'int32 long'
      echo 'int64 long long'
      echo 'int64 long'
      echo 'int64 int __attribute__((__mode__(__DI__)))'
      echo 'uint8 unsigned char'
      echo 'uint16 unsigned short'
      echo 'uint32 unsigned int'
      echo 'uint32 unsigned long'
      echo 'uint64 unsigned long long'
      echo 'uint64 unsigned long'
      echo 'uint64 unsigned int __attribute__((__mode__(__DI__)))'
    ) | (
      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 "typedef ${source} crypto_${target};"
              echo ""
              echo "#endif"
            ) > crypto_$target.h
            $c -o crypto_$target crypto_$target.c || continue
            ./crypto_$target || continue
            mkdir -p include/$abi
            cp crypto_$target.h include/$abi/crypto_$target.h
	  done
	)
      done
    )
  done
)
