*** empty log message ***
[h316.git] / lib / fortran / buildlib.sh
diff --git a/lib/fortran/buildlib.sh b/lib/fortran/buildlib.sh
new file mode 100755 (executable)
index 0000000..0341691
--- /dev/null
@@ -0,0 +1,84 @@
+#!/bin/bash
+
+# Here we find the recipes for the libraries.
+RECIPE_DIR=recipe
+
+# And their file suffix
+RECIPE_SUFFIX=.recipe
+
+# Here go the new libraries
+OUTPUT_DIR=./lib
+
+# This is needed as end-of-tape block for the loader
+ENDBLOCK=$H316/snippets/endseq
+
+# Where to get the original libraries:
+ORG_LIBDIR=original
+
+# And where to store the original objects
+ORG_OBJDIR=org
+
+# The suffix for library files (in and out)
+LIB_SUFFIX=.lib
+#######################################################################
+
+
+# Clean everything up
+clean() {
+    rm -rf $OUTPUT_DIR $ORG_OBJDIR
+}
+
+# Generate org directory containing the original library objects
+make_org() {
+    if [ ! -d "$ORG_OBJDIR" ]; then
+       mkdir  $ORG_OBJDIR
+    fi
+    tdir=$PWD
+    cd $ORG_OBJDIR
+    cat $tdir/$ORG_LIBDIR/*$LIB_SUFFIX | ldc -s
+    cd $tdir
+}
+
+genlib(){
+    echo "Library Builder start."
+    if [ ! -d "$OUTPUT_DIR" ]; then
+       echo -n "Creating $OUTPUT_DIR:"
+       mkdir  $OUTPUT_DIR && echo "Ok." || echo "FAILED!"
+    fi
+    
+    
+    
+    RECIPE_LIST=`ls $RECIPE_DIR/*$RECIPE_SUFFIX`
+    for recipe in $RECIPE_LIST; do
+       lib=$OUTPUT_DIR/`basename $recipe $RECIPE_SUFFIX`$LIB_SUFFIX
+       echo "Building $lib:"
+       rm -f $lib
+       for item in `cat $recipe`; do
+           echo "appending $item."
+           cat $item >> $lib || (echo "Error! could not find:$item")
+        done   
+           cat $ENDBLOCK >> $lib
+    done
+}
+    
+
+case $1 in
+    clean)
+       echo "Clean!"
+       clean
+    ;;
+    makeorg)
+       echo "Make org!"
+       make_org
+    ;;
+    lib)
+       echo "Build Lib!"
+       genlib
+    ;;
+    *)
+       clean
+       make_org
+       genlib
+    ;;
+esac
+