#! /bin/sh set -e OPK_SOURCE="$(sed 's/ .*//; q;' changelog)" BASE_VERSION="${OPK_SOURCE#gcc-}" TPL_PKGS='cpp gcc g++' main() { case "${1}" in clean) clean ;; *) if [ -z "${PKG_TARGETS}" ]; then PKG_TARGETS="$(cat targets.in)" fi for arch in ${PKG_TARGETS}; do PKG_TARGET_ARCH="${arch}" configure_build done >targets.mk printf 'targets = \\\n' >>targets.mk for arch in ${PKG_TARGETS}; do printf '\t%s \\\n' "${arch}" >>targets.mk done printf '\n' >>targets.mk ;; esac } msg() { printf "${OPK_SOURCE} config: " printf "${@}" printf '\n' } configure_build() { # Generate a sed script to edit files. _ss= for _name in TARGET_ARCH; do _ss="${_ss}s&@PKG_${_name}@&$(eval echo \$\{PKG_${_name}\})&;" done # Write metadata for - packages. for _pkg in ${TPL_PKGS}; do _out_pkg="${_pkg}-${BASE_VERSION}-${PKG_TARGET_ARCH}" mkdir -p "${_out_pkg}.pkg" sed "${_ss}" "${_pkg}.pkg.in/control" >"${_out_pkg}.pkg/control" cp "${_pkg}.pkg.in/files" "${_out_pkg}.pkg/files" msg 'Metadata for package "%s" generated.' "${_out_pkg}" done } clean() { # Remove generated metadata for - packages. for _pkg in ${TPL_PKGS}; do rm -Rf "${_pkg}-${BASE_VERSION}"-*-*-*.pkg/ done } main "${@}"