From 7a80680a1d3e973bd210415c1b170cdad7a532fa Mon Sep 17 00:00:00 2001
From: Ryan Harkin <ryan.harkin@linaro.org>
Date: Mon, 11 Feb 2013 08:10:43 +0000
Subject: [PATCH] panda: build.sh: change RELEASE/DEBUG param handling

Before this patch, build.sh can be called thus:
  ./build.sh
  ./build.sh -b DEBUG
  ./build.sh RELEASE

This patch simplifies the way you pass the debug/release parameter into build.sh so that build scripts can simply pass DEBUG or RELEASE, without having to create a special case to add the "-b".

Eg.
  ./build.sh
  ./build.sh DEBUG
  ./build.sh RELEASE

Signed-off-by: Ryan Harkin <ryan.harkin@linaro.org>
---
 PandaBoardPkg/build.sh |   39 +++++++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 10 deletions(-)

diff --git a/PandaBoardPkg/build.sh b/PandaBoardPkg/build.sh
index 8002eac..55180e4 100755
--- a/PandaBoardPkg/build.sh
+++ b/PandaBoardPkg/build.sh
@@ -87,10 +87,34 @@ fi
 TARGET=DEBUG
 for arg in "$@"
 do
-  if [[ $arg == RELEASE ]]; 
-  then
-    TARGET=RELEASE
-  fi
+  case $arg in
+    "RELEASE")
+      if [ "$set_debug" = "yes" ]
+      then
+        echo "ERROR: both RELEASE and DEBUG have been defined on the command line"
+        exit
+      fi
+      TARGET=RELEASE
+      if [ "$set_release" == "" ] # trap someone setting RELEASE more than once on the cmdline
+      then
+        BUILD_PARAMS="$BUILD_PARAMS -D DEBUG_TARGET=RELEASE"
+      fi
+      set_release="yes"
+      ;;
+    "DEBUG")
+      if [ "$set_release" = "yes" ]
+      then
+        echo "ERROR: both RELEASE and DEBUG have been defined on the command line"
+        exit
+      fi
+      TARGET=DEBUG
+      set_debug="yes"
+      ;;
+    *)
+      BUILD_PARAMS="$BUILD_PARAMS $arg"
+      ;;
+  esac
+
 done
 
 BUILD_ROOT=$WORKSPACE/Build/PandaBoard/"$TARGET"_"$TARGET_TOOLS"
@@ -109,12 +133,7 @@ fi
 #
 # Build the edk2 PandaBoard code
 #
-if [[ $TARGET == RELEASE ]]; then
-  build -p $WORKSPACE/PandaBoardPkg/PandaBoardPkg.dsc -a ARM -t $TARGET_TOOLS -b $TARGET -D DEBUG_TARGET=RELEASE ${2:-} ${3:-} ${4:-} ${5:-} ${6:-} ${7:-} ${8:-}
-else
-  build -p ${WORKSPACE:-}/PandaBoardPkg/PandaBoardPkg.dsc -a ARM -t $TARGET_TOOLS -b $TARGET ${1:-} ${2:-} ${3:-} ${4:-} ${5:-} ${6:-} ${7:-} ${8:-}
-fi
-
+build -p $WORKSPACE/PandaBoardPkg/PandaBoardPkg.dsc -a ARM -t $TARGET_TOOLS -b $TARGET $BUILD_PARAMS
 
 for arg in "$@"
 do
-- 
1.7.9.5

