make CFLAGS="${MAKE_CFLAGS}" CXXFLAGS="${MAKE_CXXFLAGS}" LDFLAGS="${MAKE_LDFLAGS}"
make install
-# Build shared ANTLR library
-
-# On some systems the library may be installed to lib64/ instead of lib/
-LIB_DIR="$(dirname "$(find "$INSTALL_DIR" -name libantlr3c.a)")"
+# Find and move the static build
+rename_installed_lib "libantlr3c.a" "libantlr3c-static.a"
-mv "$LIB_DIR/libantlr3c.a" "$LIB_DIR/libantlr3c-static.a"
+# Build shared ANTLR library
make clean
./configure --with-pic --disable-antlrdebug --prefix="$INSTALL_DIR" $ANTLR_CONFIGURE_ARGS $BUILD_TYPE
sed 's,^\(CFLAGS = .*\),\1 -fexceptions,' Makefile.orig > Makefile
make CFLAGS="${MAKE_CFLAGS}" CXXFLAGS="${MAKE_CXXFLAGS}" LDFLAGS="${MAKE_LDFLAGS}"
make install
-mv "$LIB_DIR/libantlr3c.la" "$LIB_DIR/libantlr3c.la.orig"
+rename_installed_lib "libantlr3c.la" "libantlr3c.la.orig"
+LIB_DIR=$(guess_lib_dir "libantlr3c.la.orig")
awk '/^old_library=/ {print "old_library='\''libantlr3c-static.a'\''"} /^library_names=/ {print "library_names='\''libantlr3c.a'\''"} !/^old_library=/ && !/^library_names=/ {print}' < "$LIB_DIR/libantlr3c.la.orig" > "$LIB_DIR/libantlr3c.la"
rm "$LIB_DIR/libantlr3c.la.orig"
./configure --without-pic --prefix="$INSTALL_DIR" --disable-shared --enable-static --disable-dependency-tracking
make install -j$(nproc)
make distclean
-mv "$INSTALL_LIB_DIR/libglpk.a" "$INSTALL_LIB_DIR/libglpk-static.a"
+
+# Find and move the static build
+rename_installed_lib "libglpk.a" "libglpk-static.a"
./configure --with-pic --prefix="$INSTALL_DIR" --disable-shared --enable-static --disable-dependency-tracking
make install -j$(nproc)
[ ! -d "$INSTALL_BIN_DIR" ] && mkdir -p "$INSTALL_BIN_DIR"
cp "$1" "$INSTALL_BIN_DIR"
}
+
+function guess_lib_dir
+{
+ #
+ # On some systems the library may be installed to lib64/
+ # instead of lib/
+ #
+ # This function guesses the install lib directory
+ #
+ lib_name="$1"
+ lib_dir="$(dirname "$(find "$INSTALL_DIR" -name "${lib_name}")")"
+ echo ${lib_dir}
+}
+
+function rename_installed_lib
+{
+ #
+ # This function uses the calculated library directory and
+ # then relocates the first argument to the second.
+ #
+ src="$1"
+ dest="$2"
+ lib_dir="$(guess_lib_dir "$src")"
+ mv "$lib_dir/$src" "$lib_dir/$dest"
+}
+