123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- #!/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")
- <"$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" xargs -r rm -f
- rm -f "$MKIT_LOCAL/built.lst"
- rmdir --ignore-fail-on-non-empty "$MKIT_LOCAL"
- }
- true
- }
-
- dist() {
-
-
-
-
-
-
- local version=$(get_version)
- local dirname=$MKIT_PKGNAME-$version
- mkdir -p "$dirname"
- ini values "lists:dist" | xargs -I DIST_ITEM cp -R DIST_ITEM "$dirname"
- sed -i -e "s/^VERSION = .*/VERSION = $version/" "$dirname/config.mk"
- tar -cf "$dirname.tar" "$dirname"
- gzip -f "$dirname.tar"
- mkdir -p "$MKIT_LOCAL"
- echo "$dirname.tar.gz" >> "$MKIT_LOCAL/built.lst"
- rm -rf "$dirname"
- }
-
- rpmstuff() {
-
-
-
- local specname="$(ini 1value ENV: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
- ini lskeys "$section" \
- | while read varname;
- do
- varvalue="$(ini 1value "$section:$varname" | sed -e 's/\$/\\$/' )"
- echo "s|$varname|$varvalue|;" >> "$script"
- done
- done
- echo "s|__CODENAME__|$CODENAME|;" >> "$script"
- echo "s|__VERSION__|$(get_version)|;" >> "$script"
- perl -wp "$script" || die "expand_variables failed"
- rm "$script"
- }
-
- get_version() {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- local version=$VERSION
- local prerl=$PRERELEASE
- grep ":" <<<"$prerl" && warn "colon in PRERELEASE may corrupt version data: $prerl"
- if git rev-parse HEAD >&/dev/null;
- then
- local lasttag=$(git tag | grep ^v | sort -V | tail -n1)
- 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 "$lasttag" && version=${lasttag: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"
- }
|