diff --git a/Makefile b/Makefile index 5d54f78..30f4251 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,7 @@ dist: $(PACKAGE)-$(VERSION)/doc/scripts/gettext.sh \ $(PACKAGE)-$(VERSION)/doc/scripts/gtkdoc.sh \ $(PACKAGE)-$(VERSION)/doc/scripts/pkgconfig.sh \ + $(PACKAGE)-$(VERSION)/doc/scripts/subst.sh \ $(PACKAGE)-$(VERSION)/doc/scripts/project.conf \ $(PACKAGE)-$(VERSION)/src/configure.c \ $(PACKAGE)-$(VERSION)/src/makefile.c \ diff --git a/doc/scripts/Makefile b/doc/scripts/Makefile index ed460a5..f1c6eb8 100644 --- a/doc/scripts/Makefile +++ b/doc/scripts/Makefile @@ -22,6 +22,8 @@ install: $(INSTALL) -m 0644 -- gtkdoc.sh $(DESTDIR)$(PREFIX)/share/doc/configure/scripts/gtkdoc.sh $(MKDIR) $(DESTDIR)$(PREFIX)/share/doc/configure/scripts $(INSTALL) -m 0644 -- pkgconfig.sh $(DESTDIR)$(PREFIX)/share/doc/configure/scripts/pkgconfig.sh + $(MKDIR) $(DESTDIR)$(PREFIX)/share/doc/configure/scripts + $(INSTALL) -m 0644 -- subst.sh $(DESTDIR)$(PREFIX)/share/doc/configure/scripts/subst.sh uninstall: $(RM) -- $(DESTDIR)$(PREFIX)/share/doc/configure/scripts/appbroker.sh @@ -29,5 +31,6 @@ uninstall: $(RM) -- $(DESTDIR)$(PREFIX)/share/doc/configure/scripts/gettext.sh $(RM) -- $(DESTDIR)$(PREFIX)/share/doc/configure/scripts/gtkdoc.sh $(RM) -- $(DESTDIR)$(PREFIX)/share/doc/configure/scripts/pkgconfig.sh + $(RM) -- $(DESTDIR)$(PREFIX)/share/doc/configure/scripts/subst.sh .PHONY: all clean distclean install uninstall diff --git a/doc/scripts/project.conf b/doc/scripts/project.conf index d149e34..09691fb 100644 --- a/doc/scripts/project.conf +++ b/doc/scripts/project.conf @@ -1,4 +1,4 @@ -dist=Makefile,appbroker.sh,docbook.sh,gettext.sh,gtkdoc.sh,pkgconfig.sh +dist=Makefile,appbroker.sh,docbook.sh,gettext.sh,gtkdoc.sh,pkgconfig.sh,subst.sh [appbroker.sh] install=$(PREFIX)/share/doc/configure/scripts @@ -14,3 +14,6 @@ install=$(PREFIX)/share/doc/configure/scripts [pkgconfig.sh] install=$(PREFIX)/share/doc/configure/scripts + +[subst.sh] +install=$(PREFIX)/share/doc/configure/scripts diff --git a/doc/scripts/subst.sh b/doc/scripts/subst.sh new file mode 100755 index 0000000..8f89d87 --- /dev/null +++ b/doc/scripts/subst.sh @@ -0,0 +1,102 @@ +#!/bin/sh +#$Id$ +#Copyright (c) 2012 Pierre Pronchery +#This program is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, version 3 of the License. +# +#This program is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. +# +#You should have received a copy of the GNU General Public License +#along with this program. If not, see . + + + +#variables +PREFIX="/usr/local" +[ -f "../config.sh" ] && . "../config.sh" +CHMOD="chmod" +DEBUG="_debug" +DEVNULL="/dev/null" +INSTALL="install -m 0755" +MKDIR="mkdir -m 0755 -p" +RM="rm -f" +SED="sed" + + +#functions +#debug +_debug() +{ + echo $@ 1>&2 + $@ +} + + +#usage +_usage() +{ + echo "Usage: subst.sh [-i|-u][-P prefix] target" 1>&2 + return 1 +} + + +#main +install=0 +uninstall=0 +while getopts iuP: name; do + case $name in + i) + uninstall=0 + install=1 + ;; + u) + install=0 + uninstall=1 + ;; + P) + PREFIX="$2" + ;; + ?) + _usage + exit $? + ;; + esac +done +shift $(($OPTIND - 1)) +if [ $# -eq 0 ]; then + _usage + exit $? +fi + +BINDIR="$PREFIX/bin" +while [ $# -gt 0 ]; do + target="$1" + shift + + #uninstall + if [ "$uninstall" -eq 1 ]; then + $DEBUG $RM -- "$BINDIR/$target" || exit 2 + continue + fi + + #install + if [ "$install" -eq 1 ]; then + $DEBUG $MKDIR -- "$BINDIR" || exit 2 + $DEBUG $INSTALL "$target" "$BINDIR/$target" || exit 2 + continue + fi + + #create + $DEBUG $SED -e "s,@PREFIX@,$PREFIX," \ + -e "s,@VERSION@,$VERSION," "$target.in" > "$target" + if [ $? -ne 0 ]; then + $RM -- "$target" 2> "$DEVNULL" + exit 2 + elif [ -x "$target.in" ]; then + $DEBUG $CHMOD +x "$target" + fi +done