aboutsummaryrefslogtreecommitdiff
path: root/bfc.sh
blob: 49c1370e11295dfd74bd7b05f9aa490129a0b88c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env sh

set -e

BFC="./build/bfc"
SRC="$1"

if [ -z "$SRC" ]; then
  echo "usage: $0 <file.bf>" >&2
  exit 1
fi

# silently build compiler if missing
if [ ! -f "$BFC" ]; then
  make -s || {
    echo "build failed" >&2
    exit 1
  }
fi

# compile pipeline
OUT=$(cat "$SRC" | "$BFC")

LDFLAGS="-Os -march=native -mtune=native -flto -fuse-linker-plugin -DNDEBUG -fomit-frame-pointer -nostdlib -nostartfiles -no-pie -fno-stack-protector"

echo "$OUT" > out.c
echo "$OUT" | gcc $LDFLAGS -o ./bf.out -x c -