• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Shabbypenguin

Extreme Android User
Mar 28, 2011
5,381
5,072
37
Here is some of teh scripts i use to build stuff. some of it may be fairly advanced, for those that do understand it and learn from it can adapt it to what they need :)

My CM/AOKP/BB build script
[HIGH]
#############################################################################
###### Compile Script - Created by Shabbypenguin, improved by many ##########
#############################################################################

#!/bin/bash
[ $# -eq 0 ] && { echo "Usage:
$0 Device"; exit 1; }
# Lets set some exports
# Goo Exports
DEV=Shabbypenguin
PRODUCT=$1
ROM=CM10
LROM=${ROM,,}
VERSION=$(date +%Y%m%d)
FOLDER=$PRODUCT"-"$ROM
# Build Exports
THREADS=$(expr 2 + $(grep processor /proc/cpuinfo | wc -l))
MAKE="make -j${THREADS}"
DIR=~/android/$ROM
DONE=$DIR/done
TEMP=$DONE/TEMP
LOG=$DONE/logging.txt
OUT=$DIR/out/target/product/$PRODUCT
GOOUPLOAD=Shabbypenguin@upload.goo.im:public_html/$FOLDER
WEBSITE=u6820@shabbypenguin.com:OUDstuff/Samsung/Metro/R530M/$ROM
SIGN=~/bin/testsign.jar
export ANDROID_JAVA_HOME=/opt/sun-jdk-1.6.0.39/
export TZ=":America/New_York"
NOW=`date +%m-%d`
ZIP=$OUT/*"unofficial"*".zip"

# Make sure things are in order
rm -rf $DONE
[ -d "$TEMP" ] || mkdir -p "$TEMP"
exec > >(tee $DONE/buildlog.txt) 2>&1
echo "Staring at" > $LOG && date >> $LOG && echo "" >> $LOG

# Always clean up your messes
$MAKE installclean
$MAKE clobber

# Start the good stuff
echo "gettin good" >> $LOG && date >> $LOG && echo "" >> $LOG

# Get things up to date :)
repo sync -j$THREADS
echo "this is how long it takes to repo sync" >> $LOG && date >> $LOG && echo "" >> $LOG

# Lets start buildin
. build/envsetup.sh
brunch $PRODUCT
echo "this is how long it takes to compile" >> $LOG && date >> $LOG && echo "" >> $LOG

# Adding goo's
cp $ZIP $DONE/$ROM"-Copied.zip"
unzip $DONE/*.zip -d $TEMP
rm $DONE/*-Copied.zip
echo -e "\\n" >> $TEMP/system/build.prop
echo "# Goo-Manager Info" >> $TEMP/system/build.prop
echo "ro.goo.developerid="$DEV >> $TEMP/system/build.prop
echo "ro.goo.rom="$ROM >> $TEMP/system/build.prop
echo "ro.goo.version="$VERSION >> $TEMP/system/build.prop
echo "ro.goo.board="$PRODUCT >> $TEMP/system/build.prop
echo -e "\\n" >> $TEMP/system/build.prop
echo -e "\\n" >> $TEMP/system/build.prop

# Zippin again
cd $TEMP
zip -r $TEMP/$ROM".zip" *
java -classpath $SIGN testsign $ROM".zip" $TEMP/$ROM"_signed.zip"
cp $TEMP/$ROM"_signed.zip" $DONE/$ROM"_signed.zip"

# Upload maybe?
chmod 744 $DONE/*
for file in $DONE/*zip; do newfile=$NOW"-"$ROM"-"$PRODUCT"-KANG.zip"; mv "$file" "$DONE/$newfile"; md5sum $DONE/$newfile > $DONE/$newfile".md5sum"; done
scp -P2222 $DONE/$newfile* $GOOUPLOAD
scp -P22 $DONE/$newfile* $WEBSITE
echo "this is how long it takes to upload" >> $LOG && date >> $LOG
[/HIGH]

Here is my kernel building script for the SGS3:

[HIGH]
#!/bin/bash

# This is my usage information
[ $# -eq 0 ] && { echo "Usage:
$0 Kernel-name [Stock,CM,CM101]"; exit 1; }

# These setup our build enviroment
THREADS=$(expr 2 + $(grep processor /proc/cpuinfo | wc -l))
MAKE="make -j${THREADS}"
ARCH="ARCH=arm"
CROSS="CROSS_COMPILE=~/android/CM10/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-"

# Setup our directories now
DIR=~/android/Kernels
KERNEL=$DIR/SGH-Krait
PACK=$KERNEL/package
OUT=$KERNEL/arch/arm/boot
TOOLS=$DIR/tools

# Set our Ramdisk locations
STOCK=$DIR/Ramdisks/d2mtr
CM=$DIR/Ramdisks/d2mtr-CM
CM101=$DIR/Ramdisks/d2mtr-CM10-1

# These are for mkbootimg
PAGE=2048
BASE=0x80200000
RAMADDR=0x81500000
CMDLINE='"androidboot.hardware=qcom user_debug=31 zcache"'

# These are extra variables designed to make things nicer/easier
UPDATER=$TOOLS/Updater-Scripts/d2
MODULES=$UPDATER/system/lib/modules
KERNELNAME=$1
KBUILD_BUILD_VERSION=$1
export KBUILD_BUILD_VERSION

# -----------------------------------------------------------------------------------------------
# Dont mess with below here unless you know what you are doing
# -----------------------------------------------------------------------------------------------

export USE_CCACHE=1
export $ARCH
export $CROSS

# This cleans out crud and makes new config
$MAKE clean
$MAKE mrproper
rm -rf $MODULES
rm -rf $PACK
[ -d "$PACK" ] || mkdir "$PACK"
[ -d "$MODULES" ] || mkdir -p "$MODULES"
exec > >(tee $PACK/buildlog.txt) 2>&1
$MAKE $DEFCONFIG

# Finally making the kernel
$MAKE zImage
$MAKE modules

# These move files to easier locations
find -name '*.ko' -exec cp -av {} $MODULES/ \;

# -----------------------------------------------------------------------------------------------
# This part packs the img up :)
# In order for this part to work you need the mkbootimg tools
# -----------------------------------------------------------------------------------------------

# This will base ramdisks location off $2
if [ $2 == "Stock" ];
then
RAMDISK=$STOCK
else
if [ $2 == "CM" ];
then
RAMDISK=$CM
else
if [ $2 == "CM101" ];
then
RAMDISK=$CM101
fi
fi
fi

cd $PACK
cp $OUT/zImage $PACK
$TOOLS/mkbootfs $RAMDISK | gzip > $PACK/ramdisk.gz
$TOOLS/mkbootimg --cmdline "$CMDLINE" --kernel $PACK/zImage --ramdisk $PACK/ramdisk.gz --pagesize $PAGE --base $BASE --ramdiskaddr $RAMADDR -o $PACK/boot.img
rm -rf ramdisk.gz
rm -rf zImage
cp -R $UPDATER/* $PACK
zip -r $KERNELNAME"-"$2".zip" * -x "*.txt"
# -----------------------------------------------------------------------------------------------
# All Done
echo $KERNELNAME"-"$2 "was made!"
[/HIGH]

my rom building script goes from nothing to a clean build then uploads it to goo and my webhosting. my kernel building script does a clean wipe compiles teh kernel, packs it into a boot.img with one of 3 ramdisks, then makes it into a flashable zip for me.

both of these scripts require the tools required to be in teh right places as well just figured id show you guys some insight on what tools i use
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones