- fixed tabs vs. spaces mix-up by using only spaces

Signed-off-by: Steffen Pankratz <kratz00@gmx.de>
Reviewed-by: Tim Niemeyer <tim.niemeyer@mastersword.de>
This commit is contained in:
Steffen Pankratz 2015-07-17 18:47:16 +02:00 committed by Tim Niemeyer
parent 1cba3f0e59
commit bcb17059da
1 changed files with 283 additions and 284 deletions

View File

@ -36,351 +36,350 @@ FASTD_PKGS="fastd"
FEEDS=(OPENWRT OPENWRT_OLDPACKAGES ROUTING FASTD) FEEDS=(OPENWRT OPENWRT_OLDPACKAGES ROUTING FASTD)
checkout_git(){ checkout_git(){
local DIRECTORY=$1 local DIRECTORY=$1
local REPO_URL=$2 local REPO_URL=$2
local COMMITID=$3 local COMMITID=$3
local MYGIT="git -C $DIRECTORY" local MYGIT="git -C $DIRECTORY"
echo "checking out $REPO_URL to $DIRECTORY in version $COMMITID" echo "checking out $REPO_URL to $DIRECTORY in version $COMMITID"
if [ -d "$DIRECTORY" ]; then if [ -d "$DIRECTORY" ]; then
if $MYGIT remote -v | grep -q "$REPO_URL" ; then if $MYGIT remote -v | grep -q "$REPO_URL" ; then
echo "Right remote detected" echo "Right remote detected"
if ! $MYGIT checkout "$COMMITID" ; then if ! $MYGIT checkout "$COMMITID" ; then
echo "commitid not found trying to fetch new commits" echo "commitid not found trying to fetch new commits"
$MYGIT pull && $MYGIT checkout "$COMMITID" $MYGIT pull && $MYGIT checkout "$COMMITID"
fi fi
else else
echo "wrong remote or not an git repo at all -> deleting whole directory" echo "wrong remote or not an git repo at all -> deleting whole directory"
/bin/rm -rf "$DIRECTORY" /bin/rm -rf "$DIRECTORY"
#needs to be without -C!!! #needs to be without -C!!!
git clone "$REPO_URL" "$DIRECTORY" git clone "$REPO_URL" "$DIRECTORY"
$MYGIT checkout "$COMMITID" $MYGIT checkout "$COMMITID"
fi fi
else else
echo "We need to do a fresh checkout" echo "We need to do a fresh checkout"
#needs to be without -C!!! #needs to be without -C!!!
git clone "$REPO_URL" "$DIRECTORY" git clone "$REPO_URL" "$DIRECTORY"
$MYGIT checkout "$COMMITID" $MYGIT checkout "$COMMITID"
fi fi
} }
get_source() { get_source() {
test -d src || mkdir src test -d src || mkdir src
cd src cd src
#Get the OpenWrt Core Source for Firmware #Get the OpenWrt Core Source for Firmware
checkout_git openwrt $OPENWRTURL $OPENWRTREV checkout_git openwrt $OPENWRTURL $OPENWRTREV
test -d packages || mkdir packages test -d packages || mkdir packages
cd packages cd packages
#checkout needed package feeds #checkout needed package feeds
for FEEDVAR in "${FEEDS[@]}" ; do for FEEDVAR in "${FEEDS[@]}" ; do
FEED="${FEEDVAR}[@]" FEED="${FEEDVAR}[@]"
FEED=("${!FEED}") FEED=("${!FEED}")
local NAME=${FEED[0]} local NAME=${FEED[0]}
local URL=${FEED[1]} local URL=${FEED[1]}
local REV=${FEED[2]} local REV=${FEED[2]}
local PATCH=${FEED[3]} local PATCH=${FEED[3]}
checkout_git "$NAME" "$URL" "$REV" checkout_git "$NAME" "$URL" "$REV"
# Patches for feeds could be stored in known directories like build_patches/$NAME/ # Patches for feeds could be stored in known directories like build_patches/$NAME/
# That way multiple patches for one feed could be supported # That way multiple patches for one feed could be supported
if [ ! -z "$PATCH" ] ; then if [ ! -z "$PATCH" ] ; then
echo "Patching $PATCH" echo "Patching $PATCH"
git -C "$NAME" am --whitespace=nowarn "$PATCH" git -C "$NAME" am --whitespace=nowarn "$PATCH"
fi fi
done done
cd .. # packages cd .. # packages
cd .. # src cd .. # src
} }
prepare() { prepare() {
get_source get_source
test -d $builddir || mkdir $builddir test -d $builddir || mkdir $builddir
/bin/rm -rf "$target" /bin/rm -rf "$target"
cp -a src/openwrt "$target" cp -a src/openwrt "$target"
## generate own feeds.conf ## generate own feeds.conf
#this local variable should be globally configure variable used in get_source and here #this local variable should be globally configure variable used in get_source and here
local PACKAGEBASE=${PWD}/src/packages local PACKAGEBASE=${PWD}/src/packages
rm -f "$target"/feeds.conf rm -f "$target"/feeds.conf
for FEEDVAR in "${FEEDS[@]}" ; do for FEEDVAR in "${FEEDS[@]}" ; do
FEED="${FEEDVAR}[@]" FEED="${FEEDVAR}[@]"
FEED=("${!FEED}") FEED=("${!FEED}")
local NAME=${FEED[0]} local NAME=${FEED[0]}
echo "adding $NAME to package feeds" echo "adding $NAME to package feeds"
echo src-link "$NAME" "$PACKAGEBASE"/"$NAME" >> "$target"/feeds.conf echo src-link "$NAME" "$PACKAGEBASE"/"$NAME" >> "$target"/feeds.conf
done done
echo "cleaning feeds" echo "cleaning feeds"
/bin/rm -rf "$target"/feeds /bin/rm -rf "$target"/feeds
"$target"/scripts/feeds update "$target"/scripts/feeds update
for FEEDVAR in "${FEEDS[@]}" ; do for FEEDVAR in "${FEEDS[@]}" ; do
FEED="${FEEDVAR}[@]" FEED="${FEEDVAR}[@]"
FEED=("${!FEED}") FEED=("${!FEED}")
local NAME=${FEED[0]} local NAME=${FEED[0]}
local PACKAGESVAR="${FEEDVAR}_PKGS" local PACKAGESVAR="${FEEDVAR}_PKGS"
PACKAGESVAR="${PACKAGESVAR}[@]" PACKAGESVAR="${PACKAGESVAR}[@]"
PACKAGESVAR=(${!PACKAGESVAR}) PACKAGESVAR=(${!PACKAGESVAR})
if [[ -n "${PACKAGESVAR[@]}" ]] ; then if [[ -n "${PACKAGESVAR[@]}" ]] ; then
echo "adding ${PACKAGESVAR[*]} from feed $NAME to available packages" echo "adding ${PACKAGESVAR[*]} from feed $NAME to available packages"
"$target"/scripts/feeds install -p "$NAME" "${PACKAGESVAR[@]}" "$target"/scripts/feeds install -p "$NAME" "${PACKAGESVAR[@]}"
fi fi
done done
# todo evaluate this with the new openwrt # todo evaluate this with the new openwrt
# This changes the default behavior of sysupgrade to not save the config # This changes the default behavior of sysupgrade to not save the config
patch -p0 -d "$target" -i "$PWD"/build_patches/sysupgrade_no_config_save.patch patch -p0 -d "$target" -i "$PWD"/build_patches/sysupgrade_no_config_save.patch
#saves ~200MB for each build #saves ~200MB for each build
test -d ./src/dl || mkdir ./src/dl test -d ./src/dl || mkdir ./src/dl
ln -s ../../src/dl "$target"/dl ln -s ../../src/dl "$target"/dl
board_prepare board_prepare
} }
prebuild() { prebuild() {
#create filesdir for our config #create filesdir for our config
/bin/rm -rf "$target"/files /bin/rm -rf "$target"/files
mkdir "$target"/files mkdir "$target"/files
cp -r ./bsp/default/root_file_system/* "$target"/files/ cp -r ./bsp/default/root_file_system/* "$target"/files/
cp -r ./bsp/"$machine"/root_file_system/* "$target"/files/ cp -r ./bsp/"$machine"/root_file_system/* "$target"/files/
cp ./bsp/"$machine"/.config "$target"/.config cp ./bsp/"$machine"/.config "$target"/.config
arch=$(awk -F= '/^CONFIG_TARGET_BOARD/{print gsub(/"/,"",$2); print $2;}' ./bsp/"$machine"/.config) arch=$(awk -F= '/^CONFIG_TARGET_BOARD/{print gsub(/"/,"",$2); print $2;}' ./bsp/"$machine"/.config)
version=$(awk '/^CONFIG_LINUX/ { sub(/CONFIG_LINUX_/,""); sub(/=y/,""); gsub(/_/,"."); print; }' ./bsp/"$machine"/.config) version=$(awk '/^CONFIG_LINUX/ { sub(/CONFIG_LINUX_/,""); sub(/=y/,""); gsub(/_/,"."); print; }' ./bsp/"$machine"/.config)
test -f ./bsp/"$machine"/.kernelconfig-"$version" && \ test -f ./bsp/"$machine"/.kernelconfig-"$version" && \
cp ./bsp/"$machine"/.kernelconfig-"$version" \ cp ./bsp/"$machine"/.kernelconfig-"$version" \
"$target"/target/linux/"$arch"/config-"$version" "$target"/target/linux/"$arch"/config-"$version"
board_prebuild board_prebuild
shopt -s globstar nullglob shopt -s globstar nullglob
for template in $target/files/**/*.tpl for template in $target/files/**/*.tpl
do do
echo "Translating $template .." echo "Translating $template .."
$tpl_translate "$template" > "$(dirname "$template")"/"$(basename "$template" .tpl)" $tpl_translate "$template" > "$(dirname "$template")"/"$(basename "$template" .tpl)"
/bin/rm "$template" /bin/rm "$template"
done done
#insert actual firware version informations into release file #insert actual firware version informations into release file
version=$(git describe --tags --dirty) version=$(git describe --tags --dirty)
{ {
echo "FIRMWARE_VERSION=\"$version\"" echo "FIRMWARE_VERSION=\"$version\""
echo "BUILD_DATE=\"build date: $(date)\"" echo "BUILD_DATE=\"build date: $(date)\""
echo "OPENWRT_CORE_REVISION=\"${OPENWRTREV}\"" echo "OPENWRT_CORE_REVISION=\"${OPENWRTREV}\""
echo "OPENWRT_FEEDS_PACKAGES_REVISION=\"${PACKAGEREV}\"" echo "OPENWRT_FEEDS_PACKAGES_REVISION=\"${PACKAGEREV}\""
} > "$target"/files/etc/firmware_release } > "$target"/files/etc/firmware_release
} }
build() { build() {
prebuild prebuild
opath=$(pwd) opath=$(pwd)
cd "$target" cd "$target"
cpus=$(grep -c processor /proc/cpuinfo) cpus=$(grep -c processor /proc/cpuinfo)
case "$1" in case "$1" in
"debug") "debug")
make V=99 make V=99
;; ;;
"fast") "fast")
ionice -c 2 -- nice -n 1 -- make -j $((cpus*2)) ionice -c 2 -- nice -n 1 -- make -j $((cpus*2))
;; ;;
*) *)
ionice -c 3 -- nice -n 10 -- make -j $((cpus+1)) ionice -c 3 -- nice -n 10 -- make -j $((cpus+1))
;; ;;
esac esac
cd "$opath" cd "$opath"
if [ ! -d bin ]; then if [ ! -d bin ]; then
mkdir bin mkdir bin
fi fi
postbuild postbuild
} }
config() { config() {
prebuild prebuild
opath=$(pwd) opath=$(pwd)
cd "$target" cd "$target"
case "$1" in case "$1" in
"openwrt") "openwrt")
make menuconfig make menuconfig
;; ;;
"kernel") "kernel")
make kernel_menuconfig make kernel_menuconfig
;; ;;
esac esac
cd "$opath" cd "$opath"
save="" save=""
until [ "$save" = "y" -o "$save" = "n" ]; do until [ "$save" = "y" -o "$save" = "n" ]; do
echo "Do you want to save the generated config? (y/n)" echo "Do you want to save the generated config? (y/n)"
read save read save
done done
if [ "$save" = "y" ]; then if [ "$save" = "y" ]; then
case "$1" in case "$1" in
"openwrt") "openwrt")
grep '^CON\|^# CON' "$target"/.config | sort > ./bsp/"$machine"/.config grep '^CON\|^# CON' "$target"/.config | sort > ./bsp/"$machine"/.config
;; ;;
"kernel") "kernel")
arch=$(awk -F= '/^CONFIG_TARGET_BOARD/{gsub(/"/,"",$2); print $2;}' ./bsp/"$machine"/.config) arch=$(awk -F= '/^CONFIG_TARGET_BOARD/{gsub(/"/,"",$2); print $2;}' ./bsp/"$machine"/.config)
version=$(awk '/^CONFIG_LINUX/ { sub(/CONFIG_LINUX_/,""); sub(/=y/,""); gsub(/_/,"."); print; }' ./bsp/"$machine"/.config) version=$(awk '/^CONFIG_LINUX/ { sub(/CONFIG_LINUX_/,""); sub(/=y/,""); gsub(/_/,"."); print; }' ./bsp/"$machine"/.config)
grep '^CON\|^# CON' "$target"/target/linux/"$arch"/config-"$version" | sort > ./bsp/"$machine"/.kernelconfig-"$version" grep '^CON\|^# CON' "$target"/target/linux/"$arch"/config-"$version" | sort > ./bsp/"$machine"/.kernelconfig-"$version"
;; ;;
esac esac
fi fi
} }
postbuild() { postbuild() {
board_postbuild board_postbuild
} }
clean() { clean() {
board_clean board_clean
/bin/rm -rf bin $builddir /bin/rm -rf bin $builddir
} }
buildall() { buildall() {
for bsp in $(/bin/ls bsp/*.bsp); do for bsp in $(/bin/ls bsp/*.bsp); do
./buildscript selectcommunity "$1" ./buildscript selectcommunity "$1"
./buildscript selectbsp "$bsp" ./buildscript selectbsp "$bsp"
./buildscript prepare ./buildscript prepare
./buildscript build "$2" ./buildscript build "$2"
done done
} }
if [ "$1" != "selectbsp" -a "$1" != "selectcommunity" -a "$1" != "buildall" ]; then if [ "$1" != "selectbsp" -a "$1" != "selectcommunity" -a "$1" != "buildall" ]; then
if [ ! -h selected_bsp ]; then if [ ! -h selected_bsp ]; then
echo "Please select a Board-Support-Package using:" echo "Please select a Board-Support-Package using:"
echo "$0 selectbsp" echo "$0 selectbsp"
exit exit
fi fi
if [ ! -h selected_community ]; then if [ ! -h selected_community ]; then
echo "Please select a community file using:" echo "Please select a community file using:"
echo "$0 selectcommunity" echo "$0 selectcommunity"
exit exit
fi fi
echo "Working with $(/bin/ls -l selected_bsp | awk '{ print $11 }') and" \ echo "Working with $(/bin/ls -l selected_bsp | awk '{ print $11 }') and" \
"$(/bin/ls -l selected_community | awk '{ print $11 }')" "$(/bin/ls -l selected_community | awk '{ print $11 }')"
. selected_bsp . selected_bsp
tpl_translate=$(awk -F= 'BEGIN{printf("sed")} /^.+$/{gsub("/", "\\/", $0); printf(" -es/\\${%s}/%s/g",$1,$2)}' selected_community) tpl_translate=$(awk -F= 'BEGIN{printf("sed")} /^.+$/{gsub("/", "\\/", $0); printf(" -es/\\${%s}/%s/g",$1,$2)}' selected_community)
echo echo
fi fi
case "$1" in case "$1" in
"selectbsp") "selectbsp")
if [ "$2" = "help" ] || [ "$2" = "" ]; then if [ "$2" = "help" ] || [ "$2" = "" ]; then
echo "Select a Board-Support-Package:" echo "Select a Board-Support-Package:"
echo echo
echo "Usage: $0 $1 bsp" echo "Usage: $0 $1 bsp"
echo "available packages:" echo "available packages:"
/bin/ls bsp/*.bsp /bin/ls bsp/*.bsp
else else
if [ ! -f "$2" ]; then if [ ! -f "$2" ]; then
echo "Could not find $2" echo "Could not find $2"
else else
/bin/rm -rf selected_bsp /bin/rm -rf selected_bsp
/bin/ln -s "$2" selected_bsp /bin/ln -s "$2" selected_bsp
fi fi
fi fi
;; ;;
"selectcommunity") "selectcommunity")
if [ "$2" = "help" ] || [ "$2" = "" ]; then if [ "$2" = "help" ] || [ "$2" = "" ]; then
echo "Select a Community-File:" echo "Select a Community-File:"
echo echo
echo "Usage: $0 $1 community.cfg" echo "Usage: $0 $1 community.cfg"
echo "community.cfg: " echo "community.cfg: "
/bin/ls community/*.cfg /bin/ls community/*.cfg
else else
if [ ! -f "$2" ]; then if [ ! -f "$2" ]; then
echo "Could not find $2" echo "Could not find $2"
else else
/bin/rm -rf selected_community /bin/rm -rf selected_community
/bin/ln -s "$2" selected_community /bin/ln -s "$2" selected_community
fi fi
fi fi
;; ;;
"prepare") "prepare")
if [ "$2" = "help" ] || [ "$2" = "x" ]; then if [ "$2" = "help" ] || [ "$2" = "x" ]; then
echo "This option fetches the sources for the images and configurates the build so that it can be compiled" echo "This option fetches the sources for the images and configurates the build so that it can be compiled"
echo "Usage: $0 $1" echo "Usage: $0 $1"
else else
prepare prepare
fi fi
;; ;;
"build") "build")
if [ "$2" = "help" ] || [ "$2" = "x" ]; then if [ "$2" = "help" ] || [ "$2" = "x" ]; then
echo "This option compiles the firmware" echo "This option compiles the firmware"
echo "Normaly the build uses lower IO and System priorities, " echo "Normaly the build uses lower IO and System priorities, "
echo "you can append \"fast\" option, to use normal user priorities" echo "you can append \"fast\" option, to use normal user priorities"
echo "Usage: $0 $1 [fast|debug]" echo "Usage: $0 $1 [fast|debug]"
else else
build "$2" build "$2"
fi fi
;; ;;
"config") "config")
case "$2" in case "$2" in
openwrt) openwrt)
config openwrt config openwrt
;; ;;
kernel) kernel)
config kernel config kernel
;; ;;
*) *)
echo "This open the OpenWRT menuconfig dialog" echo "This open the OpenWRT menuconfig dialog"
echo echo
echo "Usage: $0 $1 openwrt|kernel" echo "Usage: $0 $1 openwrt|kernel"
;; ;;
esac esac
;; ;;
"clean") "clean")
if [ "$2" = "help" ] || [ "$2" = "x" ]; then if [ "$2" = "help" ] || [ "$2" = "x" ]; then
echo "This option cleans all build files." echo "This option cleans all build files."
echo "$0 $1" echo "$0 $1"
else else
clean clean
fi fi
;; ;;
"buildall") "buildall")
if [ "$2" = "help" ] || [ "$2" = "" ]; then if [ "$2" = "help" ] || [ "$2" = "" ]; then
echo "This option builds the firmware for all routers of a given community." echo "This option builds the firmware for all routers of a given community."
echo "Usage: $0 $1 community.cfg [fast]" echo "Usage: $0 $1 community.cfg [fast]"
echo "community.cfg: " echo "community.cfg: "
/bin/ls community/*.cfg /bin/ls community/*.cfg
else else
buildall "$2" "$3" buildall "$2" "$3"
fi fi
;; ;;
*) *)
echo "This is the Build Environment Script of the Freifunk Community Franken." echo "This is the Build Environment Script of the Freifunk Community Franken."
echo "Usage: $0 command" echo "Usage: $0 command"
echo "command:" echo "command:"
echo " selectcommunity [communityfile]" echo " selectcommunity [communityfile]"
echo " selectbsp [bsp file]" echo " selectbsp [bsp file]"
echo " prepare" echo " prepare"
echo " config <openwrt|kernel>" echo " config <openwrt|kernel>"
echo " build [<fast|debug>]" echo " build [<fast|debug>]"
echo " buildall <community> [<fast>]" echo " buildall <community> [<fast>]"
echo " clean" echo " clean"
echo "" echo ""
echo "If you need help to one of these options just type $0 command help" echo "If you need help to one of these options just type $0 command help"
;; ;;
esac esac
# vim: noexpandtab