#!/bin/sh

CFLAGS="-Wall -O3 `gcccpuopt 2>/dev/null`"

echo "getline -DGETLINE
linebuffer_fgets_locked -D_REENTRANT
linebuffer_fgets_NoNulls -D_REENTRANT -DNoNULLs
linebuffer_fgets_unlocked -DFORCE_FGETS
linebuffer_fgets_unlocked_NoNulls -DFORCE_FGETS -DNoNULLs
linebuffer_getc_locked -DFORCE_GETC
linebuffer_getc_unlocked" |

while read bin def; do
    echo "*** Building $bin ***"
    gcc $CFLAGS -c linebuffer.c $def
    gcc $CFLAGS c.c -o $bin linebuffer.o $def
    strip $bin
done

echo "*** Building cpp ***"
g++ $CFLAGS cpp.cpp -o cpp

#Note the separate getline.c has the same performance as the
#version above integrated into linebuffer, and is only present for illustration
#gcc $CFLAGS ../getline.c -o getline
