Browse Source

build.sh: some improvements

Karsten Böddeker 8 years ago
parent
commit
e9c2731605
1 changed files with 47 additions and 37 deletions
  1. 47 37
      build.sh

+ 47 - 37
build.sh

@@ -130,17 +130,23 @@ GLUON_COMMIT=$(git rev-list --max-count=1 HEAD)
 ### CHECKOUT SITE REPO
 progress "Checking out SITE REPO ..."
 pushd ${SITE_DIR} > /dev/null
-# TODO: check if site got modified locally and bail out if necessary
-if [ -z "${SITE_ID}" ]; then
-	# no specific site given - get the most current one
-	git checkout -q ${BRANCH} ; git pull
-	[ "$?" -eq "0" ] || abort "Failed to get newest '${BRANCH}' in site repository, mimimi."
-else
-	# fetch site repo updates
-	git fetch || true
-	# commit given - use this one
-	git checkout -q ${SITE_ID}
-	[ "$?" -eq "0" ] || abort "Failed to checkout requested site commit '${SITE_ID}', mimimi."
+if [ $(git remote | wc -l) >= 1 ]; then
+	git fetch
+	# TODO: check if site got modified locally and bail out if necessary
+	if [ -z "${SITE_ID}" ]; then
+		# no specific site given - get the most current one
+		git checkout -q ${BRANCH}
+		if [ git branch -r | grep ${BRANCH} ]; then
+			git rebase
+			[ "$?" -eq "0" ] || abort "Failed to get newest '${BRANCH}' in site repository, mimimi."
+		fi
+	else
+		# fetch site repo updates
+		git fetch || true
+		# commit given - use this one
+		git checkout -q ${SITE_ID}
+		[ "$?" -eq "0" ] || abort "Failed to checkout requested site commit '${SITE_ID}', mimimi."
+	fi
 fi
 SITE_COMMIT=$(git rev-list --max-count=1 HEAD)
 popd > /dev/null #${SITE_DIR}
@@ -149,7 +155,7 @@ popd > /dev/null #${SITE_DIR}
 progress "Applying Patches ..."
 git checkout -B patching "${BASE}"
 if [ -d "${PATCH_DIR}" -a "$(echo ${PATCH_DIR}/*.patch)" ]; then
-	git am ${PATCH_DIR}/*.patch || (
+	git am --whitespace=nowarn ${PATCH_DIR}/*.patch || (
 		git am --abort
 		git checkout patched
 		git branch -D patching
@@ -162,7 +168,7 @@ git branch -M patched
 
 ### DIRCLEAN
 if [ -d "${GLUON_BUILD_DIR}/" -a "${CLEAN}" == "dirclean" ]; then
-	progress "Cleaning your build environment ..."
+	progress "Cleaning your build environment (make dirclean) ..."
 	make dirclean
 fi
 
@@ -175,7 +181,7 @@ popd > /dev/null #${CODE_DIR}
 ### set reasonable defaults for ${TARGETS} and ${BRANCH} if unset
 if [ -z "${TARGETS}" ]; then
         TARGETS=$(make list-targets | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
-        info "building all tagets: '${TARGETS}'"
+        info "building all targets: '${TARGETS}'"
 fi
 if [ "${BRANCH}" == "experimental" -a -z "${VERSION}" ] ; then
         VERSION=$(make default-release)
@@ -224,53 +230,57 @@ for target in ${TARGETS} ; do
 	[ "${AUTOUPDATER}" != "off" ] && export GLUON_BRANCH="${AUTOUPDATER}"
 
 	# prepare build environment for our current target
-	progress "Preparing build environment for target ${target}."
+	progress "${target}: Preparing build environment."
 	if [ "${CLEAN}" == "clean" ]; then
 		make clean
-		[ "$?" -eq "0" ] || abort "Unable to clean environment for target-platform ${target}."
+		[ "$?" -eq "0" ] || abort "${target}: Unable to clean environment."
 	fi
 
 	make -j ${MAKEJOBS} prepare-target ${MAKE_PARAM}
-	[ "$?" -eq "0" ] || abort "Unable to build environment for target-platform ${target}."
+	[ "$?" -eq "0" ] || abort "${target}: Unable to build environment."
 
 	# need to have a toolchain for the particular target 
-	progress "Building toolchain for target ${target}."
+	progress "${target}: Building toolchain."
 	make -j ${MAKEJOBS} toolchain/install ${MAKE_PARAM}
-	[ "$?" -eq "0" ] || abort "Unable to build toolchain for target-platform ${target}."
+	[ "$?" -eq "0" ] || abort "${target}: Unable to build toolchain."
 
 	# now we can start building the images for the target platform
-	progress "Building FFHO-flavoured Gluon firmware for target ${target}. You'd better go and fetch some c0ffee!"
+	progress "${target}: Building FFHO-flavoured Gluon firmware. You'd better go and fetch some c0ffee!"
 	make -j ${MAKEJOBS} prepare ${MAKE_PARAM}
-	[ "$?" -eq "0" ] || abort "Failed to build firmware for target-platform ${target}."
+	[ "$?" -eq "0" ] || abort "${target}: Unable to build firmware."
 
 	# finally compile the firmware binaries
-	progress "Compiling binary firmware images."
+	progress "${target}: Compiling binary firmware images."
 	make -j ${MAKEJOBS} images ${MAKE_PARAM}
-	[ "$?" -eq "0" ] || abort "Failed to assemble images for target-platform ${target}."
+	[ "$?" -eq "0" ] || abort "${target}: Unable to assemble images."
 
 	# compile the modules
-	progress "Compiling modules."
+	progress "${target}: Compiling modules."
 	make -j ${MAKEJOBS} modules ${MAKE_PARAM}
-	[ "$?" -eq "0" ] || abort "Failed to build modules for target-platform ${target}."
+	[ "$?" -eq "0" ] || abort "${target}: Unable to build modules."
 done
 
 popd > /dev/null #${CODE_DIR}
 
 # compress all binaries into 7z archive
-progress "Assembling images.7z ..."
-pushd ${IMAGE_DIR} > /dev/null
-[ -e "${OUTPUT_DIR}/${BRANCH}/images.7z" ] && rm "${OUTPUT_DIR}/${BRANCH}/images.7z"
-7z a -mmt=on -xr!*.manifest "${OUTPUT_DIR}/${BRANCH}/images.7z" ./sysupgrade/* ./factory/*
-[ "$?" -eq "0" ] || abort "Failed to assemble images (did you install p7zip-full?)."
-popd > /dev/null #${IMAGE_DIR}
+if [ -d "${IMAGE_DIR}" ]; then
+	progress "Assembling images.7z ..."
+	pushd ${IMAGE_DIR} > /dev/null
+	[ -e "${OUTPUT_DIR}/${BRANCH}/images.7z" ] && rm "${OUTPUT_DIR}/${BRANCH}/images.7z"
+	7z a -mmt=on -xr!*.manifest "${OUTPUT_DIR}/${BRANCH}/images.7z" ./sysupgrade/* ./factory/*
+	[ "$?" -eq "0" ] || abort "Failed to assemble images (did you install p7zip-full?)."
+	popd > /dev/null #${IMAGE_DIR}
+fi
 
 # compress modules into 7z archive
-progress "Assembling modules.7z ..."
-pushd ${MODULE_DIR} > /dev/null
-[ -e "${OUTPUT_DIR}/${BRANCH}/modules.7z" ] && rm "${OUTPUT_DIR}/${BRANCH}/modules.7z"
-7z a -mmt=on "${OUTPUT_DIR}/${BRANCH}/modules.7z" ./* > /dev/null
-[ "$?" -eq "0" ] || abort "Failed to assemble modules."
-popd > /dev/null #${MODULE_DIR}
+if [ -d "${MODULE_DIR}" ]; then
+	progress "Assembling modules.7z ..."
+	pushd ${MODULE_DIR} > /dev/null
+	[ -e "${OUTPUT_DIR}/${BRANCH}/modules.7z" ] && rm "${OUTPUT_DIR}/${BRANCH}/modules.7z"
+	7z a -mmt=on "${OUTPUT_DIR}/${BRANCH}/modules.7z" ./* > /dev/null
+	[ "$?" -eq "0" ] || abort "Failed to assemble modules."
+	popd > /dev/null #${MODULE_DIR}
+fi
 
 # generate and copy manifests
 progress "Generating and copying manifest ..."