-#!/bin/sh
+#!/bin/bash
-TOPDIR="$(cd $(dirname $0); pwd)"
+TOPDIR="$(cd $(dirname $(which $0)); pwd)"
+echo "TOP: $TOPDIR"
+TMP_CONF="$(mktemp)"
PKGMK=$TOPDIR/src/pkgmk
PKGMK_CONF=$TOPDIR/src/pkgmk.conf
+PKGMK_ARGS=""
+PKGMK_OPTIMIZE=""
-$PKGMK -cf $PKGMK_CONF $@
+while [ "$1" ]; do
+ echo "arg: $1"
+ case $1 in
+ -o) PKGMK_OPTIMIZE="$2" ;;
+ *) PKGMK_ARGS="$PKGMK_ARGS $1" ;;
+ esac
+ shift
+done
+
+if [ ! -z "$PKGMK_OPTIMIZE" ]; then
+ _cflags="$(grep "^${PKGMK_OPTIMIZE}_CFLAGS=" $PKGMK_CONF | cut -d'=' -f2- | sed 's|"||g')"
+ if [ ! -z "$_cflags" ]; then
+ sed '/_CFLAGS=/d' $PKGMK_CONF | sed "s|CFLAGS=.*|CFLAGS=\"$_cflags\"|" > $TMP_CONF
+ PKGMK_CONF="$TMP_CONF"
+ else
+ echo "Error, invalid optimization: '$PKGMK_OPTIMIZE'"
+ exit 1
+ fi
+fi
+
+echo "$PKGMK -cf $PKGMK_CONF $PKGMK_ARGS"
+
+#rm -f $TMP_CONF
# End of file
export STRIP="$CTARGET-strip"
export CFLAGS="-O2 -pipe"
-export CXXFLAGS="-O2 -pipe"
+export CXXFLAGS="$CFLAGS"
+
+arm9tdmi_CFLAGS="-O2 -pipe -march=armv4 -mtune=arm9tdmi"
+armv5te_CFLAGS="-O2 -pipe -march=armv5te"
+strongarm_CFLAGS="-O2 -pipe -march=armv4 -mtune=strongarm"
+xscale_CFLAGS="-O2 -pipe -march=armv5te -mtune=xscale"
STRIP_CMD="$STRIP"