From 30d2b031992eeb46eceda25093692419ee6ec449 Mon Sep 17 00:00:00 2001 From: dbs Date: Fri, 29 Jan 2010 03:16:51 +0000 Subject: [PATCH] Forward-port Dan McMahill's portability patches r1907 and r1908 Improve support for building, compiling, and running OpenSRF on non-Linux distributions such as NetBSD. git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1909 9efc2488-bf62-4759-914b-345cdb29e865 --- bin/osrf_config.in | 36 +++++++-------- bin/osrf_ctl.sh.in | 91 +++++++++++++++++++------------------- configure.ac | 10 ++--- src/Makefile.am | 15 ++++--- src/c-apps/Makefile.am | 11 +++-- src/c-apps/timejson.c | 5 ++- src/libopensrf/Makefile.am | 4 +- 7 files changed, 91 insertions(+), 81 deletions(-) diff --git a/bin/osrf_config.in b/bin/osrf_config.in index a61bfe8..5002b04 100644 --- a/bin/osrf_config.in +++ b/bin/osrf_config.in @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # Copyright (C) 2008 Equinox Software, Inc. # Kevin Beswick @@ -20,7 +20,7 @@ prefix=@prefix@ exec_prefix=@exec_prefix@ datarootdir=@datarootdir@ -function showInstalled { +showInstalled() { JAVA=@OSRF_INSTALL_JAVA@ PYTHON=@OSRF_INSTALL_PYTHON@ if test "$JAVA" = "true"; then @@ -31,7 +31,7 @@ function showInstalled { fi } -function showAll { +showAll() { echo @PACKAGE_STRING@ echo PREFIX=@prefix@ echo BINDIR=@bindir@ @@ -48,7 +48,7 @@ function showAll { showInstalled; } -function showHelp { +showHelp() { echo echo "------------------------------------------------------------" echo " osrf_config " @@ -77,53 +77,53 @@ function showHelp { case "$1" in --installed) - showInstalled; + showInstalled ;; --cconfig) cconfig; ;; --libxml) - echo @LIBXML2_HEADERS@; + echo @LIBXML2_HEADERS@ ;; --apr) - echo @APR_HEADERS@; + echo @APR_HEADERS@ ;; --apache) - echo @APACHE2_HEADERS@; + echo @APACHE2_HEADERS@ ;; --prefix) echo @prefix@ ;; --version) - echo @PACKAGE_STRING@; + echo @PACKAGE_STRING@ ;; --bindir) echo @bindir@ ;; --libdir) - echo @libdir@; + echo @libdir@ ;; --sysconfdir) - echo @sysconfdir@; + echo @sysconfdir@ ;; --localstatedir) - echo @localstatedir@; + echo @localstatedir@ ;; --tmpdir) - echo @TMP@; + echo @TMP@ ;; --apxs) - echo @APXS2@; + echo @APXS2@ ;; --includedir) - echo @includedir@; + echo @includedir@ ;; --docdir) - echo @docdir@; + echo @docdir@ ;; --help) - showHelp; + showHelp ;; *) - showAll; + showAll ;; esac diff --git a/bin/osrf_ctl.sh.in b/bin/osrf_ctl.sh.in index 625b7a3..b1a10df 100755 --- a/bin/osrf_ctl.sh.in +++ b/bin/osrf_ctl.sh.in @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -28,40 +28,41 @@ OSRF_HOSTNAME="" [ $(whoami) != 'opensrf' ] && echo 'Must run as user "opensrf"' && exit; -function usage { - echo ""; - echo "usage: $0 [OPTION]... -c -a "; - echo ""; - echo "Mandatory parameters:"; - echo -e " -a\t\taction to perform"; - echo ""; - echo "Optional parameters:"; - echo -e " -c\t\tfull path to C configuration file (opensrf_core.xml)"; - echo -e " -d\t\tstore PID files in this directory"; - echo -e " -l\t\taccept 'localhost' as the fully-qualified domain name"; - echo ""; - echo "Actions include:"; - echo -e "\tstart_router" - echo -e "\tstop_router" - echo -e "\trestart_router" - echo -e "\tstart_perl" - echo -e "\tstop_perl" - echo -e "\trestart_perl" - echo -e "\tstart_c" - echo -e "\tstop_c" - echo -e "\trestart_c" - echo -e "\tstart_osrf" - echo -e "\tstop_osrf" - echo -e "\trestart_osrf" - echo -e "\tstop_all" - echo -e "\tstart_all" - echo -e "\trestart_all" - echo ""; - echo "Examples:"; - echo " $0 -a restart_all"; - echo " $0 -l -c opensrf_core.xml -a restart_all"; - echo ""; - exit; +usage() { + cat << EOF + +usage: $0 [OPTION]... -c -a + +Mandatory parameters: + -a action to perform + +Optional parameters:"; + -c full path to C configuration file (opensrf_core.xml) + -d store PID files in this directory + -l accept 'localhost' as the fully-qualified domain name + +Actions include: + start_router + stop_router + restart_router + start_perl + stop_perl + restart_perl + start_c + stop_c + restart_c + start_osrf + stop_osrf + restart_osrf + stop_all + start_all + restart_all + +Examples: + $0 -a restart_all + $0 -l -c opensrf_core.xml -a restart_all + +EOF } # --------------------------------------------------------------------------- @@ -96,13 +97,13 @@ PID_OSRF_C="$OPT_PID_DIR/osrf_c.pid"; # --------------------------------------------------------------------------- # Utility code for checking the PID files # --------------------------------------------------------------------------- -function do_action { +do_action() { action="$1"; pidfile="$2"; item="$3"; - if [ $action == "start" ]; then + if [ $action = "start" ]; then if [ -e $pidfile ]; then pid=$(cat $pidfile); @@ -112,7 +113,7 @@ function do_action { echo "Starting $item"; fi; - if [ $action == "stop" ]; then + if [ $action = "stop" ]; then if [ ! -e $pidfile ]; then echo "$item not running"; @@ -138,7 +139,7 @@ function do_action { # --------------------------------------------------------------------------- -function start_router { +start_router() { do_action "start" $PID_ROUTER "OpenSRF Router"; opensrf_router $OPT_CONFIG routers sleep 2; # give the router procs time to fork and appear in ps @@ -147,28 +148,28 @@ function start_router { return 0; } -function stop_router { +stop_router() { do_action "stop" $PID_ROUTER "OpenSRF Router"; return 0; } -function start_perl { +start_perl() { echo "Starting OpenSRF Perl"; opensrf-perl.pl --verbose --pid-dir $OPT_PID_DIR \ --config $OPT_CONFIG --action start_all --settings-startup-pause 3 return 0; } -function stop_perl { +stop_perl() { echo "Stopping OpenSRF Perl"; opensrf-perl.pl --verbose --pid-dir $OPT_PID_DIR --config $OPT_CONFIG --action stop_all sleep 1; return 0; } -function start_c { +start_c() { host=$OSRF_HOSTNAME - if [ "_$host" == "_" ]; then + if [ "_$host" = "_" ]; then host=$(perl -MNet::Domain=hostfqdn -e 'print hostfqdn()'); fi; @@ -180,7 +181,7 @@ function start_c { return 0; } -function stop_c { +stop_c() { do_action "stop" $PID_OSRF_C "OpenSRF C"; sleep 1; return 0; diff --git a/configure.ac b/configure.ac index 00bcddc..c7ad418 100644 --- a/configure.ac +++ b/configure.ac @@ -254,10 +254,10 @@ if test "x$OSRF_INSTALL_CORE" = "xtrue"; then # Checks for libraries. #----------------------------- - AC_CHECK_LIB([dl], [dlerror], [],AC_MSG_ERROR(***OpenSRF requires libdl)) - AC_CHECK_LIB([ncurses], [initscr], [], AC_MSG_ERROR(***OpenSRF requires ncurses headers)) - AC_CHECK_LIB([readline], [readline], [], AC_MSG_ERROR(***OpenSRF requires readline headers)) - AC_CHECK_LIB([xml2], [xmlAddID], [], AC_MSG_ERROR(***OpenSRF requires libxml2 headers)) + AC_SEARCH_LIBS([dlerror], [dl], [],AC_MSG_ERROR([***OpenSRF requires a library (typically libdl) that provides dlerror()])) + AC_CHECK_LIB([ncurses], [initscr], [], AC_MSG_ERROR(***OpenSRF requires ncurses development headers)) + AC_CHECK_LIB([readline], [readline], [], AC_MSG_ERROR(***OpenSRF requires readline development headers)) + AC_CHECK_LIB([xml2], [xmlAddID], [], AC_MSG_ERROR(***OpenSRF requires xml2 development headers)) # Check for libmemcached and set flags accordingly PKG_CHECK_MODULES(memcached, libmemcached >= 0.8.0) AC_SUBST(memcached_CFLAGS) @@ -293,7 +293,7 @@ if test "x$OSRF_INSTALL_CORE" = "xtrue"; then AC_FUNC_STRFTIME AC_FUNC_STRTOD AC_FUNC_VPRINTF - AC_CHECK_FUNCS([bzero dup2 gethostbyname gethostname gettimeofday memset select socket strcasecmp strchr strdup strerror strncasecmp strndup strrchr strtol]) + AC_CHECK_FUNCS([bzero dup2 gethostbyname gethostname gettimeofday malloc_stats memset select socket strcasecmp strchr strdup strerror strncasecmp strndup strrchr strtol]) #------------------------------------ # Configuration and output diff --git a/src/Makefile.am b/src/Makefile.am index 9dabbaf..ad03526 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -59,12 +59,15 @@ install-exec-local: mkdir -p $(SOCK) install-exec-hook: - if [ "$(MAYBE_CORE)" ]; then sed -i 's|LOCALSTATEDIR|$(VAR)|g' '$(DESTDIR)@sysconfdir@/opensrf.xml.example' && \ - sed -i 's|SYSCONFDIR|$(ETCDIR)|g' '$(DESTDIR)@sysconfdir@/opensrf.xml.example' && \ - sed -i 's|LOCALSTATEDIR|$(VAR)|g' '$(DESTDIR)@sysconfdir@/opensrf_core.xml.example' && \ - sed -i 's|SYSCONFDIR|$(ETCDIR)|g' '$(DESTDIR)@sysconfdir@/opensrf_core.xml.example' && \ - sed -i 's|LOCALSTATEDIR|$(VAR)|g' '$(DESTDIR)@sysconfdir@/srfsh.xml.example' && \ - sed -i 's|SYSCONFDIR|$(ETCDIR)|g' '$(DESTDIR)@sysconfdir@/srfsh.xml.example'; fi + if [ "$(MAYBE_CORE)" ]; then \ + for f in opensrf.xml.example opensrf_core.xml.example srfsh.xml.example ; do \ + mv "$(DESTDIR)@sysconfdir@/$${f}" "$(DESTDIR)@sysconfdir@/$${f}.bak" ; \ + sed -e 's|LOCALSTATEDIR|$(VAR)|g' -e 's|SYSCONFDIR|$(ETCDIR)|g' \ + "$(DESTDIR)@sysconfdir@/$${f}.bak" > "$(DESTDIR)@sysconfdir@/$${f}" ; \ + rm "$(DESTDIR)@sysconfdir@/$${f}.bak" ; \ + done; \ + fi + cp -r @srcdir@/javascript/* $(jsdir)/ uninstall-hook: rm -f @includedir@/opensrf/apachetools.h diff --git a/src/c-apps/Makefile.am b/src/c-apps/Makefile.am index 49c3d20..4305852 100644 --- a/src/c-apps/Makefile.am +++ b/src/c-apps/Makefile.am @@ -21,13 +21,16 @@ noinst_PROGRAMS = timejson lib_LTLIBRARIES = osrf_dbmath.la osrf_math.la osrf_version.la timejson_SOURCES = timejson.c -timejson_LDADD = -lopensrf +timejson_LDADD = @top_builddir@/src/libopensrf/libopensrf.la + osrf_dbmath_la_SOURCES = osrf_dbmath.c osrf_dbmath_la_LDFLAGS = $(AM_LDFLAGS) -module -osrf_dbmath_la_LIBADD = -lopensrf +osrf_dbmath_la_LIBADD = @top_builddir@/src/libopensrf/libopensrf.la + osrf_math_la_SOURCES = osrf_math.c osrf_math_la_LDFLAGS = $(AM_LDFLAGS) -module -osrf_math_la_LIBADD = -lopensrf +osrf_math_la_LIBADD = @top_builddir@/src/libopensrf/libopensrf.la + osrf_version_la_SOURCES = osrf_version.c osrf_version_la_LDFLAGS = $(AM_LDFLAGS) -module -osrf_version_la_LIBADD = -lopensrf +osrf_version_la_LIBADD = @top_builddir@/src/libopensrf/libopensrf.la diff --git a/src/c-apps/timejson.c b/src/c-apps/timejson.c index 009b50e..c0ab46e 100644 --- a/src/c-apps/timejson.c +++ b/src/c-apps/timejson.c @@ -57,8 +57,11 @@ int main( void ) { else printf( "Address space: %lu\n", (unsigned long) rlim.rlim_cur ); +#ifdef HAVE_MALLOC_STATS malloc_stats(); - +#else + fprintf(stderr, "malloc_stats() is not available on your system\n"); +#endif return rc; } diff --git a/src/libopensrf/Makefile.am b/src/libopensrf/Makefile.am index 1cc92bf..c2429a5 100644 --- a/src/libopensrf/Makefile.am +++ b/src/libopensrf/Makefile.am @@ -1,4 +1,4 @@ -# Copyright (C) 2008 Equinox Software, Inc. +# Copyright (C) 2008-2010 Equinox Software, Inc., and others # Kevin Beswick # # This program is free software; you can redistribute it and/or @@ -14,7 +14,7 @@ AM_CFLAGS = $(DEF_CFLAGS) -DASSUME_STATELESS -DOSRF_STRICT_PARAMS -rdynamic -fno-strict-aliasing -DOSRF_JSON_ENABLE_XML_UTILS AM_LDFLAGS = $(DEF_LDFLAGS) -R $(libdir) -LDADD = -lxml2 -ldl -lopensrf +LDADD = -lopensrf DISTCLEANFILES = Makefile.in Makefile -- 2.43.2