#!/bin/bash
-flags=()
+set -e
-sdk=/Developer/SDKs/MacOSX10.4u.sdk
-if [[ -e $sdk ]]; then
- flags+=(-mmacosx-version-min=10.4 -isysroot "$sdk")
+if which xcrun &>/dev/null; then
+ flags=(xcrun -sdk macosx g++)
+ flags+=(-mmacosx-version-min=10.4)
+
+ for arch in i386 x86_64; do
+ flags+=(-arch "${arch}")
+ done
+else
+ flags=(g++)
fi
-g++ -arch ppc -arch i386 -arch x86_64 "${flags[@]}" -o ldid ldid.cpp -I. -x c lookup2.c sha1.c
+flags+=(-I.)
+
+set -x
+"${flags[@]}" -c -std=c++11 -o ldid.o ldid.cpp
+"${flags[@]}" -o ldid ldid.o -x c lookup2.c -x c sha1.c