#!/bin/bash # Simple library build script. # # Author: Lars T. Kyllingstad, public@kyllingen.net # Licence: WTFPL # Disclaimer: You use this script at your own risk. Under no # circumstances shall the author be held responsible # for any consequences of your use of the script. ME=`basename "$0"` # Change to suit your preferences PREFIX="/usr/local" WRKDIR=".$ME" # Read arguments CMD="$1" shift SRCDIR="$1" shift DMDOPTS="$@" # Locate source files and directories LIBFILE="lib$SRCDIR.a" LIBPATH="$WRKDIR/$LIBFILE" HDRDIR="$WRKDIR/$SRCDIR" # Locate target directories SYSLIBDIR="$PREFIX/lib" SYSINCDIR="$PREFIX/include/d" # If no arguments are given, show help if [ -z "$CMD" ]; then echo "Usage:" echo " $ME build [DMD options] -- Build a library" echo " $ME install -- Install a library" echo " $ME remove -- Uninstall a library" echo " $ME clean -- Clean up after build process" exit fi # Operation: Remove temporary directory if [ "$CMD" == "clean" ]; then rm -r "$WRKDIR" exit fi # Check if a library name is given. if [ -z "$SRCDIR" ]; then echo "$ME: $CMD which library?" exit fi # Operation: Remove installed library. if [ "$CMD" == remove ]; then rm "$SYSLIBDIR/$LIBFILE" rm -r "$SYSINCDIR/$SRCDIR" exit fi # Find source files. if [ ! -d "$SRCDIR" ]; then echo "$ME: source directory '$SRCDIR' not found." exit 1 fi SOURCES=`find $SRCDIR | grep '\.d$' | grep -v '\.svn'` # Operation: Install library and include files. if [ "$CMD" == "install" ]; then if [ ! -f "$LIBPATH" ]; then echo "$ME: library file '$LIBFILE' not found." exit 1 fi mkdir -p -m 0755 "$SYSLIBDIR" "$SYSINCDIR" install -p -m 0644 "$LIBPATH" "$SYSLIBDIR" cp -r $HDRDIR "$SYSINCDIR" exit fi # Operation: Build library. if [ "$CMD" == "build" ]; then dmd $SOURCES -lib -od$WRKDIR -of$LIBFILE $DMDOPTS cp -r --parents $SOURCES "$WRKDIR/" exit fi echo "$ME: invalid command: $CMD" exit 2