BaseTools/BinToPcd: Fix Python 2.7.x compatibility issue
[mirror_edk2.git] / DuetPkg / build32.sh
1 #!/bin/bash
2 #
3 # Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
4 # Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
5 #
6 # This program and the accompanying materials
7 # are licensed and made available under the terms and conditions of the BSD License
8 # which accompanies this distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
10 #
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 #
14
15 set -e
16 shopt -s nocasematch
17
18
19 #
20 # Setup workspace if it is not set
21 #
22 if [ -z "$WORKSPACE" ]
23 then
24 echo Initializing workspace
25 if [ ! -e `pwd`/edksetup.sh ]
26 then
27 cd ..
28 fi
29 # This version is for the tools in the BaseTools project.
30 # this assumes svn pulls have the same root dir
31 # export EDK_TOOLS_PATH=`pwd`/../BaseTools
32 # This version is for the tools source in edk2
33 export EDK_TOOLS_PATH=`pwd`/BaseTools
34 echo $EDK_TOOLS_PATH
35 source edksetup.sh BaseTools
36 else
37 echo Building from: $WORKSPACE
38 fi
39
40 PROCESSOR=IA32
41 Processor=Ia32
42
43 #
44 # Pick a default tool type for a given OS
45 #
46 TARGET_TOOLS=MYTOOLS
47 case `uname` in
48 CYGWIN*) echo Cygwin not fully supported yet. ;;
49 Darwin*)
50 Major=$(uname -r | cut -f 1 -d '.')
51 if [[ $Major == 9 ]]
52 then
53 echo DuetPkg requires Snow Leopard or later OS
54 exit 1
55 else
56 TARGET_TOOLS=XCODE32
57 fi
58 ;;
59 Linux*)
60 gcc_version=$(gcc -v 2>&1 | tail -1 | awk '{print $3}')
61 case $gcc_version in
62 4.5.*)
63 TARGET_TOOLS=GCC45
64 ;;
65 4.6.*)
66 TARGET_TOOLS=GCC46
67 ;;
68 4.7.*)
69 TARGET_TOOLS=GCC47
70 ;;
71 4.8.*)
72 TARGET_TOOLS=GCC48
73 ;;
74 4.9.*|4.1[0-9].*|5.*.*)
75 TARGET_TOOLS=GCC49
76 ;;
77 *)
78 TARGET_TOOLS=GCC44
79 ;;
80 esac
81 ;;
82
83 esac
84
85 BUILD_ROOT_ARCH=$WORKSPACE/Build/DuetPkg$PROCESSOR/DEBUG_"$TARGET_TOOLS"/$PROCESSOR
86 FLOPPY_IMAGE=$WORKSPACE/Build/DuetPkg$PROCESSOR/floppy.img
87
88 if [[ ! -f `which build` || ! -f `which GenFv` ]];
89 then
90 # build the tools if they don't yet exist. Bin scheme
91 echo Building tools as they are not in the path
92 make -C $WORKSPACE/BaseTools
93 elif [[ ( -f `which build` || -f `which GenFv` ) && ! -d $EDK_TOOLS_PATH/Source/C/bin ]];
94 then
95 # build the tools if they don't yet exist. BinWrapper scheme
96 echo Building tools no $EDK_TOOLS_PATH/Source/C/bin directory
97 make -C $WORKSPACE/BaseTools
98 else
99 echo using prebuilt tools
100 fi
101
102
103 for arg in "$@"
104 do
105 if [[ $arg == qemu ]]; then
106 shift
107 qemu -fda $FLOPPY_IMAGE -boot a $*
108 exit
109 fi
110
111 if [[ $arg == cleanall ]]; then
112 make -C $WORKSPACE/BaseTools clean
113 build -p $WORKSPACE/DuetPkg/DuetPkg$Processor.dsc -a $PROCESSOR -t $TARGET_TOOLS -n 3 clean
114 exit $?
115 fi
116
117 if [[ $arg == clean ]]; then
118 build -p $WORKSPACE/DuetPkg/DuetPkg$Processor.dsc -a $PROCESSOR -t $TARGET_TOOLS -n 3 clean
119 exit $?
120 fi
121 done
122
123
124 #
125 # Build the edk2 DuetPkg
126 #
127 echo Running edk2 build for DuetPkg$Processor
128 build -p $WORKSPACE/DuetPkg/DuetPkg$Processor.dsc -a $PROCESSOR -t $TARGET_TOOLS -n 3 $*
129 echo Running DuetPkg/CreateBootDisk.sh
130
131 $WORKSPACE/DuetPkg/CreateBootDisk.sh file $FLOPPY_IMAGE /dev/null FAT12 $PROCESSOR
132 exit $?
133