#!/bin/sh

set -eu

. /usr/share/geordi/_functions
. "${CONFIG_DIR}/compile-config"

info "Compiling prelude"


TEMPDIR=$(mktemp -d)

debug "Changing to temporary directory"
OLD_DIR="$(pwd)"
cd "${TEMPDIR}"

debug "Copying prelude to temporary directory"
cp "${PRELUDE_DIR}"/* .

debug "Compiling prelude"
${GXX} ${COMPILE_FLAGS} -c *.cpp

debug "Reverting to previous directory"
cd ${OLD_DIR}

debug "Linking prelude"
rm -f "${RT}/prelude.a"
ar -rsc "${RT}/prelude.a" "${TEMPDIR}"/*.o

debug "Pre-compiling headers"
${GXX} ${COMPILE_FLAGS} -c -x c++-header "${PRELUDE_DIR}"/prelude.hpp -o "${RT}"/prelude.hpp.gch

debug "Removing temporary dir"
rm -rf "${TEMPDIR}"
