#! /usr/bin/env bash

# This script is used on macOS to workaround two problems:
#
# 1. The preprocessor in clang does not preserve layout, so we use the
#    preprocessor in gcc instead.
# 2. There seems to be a problem with the -optP option with ghc>=8.10.3,
#    so we can no longer use e.g. 'ghc -pgmP cpp-11 -optP -traditional'

# To install gcc, install Homebrew (see https://brew.sh),
# then run 'brew install gcc'

cpp=cpp
case `uname` in
    FreeBSD) cpp=cpp13 ;;
    OpenBSD) cpp=ecpp ;;
    Darwin)
	# Since gcc is an alias for clang on macOS, gcc proper is only
	# available in the path with a version suffix, so we need to
	# detect which version of gcc is installed.
	for v in $(seq 6 15) ; do
	    if which cpp-$v >/dev/null ; then
		cpp=cpp-$v
	    fi
	done
	;;
esac

$cpp -traditional "$@"
