123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- #!/bin/bash
-
- . "$MKIT_DIR/include/ini.sh" || die "cannot import ini.sh"
-
-
- build() {
-
-
-
- local srcpath
- find src -type f -name '*.skel' \
- | while read srcpath;
- do
- build1 "$srcpath"
- done
- }
-
- 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"
- mkdir -p "$MKIT_LOCAL"
- echo "$dstpath" >> "$MKIT_LOCAL/built.lst"
- }
-
- guess_ftype() {
-
-
-
- local dstpath="$1"
- case $dstpath in
- *.md) echo markdown ;;
- *) echo MKIT_COMMON ;;
- esac
- }
-
- build1_ftype() {
-
-
-
- local ftype="$1"
- case $ftype in
- MKIT_COMMON) expand_variables "vars" ;;
- markdown) expand_includes | expand_variables "vars" ;;
- rpmstuff) expand_variables "vars" "rpmstuff:vars" ;;
- *) die "unknown file type: $ftype" ;;
- esac
- }
-
- build_manpages() {
- local manfile mdfile
- if command -v ronn >/dev/null;
- then
- ini lskeys "files:man" \
- | while read manfile;
- do
- mdfile="$manfile.md"
- ronn -r "$mdfile"
- mkdir -p "$MKIT_LOCAL"
- echo "$manfile" >> "$MKIT_LOCAL/built.lst"
- done
- else
- echo "ronn is not installed"
- return 1
- fi
- }
-
- 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
- }
-
- dist() {
-
-
-
-
-
-
- local version=$(get_version)
- local dirname=$MKIT_PROJ_PKGNAME-$version
- mkdir -p "$dirname"
- ini values "lists:dist" | xargs -I DIST_ITEM cp -R DIST_ITEM "$dirname"
- update_version "$version" "$dirname/mkit.ini"
- tar -cf "$dirname.tar" "$dirname"
- gzip -f "$dirname.tar"
- mkdir -p "$MKIT_LOCAL"
- echo "$dirname.tar.gz" >> "$MKIT_LOCAL/built.lst"
- rm -rf "$dirname"
- }
-
- debstuff() {
-
-
-
- local version="$(get_version)"
-
-
-
- mv "${MKIT_PROJ_PKGNAME}-$version.tar.gz" \
- "${MKIT_PROJ_PKGNAME}_$version.orig.tar.gz" \
- || die "could not rename tarball"
- echo "${MKIT_PROJ_PKGNAME}_$version.orig.tar.gz" >> "$MKIT_LOCAL/built.lst"
-
-
-
- local debian_skel=$(ini 1value debstuff:debian_skel)
- test -n "$debian_skel" || die "debstuff:debian_skel not specified"
- test -d "$debian_skel" || die "debian directory template found: $debian_skel"
- mkdir -p debian/source
- local dfsrc dftgt
- find "$debian_skel" -type f \
- | while read dfsrc;
- do
- dftgt="debian/${dfsrc#$debian_skel}"
- mkdir -p "$(dirname "$dftgt")"
- build1 "$dfsrc" "$dftgt"
- done
- echo debian >> "$MKIT_LOCAL/built.lst"
- }
-
- rpmstuff() {
-
-
-
- local specname="$MKIT_PROJ_PKGNAME.spec"
- local specsrc="$(ini 1value "rpmstuff:spec_skel")"
- test -n "$specsrc" || die "rpmstuff:spec_skel not specified"
- test -f "$specsrc" || die "specfile template not found: $specsrc"
- build1 "$specsrc" "$specname"
- }
-
- expand_includes() {
-
-
-
-
-
- perl -we '
- use strict;
- my $text;
- while (<>) {
- chomp;
- if (m/<!-- include4: (\S+) -->/) {
- open my $fh, $1 or warn "cannot find: $1";
- my $text = do { local($/); <$fh> };
- close $fh;
- $text =~ s/^(.)/ $1/gm;
- chomp $text;
- print "$text\n";
- } else {
- print "$_\n";
- }
- }
- '
- }
-
- expand_variables() {
-
-
-
- local script=$(mktemp --tmpdir mkit-tmp.XXXXXXXXXX)
- local section varname varvalue
- {
- for section in "$@";
- do
- debug_var section
- ini lskeys "$section" \
- | while read varname;
- do
- varvalue="$(ini 1value "$section:$varname" | sed -e 's/\$/\\$/' )"
- echo "s|$varname|$varvalue|g;"
- debug_var varname varvalue
- done
- done
- echo "s|__MKIT_PROJ_NAME__|$(ini 1value project:name)|g;"
- echo "s|__MKIT_PROJ_CODENAME__|$(ini 1value project:codename)|g;"
- echo "s|__MKIT_PROJ_PKGNAME__|$(ini 1value project:pkgname)|g;"
- echo "s|__MKIT_PROJ_TAGLINE__|$(ini 1value project:tagline)|g;"
- echo "s|__MKIT_PROJ_VERSION__|$(get_version)|g;"
- echo "s|__MKIT_SELF_VERSION__|$MKIT_VERSION|g;"
- } >> "$script"
- perl -wp "$script" || die "expand_variables failed"
- rm "$script"
- }
-
- get_version() {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- local version=$(ini 1value project:version)
- local prerl=$(ini 1value project:prerl)
- grep ":" <<<"$prerl" && warn "colon in project:prerl may corrupt version data: $prerl"
- if git rev-parse HEAD >&/dev/null;
- then
- local latest_tag=$(
- git log --format="%D" \
- | sed 's/,/\n/g' \
- | sed 's/^[[:blank:]]*//; ' \
- | grep -E '^tag: v[[:digit:]]+\.' \
- | cut -d' ' -f2 \
- | head -1
- )
- if ! git describe --tags --exact-match HEAD >&/dev/null;
- then
- local sha=g$(git log -1 --pretty=format:%h HEAD)
- local curbranch=$(git rev-parse --abbrev-ref HEAD)
- local commit="$curbranch.$sha"
- fi
- if test "$(git diff --shortstat 2>/dev/null)" != "";
- then
- local dirty=dirty
- fi
- test -n "$latest_tag" && version=${latest_tag:1}
- local suffix=""
- case "$commit:$dirty" in
- :) suffix="" ;;
- :dirty) suffix="+$dirty" ;;
- *:) suffix="+$commit" ;;
- *:dirty) suffix="+$commit.$dirty" ;;
- esac
- test -b "$prerl" && suffix="-$prerl$suffix"
- version="$version$suffix"
- fi
- echo "$version"
- }
|