123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- #!/bin/bash
- # (c) 2014-2015 Helge Jung <hej@c3pb.de>
- #
- # This script is controlled by environment variables, the
- # first two being mandatory:
- #
- # BASE = Gluon Version (tag or commit, i.e. v2014.4)
- # BRANCH = Firmware Branch (stable/testing/experimental)
- # SITE = specific site repository commit-id (leave blank to use HEAD)
- # VERSION = the version tag (can only be empty if BRANCH=experimental)
- # BUILD_TS = build timestamp (format: %Y-%m-%d %H:%M:%S)
- # BROKEN = 0 (default) or 1, build the untested hardware model firmwares, too
- # MAKEJOBS = number of compiler processes running in parallel (default: number of CPUs/Cores)
- # TARGETS = a space separated list of target platforms (if unset, all platforms will be build)
- #
- function get_all_supported_platforms()
- {
- local buffer;
- for val in $(ls ${1}) ; do
- [ -d "./${1}/${val}" ] || continue
- buffer="${buffer} ${val}"
- done
- echo ${buffer}
- }
- if [ "_$BRANCH" == "_" ]; then
- echo "Please specify BRANCH environment variable." >&2
- exit 1
- fi
- if [ "_$BASE" == "_" ]; then
- echo "Please specify BASE environment variable (Gluon, i.e. 'v2014.3' or commit-id)." >&2
- exit 1
- fi
- if [ "${BRANCH}" != "experimental" -a "${BASE}" == "HEAD" ] ; then
- echo "HEAD is not an allowed BASE-identifier for non-experimental builds." >&2
- echo "Either use a tagged commit or the commit-SHA itself." >&2
- exit 1
- fi
- if [ "_$VERSION" == "_" -a "$BRANCH" != "experimental" ]; then
- echo "Please specify VERSION environment variable (not necessary for experimental branch)." >&2
- exit 1
- fi
- MY_DIR=$(dirname $0)
- MY_DIR=$(readlink -f "$MY_DIR")
- CODE_DIR="src"
- OUTPUT_DIR="${MY_DIR}/output"
- BUILD_INFO_FILENAME="build-info.txt"
- VERSIONS_INFO_DIR="versions"
- pushd $MY_DIR > /dev/null
- [ "_$BUILD_TS" == "_" ] && export BUILD_TS=$(date +"%Y-%m-%d %H:%M:%S")
- . functions.sh
- ### CHECK THAT VERSION DOES NOT YET EXISTS
- [ -n "$VERSION" -a -x "${VERSIONS_INFO_DIR}/${VERSION}" ] && abort "There exists a version file for '$VERSION' ... you are trying to do something really stupid, aren't you?"
- ### INIT /src IF NECESSARY
- if [ ! -d "$CODE_DIR" ]; then
- info "Code directory does not exist yet - fetching Gluon ..."
- git clone https://github.com/freifunk-gluon/gluon.git "$CODE_DIR"
- fi
- ### INIT /src/site IF NECESSARY
- if [ ! -d "$CODE_DIR/site" ]; then
- info "Site repository does not exist, fetching it ..."
- git clone https://git.c3pb.de/freifunk-pb/site-ffpb.git "$CODE_DIR/site"
- fi
- ### CHECKOUT GLUON
- progress "Checking out GLUON '$BASE' ..."
- cd $CODE_DIR
- # TODO: check if gluon got modified and bail out if necessary
- git fetch ; git checkout -q $BASE
- [ "$?" -eq "0" ] || abort "Failed to checkout '$BASE' gluon base version, mimimi." >&2
- GLUON_COMMIT=$(git rev-list --max-count=1 HEAD)
- ### CHECKOUT SITE REPO
- progress "Checking out SITE REPO ..."
- cd site
- # TODO: check if site got modified locally and bail out if necessary
- if [ "_$SITE" == "_" ]; 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
- # commit given - use this one
- git checkout -q $SITE || abort "Failed to checkout requested site commit, mimimi."
- fi
- SITE_COMMIT=$(git rev-list --max-count=1 HEAD)
- cd ..
- ### CLEAN
- if [ -d "./build/" -a "$BRANCH" != "experimental" ]; then
- progress "Cleaning your build environment ..."
- make dirclean
- fi
- ### PREPARE
- progress "Preparing the build environment (make update) ..."
- make update
- [ "$?" -eq "0" ] || abort "Failed to update the build environment, mimimi."
- # we are now ready to produke the firmware images, so let's "save" our state
- build_info_path="${OUTPUT_DIR}/${BRANCH}/${BUILD_INFO_FILENAME}"
- progress "Saving build information to: ${build_info_path}"
- mkdir -p $(dirname ${build_info_path})
- [ "$?" -eq "0" ] || abort "Unable to create output directory: $(dirname ${build_info_path})"
- touch $(dirname ${build_info_path})
- [ "$?" -eq "0" ] || abort "Cannot create build information file: ${build_info_path}"
- echo "VERSION=${VERSION}" >> ${build_info_path}
- echo "GLUON=${GLUON_COMMIT} # ${BASE}" >> ${build_info_path}
- echo "BRANCH=${BRANCH}" >> ${build_info_path}
- echo "SITE=${SITE_COMMIT} # ${VERSION}" >> ${build_info_path}
- echo "TS=${BUILD_TS}" >> ${build_info_path}
- ### BUILD FIRMWARE
- progress "Building the firmware - please stand by!"
- [ -n "${BROKEN}" ] || BROKEN=0
- [ -n "${MAKEJOBS}" ] || MAKEJOBS=$(grep -c "^processor" /proc/cpuinfo)
- [ -n "${TARGETS}" ] || TARGETS=$(get_all_supported_platforms "./targets")
- if [ "${BRANCH}" == "experimental" -a -z "${VERSION}" ] ; then
- default_release_pattern=$( awk -F" := " '/^DEFAULT_GLUON_RELEASE/ { gsub("shell ", "", $2); print $2; }' ./site/site.mk )
- VERSION=$(eval echo ${default_release_pattern})
- fi
- for target in ${TARGETS} ; do
- # configure build environment for our current target
- export GLUON_TARGET="${target}"
- gluon_build_env_vars="GLUON_TARGET=\"${target}\" GLUON_BRANCH=\"${BRANCH}\" GLUON_RELEASE=\"${VERSION}\" BROKEN=\"${BROKEN}\""
- # prepare build environment for our current target
- progress "Preparing build environment for target ${target}."
- [ "${BRANCH}" == "experimental" ] || make clean
- make -j ${MAKEJOBS} prepare-target
- # need to have a toolchain for the particular target
- progress "Building toolchain for target ${target}."
- make -j ${MAKEJOBS} toolchain/install
- [ "$?" -eq "0" ] || abort "Unable to build toolchain for target. Aborting."
- # now we can start building the images for the target platform
- progress "Building FFPB-flavoured Gluon firmware for target ${target}. You'd better go and fetch some c0ffee!"
- make_targets="prepare"
- eval "${gluon_build_env_vars} faketime \"$BUILD_TS\" make -j ${MAKEJOBS} ${make_targets}"
- [ "$?" -eq "0" ] || abort "Failed to build firmware for target-platform ${target}."
- # finally compile the firmware binaries
- progress "Compiling binary firmware images."
- faketime "$BUILD_TS" make images
- [ "$?" -eq "0" ] || abort "Failed to assemble images for target-platform ${target}."
- done
- cd ..
- # compress all binaries into 7z archive
- progress "Assembling images.7z ..."
- [ -e "${OUTPUT_DIR}/${BRANCH}/images.7z" ] && rm "${OUTPUT_DIR}/${BRANCH}/images.7z"
- 7z a "${OUTPUT_DIR}/${BRANCH}/images.7z" ${CODE_DIR}/images/sysupgrade/*.bin ${CODE_DIR}/images/factory/*.bin || abort "Failed to assemble images (did you install p7zip-full?)."
- # generate, franken-merge, and copy manifests
- progress "Generating and copying manifest ..."
- pushd $CODE_DIR
- for target in ${TARGETS} ; do
- GLUON_TARGET="${target}" GLUON_BRANCH=$BRANCH make manifest || abort "Failed to generate the manifest, try running 'make manifest' in '$CODE_DIR' directory manually."
- mv ./images/sysupgrade/${BRANCH}.manifest ./images/sysupgrade/${target}.${BRANCH}.manifest
- done
- frankenmerge_manifest_file="./images/sysupgrade/${BRANCH}.manifest"
- echo "BRANCH=${BRANCH}" > ${frankenmerge_manifest_file}
- echo "DATE=${BUILD_TS}$(date +%:z)" >> ${frankenmerge_manifest_file}
- echo "PRIORITY=0" >> ${frankenmerge_manifest_file}
- echo "" >> ${frankenmerge_manifest_file}
- grep -hE "*.bin$" ./images/sysupgrade/*.${BRANCH}.manifest | sort >> ${frankenmerge_manifest_file}
- popd
- cp "${CODE_DIR}/images/sysupgrade/${BRANCH}.manifest" "${OUTPUT_DIR}/${BRANCH}/"
- # Saving a copy of the build info file as reference
- progress "Building a greater and brighter firmware finished successfully. Saving build information at: ${VERSIONS_INFO_DIR}/${VERSION}"
- cp -p "${build_info_path}" "${VERSIONS_INFO_DIR}/${VERSION}"
- # The end. Finally.
- success "We're done, go and enjoy your new firmware in ${OUTPUT_DIR}/${BRANCH}!"
- popd > /dev/null
|