123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- #!/bin/bash
-
-
-
- mkit_import ini
- mkit_import facts
-
-
- __build1() {
-
-
-
- local srcpath=$1
- local dstpath=$2
- local ftype=$3
- test -n "$dstpath" || dstpath=${srcpath%.skel}
- test -n "$ftype" || ftype=$(__guess_ftype "$dstpath")
- debug_var srcpath dstpath ftype
- <"$srcpath" __build1_ftype "$ftype" >"$dstpath"
- __rec_built "$dstpath"
- }
-
- __build1_ftype() {
-
-
-
- local ftype=$1
- case $ftype in
- MKIT_COMMON) __expand_macros "macros" ;;
- rpmstuff) __expand_macros "macros" "rpmstuff:macros" ;;
- debstuff) __expand_macros "macros" "debstuff:macros" ;;
- *) die "unknown file type: $ftype" ;;
- esac
- }
-
- __expand_line() {
-
-
-
-
-
-
-
-
-
-
- local line=$1
- local mname
- local mvline
- local xline
- xline=$line
- for mname in "${!MacroMap[@]}"; do
- if ! test "${line//$mname}" == "$line"; then
- xline=$(
- while IFS= read -r mvline; do
- echo "${line//$mname/$mvline}"
- done <<<"${MacroMap[$mname]}"
- )
- fi
- line=$xline
- done
- echo "$xline"
- return 1
- }
-
- __expand_macros() {
-
-
-
- local section
- local line
- local mname
- local -A MacroMap
- MacroMap[__MKIT_PROJ_NAME__]=$(ini 1value project:name)
- MacroMap[__MKIT_PROJ_CODENAME__]=$(ini 1value project:codename)
- MacroMap[__MKIT_PROJ_LICENSE__]=$(ini 1value project:license)
- MacroMap[__MKIT_PROJ_PKGNAME__]=$(ini 1value project:pkgname)
- MacroMap[__MKIT_PROJ_TAGLINE__]=$(ini 1value project:tagline)
- MacroMap[__MKIT_PROJ_MAINTAINER__]=$(ini 1value project:maintainer)
- MacroMap[__MKIT_PROJ_VCS_BROWSER__]=$(ini 1value project:vcs_browser)
- MacroMap[__MKIT_PROJ_GIT_LASTHASH__]=$(__cached git_lasthash)
- MacroMap[__MKIT_PROJ_VERSION__]=$(__cached semver)
- MacroMap[__MKIT_SELF_VERSION__]=$MKIT_VERSION
- for section in "$@"; do
- for mname in $(ini lskeys "$section"); do
- MacroMap[$mname]=$(ini values "$section:$mname")
- done
- done
- debug_var MacroMap
- while IFS= read -r line; do
- __expand_line "$line"
- done
- }
-
- __guess_ftype() {
-
-
-
- local dstpath=$1
- case $dstpath in
- *) echo MKIT_COMMON ;;
- esac
- }
-
- __qfs() {
-
-
-
- sed '
- s:\\:\\\\:g
- s:|:\\|:g
- '
- }
-
- __cached() {
-
-
-
-
-
-
-
-
-
-
-
- local name=$1
- __local_get "$name" && return 0
- "$name" | __local_putb "$name"
- __local_get "$name"
- }
-
- __local_putb() {
-
-
-
- local fpath=$1
- __local_put "$fpath" && __rec_built "$MKIT_LOCAL/$fpath"
- }
-
- __local_put() {
-
-
-
- local fpath="$MKIT_LOCAL/$1"
- { mkdir -p "${fpath%/*}" && cat >"$fpath"; } \
- || die "cannot write to local cache: $fpath"
- }
-
- __local_get() {
-
-
-
- local fpath="$MKIT_LOCAL/$1"
- cat "$fpath" 2>/dev/null
- }
-
- __rec_built() {
-
-
-
- local file=$1
- mkdir -p "$MKIT_LOCAL"
- echo "$file" >> "$MKIT_LOCAL/built.lst"
- }
-
- _mkit_data() {
-
-
-
- local macro
- local section
- local sections
- sections=()
- ini lskeys macros | grep -q . && sections=(macros)
- sections+=( $(ini lssect | grep ':macros$') )
- {
- echo "(builtin):"
- echo " x_MKIT_PROJ_NAME__ => '__MKIT_PROJ_NAME__'"
- echo " x_MKIT_PROJ_CODENAME__ => '__MKIT_PROJ_CODENAME__'"
- echo " x_MKIT_PROJ_LICENSE__ => '__MKIT_PROJ_LICENSE__'"
- echo " x_MKIT_PROJ_PKGNAME__ => '__MKIT_PROJ_PKGNAME__'"
- echo " x_MKIT_PROJ_TAGLINE__ => '__MKIT_PROJ_TAGLINE__'"
- echo " x_MKIT_PROJ_MAINTAINER__ => '__MKIT_PROJ_MAINTAINER__'"
- echo " x_MKIT_PROJ_VCS_BROWSER__ => '__MKIT_PROJ_VCS_BROWSER__'"
- echo " x_MKIT_PROJ_GIT_LASTHASH__ => '__MKIT_PROJ_GIT_LASTHASH__'"
- echo " x_MKIT_PROJ_VERSION__ => '__MKIT_PROJ_VERSION__'"
- echo " x_MKIT_SELF_VERSION__ => '__MKIT_SELF_VERSION__'"
- for section in "${sections[@]}"; do
- echo "$section:"
- for macro in $(ini lskeys "$section"); do
- echo " x${macro:1} => '$macro'"
- done
- done
- } \
- | __expand_macros "MKIT_BUILTIN" "${sections[@]}" \
- | sed '/^ x/ s|x|_|'
- }
-
- build() {
-
-
-
- local srcpath
- find . -type f -name '*.skel' \
- | while read -r srcpath; do
- __build1 "$srcpath"
- done
- }
-
- clean() {
-
-
-
- test -f "$MKIT_LOCAL/built.lst" && {
- <"$MKIT_LOCAL/built.lst" grep -v -e '\.\.' -e ^/ \
- | xargs -r rm -rf
- rm -f "$MKIT_LOCAL/built.lst"
- rmdir --ignore-fail-on-non-empty "$MKIT_LOCAL"
- }
- true
- }
-
- debstuff() {
-
-
-
- local version
- local debian_skel
- local dfsrc
- local dftgt
- version=$(__cached semver)
-
-
-
- mv "${MKIT_PROJ_PKGNAME}-$version.tar.gz" \
- "${MKIT_PROJ_PKGNAME}_$version.orig.tar.gz" \
- || die "could not rename tarball"
- __rec_built "${MKIT_PROJ_PKGNAME}_$version.orig.tar.gz"
-
-
-
- debian_skel=$(ini 1value dist:debstuff)
- test -n "$debian_skel" || die "dist:debstuff not specified"
- test -d "$debian_skel" || die "debian directory template found: $debian_skel"
- mkdir -p debian/source
- find "$debian_skel" -type f \
- | while read -r dfsrc; do
- dftgt="debian/${dfsrc#$debian_skel}"
- mkdir -p "$(dirname "$dftgt")"
- __build1 "$dfsrc" "$dftgt" debstuff
- done
- __rec_built debian
- }
-
- dist() {
-
-
-
-
-
-
- local version
- local git_lasthash
- local dirname
- version=$(semver)
- dirname=$MKIT_PROJ_PKGNAME-$version
- git_lasthash=$(git_lasthash)
- mkdir -p "$dirname"
- ini values "dist:tarball" | xargs -I DIST_ITEM cp -R DIST_ITEM "$dirname"
- mkdir -p "$dirname/.mkit"
- echo -n "$version" > "$dirname/.mkit/semver"
- echo -n "$git_lasthash" > "$dirname/.mkit/git_lasthash"
- tar -cf "$dirname.tar" "$dirname"
- gzip -f "$dirname.tar"
- __rec_built "$dirname.tar.gz"
- rm -rf "$dirname"
- }
-
- rpmstuff() {
-
-
-
- local specname=$MKIT_PROJ_PKGNAME.spec
- local specsrc
- specsrc="$(ini 1value "dist:rpmstuff")"
- test -n "$specsrc" || die "dist:rpmstuff not specified"
- test -f "$specsrc" || die "specfile template not found: $specsrc"
- __build1 "$specsrc" "$specname" rpmstuff
- }
|