blob: 4b6ed4d1403f5b20202dcbb517c29eb8f81d285d [file] [log] [blame]
BigBrother198436570452013-11-09 22:10:23 +01001#!/bin/bash
2
xilence2210eac12912013-12-14 15:01:14 +08003# Version 2.0.4, Adapted for AOSPAL.
4
5if [ "pa$1" == "pa" ]
6then
7 echo "Usage: './mk [Device] {Variable}'"
8 echo " Device - your device name"
9 echo " Variable - functions"
10 echo " fix :start build without any cleanning for fix build"
11 echo " clean :run 'make installclean' before build"
12 echo " sync :run 'repo sync' before build"
13 echo " "
14 exit 0
15fi
BigBrother198436570452013-11-09 22:10:23 +010016
17# We don't allow scrollback buffer
18echo -e '\0033\0143'
19clear
20
21# Get current path
22DIR="$(cd `dirname $0`; pwd)"
23OUT="$(readlink $DIR/out)"
24[ -z "${OUT}" ] && OUT="${DIR}/out"
25
26# Prepare output customization commands
27red=$(tput setaf 1) # red
28grn=$(tput setaf 2) # green
29blu=$(tput setaf 4) # blue
30cya=$(tput setaf 6) # cyan
31txtbld=$(tput bold) # Bold
32bldred=${txtbld}$(tput setaf 1) # red
33bldgrn=${txtbld}$(tput setaf 2) # green
34bldblu=${txtbld}$(tput setaf 4) # blue
35bldcya=${txtbld}$(tput setaf 6) # cyan
36txtrst=$(tput sgr0) # Reset
37
38# Local defaults, can be overriden by environment
39: ${PREFS_FROM_SOURCE:="false"}
40: ${THREADS:="$(cat /proc/cpuinfo | grep "^processor" | wc -l)"}
41
42# If there is more than one jdk installed, use latest 6.x
43if [ "`update-alternatives --list javac | wc -l`" -gt 1 ]; then
44 JDK6=$(dirname `update-alternatives --list javac | grep "\-6\-"` | tail -n1)
45 JRE6=$(dirname ${JDK6}/../jre/bin/java)
46 export PATH=${JDK6}:${JRE6}:$PATH
47fi
48JVER=$(javac -version 2>&1 | head -n1 | cut -f2 -d' ')
49
50# Import command line parameters
xilence2210eac12912013-12-14 15:01:14 +080051THREADS="4"
BigBrother198436570452013-11-09 22:10:23 +010052DEVICE="$1"
BigBrother198436570452013-11-09 22:10:23 +010053
54# Get build version
Paul Beeler761c43c2014-03-18 03:10:27 -060055PA_MAJOR=$(cat $DIR/vendor/pa/vendor.mk | grep 'ROM_VERSION_MAJOR := *' | sed 's/ROM_VERSION_MAJOR := //g')
56PA_MINOR=$(cat $DIR/vendor/pa/vendor.mk | grep 'ROM_VERSION_MINOR := *' | sed 's/ROM_VERSION_MINOR := //g')
57PA_MAINTENANCE=$(cat $DIR/vendor/pa/vendor.mk | grep 'ROM_VERSION_MAINTENANCE := *' | sed 's/ROM_VERSION_MAINTENANCE := //g')
58PA_TAG=$(cat $DIR/vendor/pa/vendor.mk | grep 'ROM_VERSION_TAG := *' | sed 's/ROM_VERSION_TAG := //g')
BigBrother198436570452013-11-09 22:10:23 +010059
Paul Beeler761c43c2014-03-18 03:10:27 -060060PSD_MAJOR=$(cat $DIR/vendor/psd/vendor.mk | grep 'PSD_VERSION_MAJOR := *' | sed 's/PSD_VERSION_MAJOR := //g')
61PSD_MINOR=$(cat $DIR/vendor/psd/vendor.mk | grep 'PSD_VERSION_MINOR := *' | sed 's/PSD_VERSION_MINOR := //g')
62PSD_MAINTENANCE=$(cat $DIR/vendor/psd/vendor.mk | grep 'PSD_VERSION_MAINTENANCE := *' | sed 's/PSD_VERSION_MAINTENANCE := //g')
TheMrcool212d1a19db2014-05-17 18:33:58 +080063PSD_TAG=$(cat $DIR/vendor/psd/vendor.mk | grep 'PSD_TYPE := *' | sed 's/PSD_TYPE := //g')
Paul Beeler761c43c2014-03-18 03:10:27 -060064
65if [ -n "$PA_TAG" ]; then
Yamil Ghazi38b55c82014-01-13 06:14:54 -060066 VERSION=$MAJOR.$MINOR$MAINTENANCE-$TAG
67else
68 VERSION=$MAJOR.$MINOR$MAINTENANCE
69fi
BigBrother198436570452013-11-09 22:10:23 +010070
Paul Beeler761c43c2014-03-18 03:10:27 -060071if [ -n "$PSD_TAG" ]; then
TheMrcool212d1a19db2014-05-17 18:33:58 +080072 PSD_VERSION=$PSD_MAINTENANCE-$PSD_TAG-$PSD_MAJOR.$PSD_MINOR
Paul Beeler761c43c2014-03-18 03:10:27 -060073else
TheMrcool212d1a19db2014-05-17 18:33:58 +080074 PSD_VERSION=$PSD_MAINTENANCE-$PSD_MAJOR.$PSD_MINOR
Paul Beeler761c43c2014-03-18 03:10:27 -060075fi
BigBrother198436570452013-11-09 22:10:23 +010076
77# Get start time
78res1=$(date +%s.%N)
79
TheMrcool2127c586cd2014-05-17 14:13:53 +080080echo -e "${cya}Building ${bldcya}AOSPAL $PSD_TAG $PSD_MAJOR.$PSD_MINOR for $DEVICE ${txtrst}";
BigBrother198436570452013-11-09 22:10:23 +010081echo -e "${bldgrn}Start time: $(date) ${txtrst}"
82
83# Decide what command to execute
84case "$EXTRAS" in
85 threads)
86 echo -e "${bldblu}Please enter desired building/syncing threads number followed by [ENTER]${txtrst}"
87 read threads
88 THREADS=$threads
89 ;;
90 clean|cclean)
91 echo -e "${bldblu}Cleaning intermediates and output files${txtrst}"
92 export CLEAN_BUILD="true"
93 [ -d "${DIR}/out" ] && rm -Rf ${DIR}/out/*
94 ;;
95esac
96
97echo -e ""
98
Yamil Ghazi676e8352014-01-14 03:23:30 -060099export DEVICE=$DEVICE
100
D4rKn3sSyS3c87e452013-11-10 08:58:19 -0500101# Fetch latest sources
BigBrother198436570452013-11-09 22:10:23 +0100102if [ "$SYNC" == "true" ]; then
103 echo -e ""
104 echo -e "${bldblu}Fetching latest sources${txtrst}"
105 repo sync -j"$THREADS"
106 echo -e ""
107fi
108
109if [ ! -r "${DIR}/out/versions_checked.mk" ] && [ -n "$(java -version 2>&1 | grep -i openjdk)" ]; then
110 echo -e "${bldcya}Your java version still not checked and is candidate to fail, masquerading.${txtrst}"
111 JAVA_VERSION="java_version=${JVER}"
112fi
113
xilence2210eac12912013-12-14 15:01:14 +0800114makeme=0
BigBrother198436570452013-11-09 22:10:23 +0100115if [ -n "${INTERACTIVE}" ]; then
116 echo -e "${bldblu}Dropping to interactive shell${txtrst}"
117 echo -en "${bldblu}Remeber to lunch you device:"
118 if [ "${VENDOR}" == "pa" ]; then
119 echo -e "[${bldgrn}lunch pa_$DEVICE-userdebug${bldblu}]${txtrst}"
120 else
121 echo -e "[${bldgrn}lunch full_$DEVICE-userdebug${bldblu}]${txtrst}"
122 fi
123 bash --init-file build/envsetup.sh -i
124else
125 # Setup environment
126 echo -e ""
127 echo -e "${bldblu}Setting up environment${txtrst}"
xilence2210eac12912013-12-14 15:01:14 +0800128 export USE_CCACHE=1
129 export CCACHE_DIR=~/.ccache
130 # set ccache due to your disk space,set it at your own risk
131 prebuilts/misc/linux-x86/ccache/ccache -M 15G
BigBrother198436570452013-11-09 22:10:23 +0100132 . build/envsetup.sh
133 echo -e ""
134
135 # lunch/brunch device
136 echo -e "${bldblu}Lunching device [$DEVICE] ${cya}(Includes dependencies sync)${txtrst}"
137 export PREFS_FROM_SOURCE
138 lunch "pa_$DEVICE-userdebug";
Paul Beeler761c43c2014-03-18 03:10:27 -0600139
xilence2210eac12912013-12-14 15:01:14 +0800140 makeme=1
141fi
BigBrother198436570452013-11-09 22:10:23 +0100142
xilence2210eac12912013-12-14 15:01:14 +0800143# Decide what command to execute
xilence2210c33072f2013-12-18 13:05:35 +0800144fix_count=0
xilence2210eac12912013-12-14 15:01:14 +0800145for var in $* ; do
146if [ "$var" == "sync" ]
147then
148 echo -e "${bldblu}Fetching latest sources ${txtrst}"
149 repo sync
150 echo -e ""
151elif [ "$var" == "clean" ]
152then
153 echo -e "${bldblu}Clearing previous build info ${txtrst}"
154 mka installclean
155elif [ "$var" == "allclean" ]
156then
157 echo -e "${bldblu}Clearing build path ${txtrst}"
158 mka clean
159elif [ "$var" == "fix" ]
160then
161 echo -e "skip for remove build.prop"
162 fix_count=1
163else
164 echo -e "running..."
165fi
166done
167
168if [ "$fix_count" == "0" ]
169then
xilence2210c33072f2013-12-18 13:05:35 +0800170 echo -e "removing build.prop..."
171 rm $OUT/system/build.prop
xilence2210eac12912013-12-14 15:01:14 +0800172fi
173
174echo -e ""
175
176if [ "$makeme" == "1" ]
177then
BigBrother198436570452013-11-09 22:10:23 +0100178 echo -e "${bldblu}Starting compilation${txtrst}"
179 mka bacon
180fi
181echo -e ""
182
183# Get elapsed time
184res2=$(date +%s.%N)
185echo -e "${bldgrn}Total time elapsed: ${txtrst}${grn}$(echo "($res2 - $res1) / 60"|bc ) minutes ($(echo "$res2 - $res1"|bc ) seconds)${txtrst}"