Blame sofort.sh

f46039
#!/bin/sh
f46039
f46039
usage()
f46039
{
f46039
cat << EOF >&2
f46039
f46039
Usage:
f46039
  -h            show this HELP message
f46039
  -d  DSTDIR    set destination directory
f46039
  -p  PROJECT   set project name (i.e. sofort)
f46039
  -n  PREFIX    set namespace prefix (i.e. sfrt)
f46039
f46039
EOF
f46039
exit 1
f46039
}
f46039
f46039
error_dstdir_exists()
f46039
{
f46039
	echo "the destination directory '$dstdir' already exists!" >&2
f46039
	exit 2
f46039
}
f46039
f46039
# one: args
f46039
dstdir=
f46039
project=
f46039
namespace=
f46039
f46039
srcdir=`dirname $0` || exit 2
f46039
cd "$srcdir" || exit 2
f46039
srcdir=`pwd` || exit 2
f46039
f46039
while getopts "hd:p:n:" opt; do
f46039
	case $opt in
f46039
	h)
f46039
  		usage
f46039
  		;;
f46039
	d)
f46039
    		dstdir="$OPTARG"
f46039
    		;;
f46039
	p)
f46039
    		project="$OPTARG"
f46039
    		;;
f46039
	n)
f46039
    		namespace="$OPTARG"
f46039
    		;;
f46039
	\?)
f46039
    		printf "Invalid option: -%s" "$OPTARG" >&2
f46039
    		usage
f46039
    		;;
f46039
	esac
f46039
done
f46039
f46039
# two: clone
f46039
if [ -z "$dstdir" ] || [ -z "$project" ] || [ -z "$namespace" ]; then
f46039
	usage
f46039
fi
f46039
f46039
stat "$dstdir" >/dev/null 2>/dev/null && error_dstdir_exists
f46039
mkdir -p "$(dirname $dstdir)" || exit 2
f46039
cp -r "$srcdir" "$dstdir" || exit 2
f46039
rm "$dstdir"/sofort.sh || exit 2
8b17a6
rm "$dstdir"/recipiff || exit 2
f46039
rm -rf "$dstdir"/.git || exit 2
f46039
f46039
# three: content
f46039
cd "$dstdir" || exit 2
f46039
files=$(find . -type f)
f46039
lowerspace=`echo "$namespace" | tr '[:upper:]' '[:lower:]'`_
f46039
upperspace=`echo "$namespace" | tr '[:lower:]' '[:upper:]'`_
f46039
f46039
for f in $files; do
f46039
	sed -e s/sofort/$project/g "$f" > "$f.tmp" || exit 2
f46039
	mv "$f.tmp" "$f" || exit 2
f46039
f46039
	sed -e s/sfrt_/$lowerspace/g "$f" > "$f.tmp" || exit 2
f46039
	mv "$f.tmp" "$f" || exit 2
f46039
785098
	sed -e s/SFRT_/$upperspace/g "$f" > "$f.tmp" || exit 2
f46039
	mv "$f.tmp" "$f" || exit 2
f46039
done
f46039
29a0ab
# and also the driver and public headers
29a0ab
files="$dstdir/src/driver/sfrt_driver_ctx.c"
29a0ab
files="$files $dstdir/src/internal/sofort_driver_impl.h"
29a0ab
files="$files $dstdir/include/sofort/sofort.h"
29a0ab
files="$files $dstdir/include/sofort/sofort_api.h"
29a0ab
29a0ab
upperspace=`echo "$project" | tr '[:lower:]' '[:upper:]'`
29a0ab
29a0ab
for f in $files; do
29a0ab
	sed -e s/SOFORT/$upperspace/g "$f" > "$f.tmp" || exit 2
29a0ab
	mv "$f.tmp" "$f" || exit 2
29a0ab
done
29a0ab
9160dd
# and also project/tagver.mk, which has SFRT, not SFRT_
9160dd
f=project/tagver.mk
02d787
upperspace=`echo "$namespace" | tr '[:lower:]' '[:upper:]'`
9160dd
sed -e s/SFRT/$upperspace/g "$f" > "$f.tmp" || exit 2
9160dd
mv "$f.tmp" "$f" || exit 2
9160dd
f46039
# four: directory names
f46039
mv include/sofort include/$project || exit 2
f46039
dirs=$(find . -type d)
f46039
f46039
for d in $dirs; do
66b48c
	case $d in
66b48c
		./sofort | ./sofort/* )
66b48c
			name=$d
66b48c
			;;
66b48c
		* )
66b48c
			name=`echo "$d" | sed -e s/sfrt_/$lowerspace/g \
66b48c
				-e s/sofort/$project/g`
66b48c
			;;
66b48c
	esac
f46039
f46039
	if [ "$d" != "$name" ]; then
f46039
		mv "$d" "$name" || exit 2
f46039
	fi
f46039
done
f46039
f46039
# five: file names
f46039
files=$(find . -type f)
f46039
f46039
for f in $files; do
66b48c
	case $(dirname $f) in
66b48c
		./sofort | ./sofort/* )
66b48c
			name=$f
66b48c
			;;
66b48c
66b48c
		* )
66b48c
			name=`echo "$f" | sed -e s/sfrt_/$lowerspace/g \
66b48c
				-e s/sofort/$project/g`
66b48c
			;;
66b48c
	esac
f46039
f46039
	if [ "$f" != "$name" ]; then
f46039
		mv "$f" "$name" || exit 2
f46039
	fi
f46039
done
f46039
f46039
# six: references
f46039
cp "$srcdir"/COPYING.SOFORT "$dstdir" || exit 2
fb7de2
cp "$srcdir"/src/internal/argv/argv.h "$dstdir"/src/internal/argv || exit 2
f46039
eac92e
# seven: remove howto text and dummy interfaces
eac92e
rm "$dstdir"/HOWTO || exit 2
abc68f
rm "$dstdir"/src/output/* || exit 2
abc68f
abc68f
recipe="$dstdir"/project/common.mk
abc68f
files=$(find . -type f)
abc68f
abc68f
grep -v 'src/output' "$recipe" > "$recipe".tmp || exit 2
abc68f
mv "$recipe".tmp "$recipe" || exit 2
abc68f
abc68f
for f in $files; do
abc68f
	grep -v 'dummy' "$f" > "$f".tmp
abc68f
	mv "$f".tmp "$f" || exit 2
abc68f
done
abc68f
20cc26
# seven: sofort
66b48c
cp -p "$srcdir/configure"   "$dstdir"
66b48c
cp -p "$srcdir/Makefile.in" "$dstdir"
20cc26
abc68f
# eight: finalize
f46039
uppername=`echo "$project" | tr '[:lower:]' '[:upper:]'`
f46039
utilcsrc=src/$project.c
f46039
f46039
sed -e s/SOFORT/$uppername/g $utilcsrc> $utilcsrc.tmp || exit 2
f46039
mv $utilcsrc.tmp $utilcsrc || exit 2
f46039
f46039
touch COPYING.$uppername || exit 2
f46039
echo "$project: project description" > README || exit 2
f46039
f46039
chmod +x sysinfo/version.sh   || exit 2
f46039
chmod +x ./configure          || exit 2
f46039
f46039
# all done
f46039
exit 0