Commit ad7d6d73 authored by Karl Wette's avatar Karl Wette

Add utilities for printing version information to all LAL libraries

- Use common source file generated from lal/src/version.c.in
- LAL: rename lal-version to lal_version for consistency with LALApps's
  use of _, and rename lal-simd-detect to lal_simd_detect for consistency
- LAL: Remove LALVersion.[ch], use XLALPerror() instead of LALVersion()
  in LALSUITE_CHECK_LIB() Autoconf macro calls
- LALApps: name file version2.c instead of version.c, since changing
  a file which used to be in the source tree to a file generated in
  the build directory can confuse the build system (VPATH, .deps/*.Po)
- Refs #4801
Original: a586b5d59398e0366d969446a0d6756d9581f483
parent a39b051d
......@@ -50,10 +50,11 @@ src/config.h
src/config.h.in
src/fft/CudaFFT.cpp
src/git_version
src/lal-simd-detect
src/lal-version
src/lal_simd_detect
src/lal_version
src/stamp-h1
src/stamp-h2
src/version.c
swig/swiglal*
test/*/*.dat
test/*/*.out
......@@ -92,7 +93,6 @@ test/std/LALGSLTest
test/std/LALMallocPerf
test/std/LALMallocTest
test/std/LALStringTest
test/std/LALVersionTest
test/std/StringConvertTest
test/support/ConfigFileTest
test/support/GzipTest
......
......@@ -34,6 +34,7 @@ AC_CONFIG_FILES([ \
src/tools/Makefile \
src/utilities/Makefile \
src/vectorops/Makefile \
src/version.c \
src/window/Makefile \
swig/Makefile \
test/Makefile \
......
usr/bin/lal-version
usr/bin/lal-simd-detect
usr/bin/lal_version
usr/bin/lal_simd_detect
etc/lal-user-env.*
usr/lib/*/*.so.*
#usr/share/lal
......@@ -89,8 +89,8 @@ rm -Rf ${RPM_BUILD_DIR}/%{name}-%{version}
%files
%defattr(-,root,root)
%{_bindir}/lal-simd-detect
%{_bindir}/lal-version
%{_bindir}/lal_simd_detect
%{_bindir}/lal_version
%{_libdir}/*.so.*
%{_sysconfdir}/lal-user-env.*
......
......@@ -70,11 +70,14 @@ build_info_dependencies = $(liblal_la_DEPENDENCIES)
LDADD = liblal.la
bin_PROGRAMS = \
lal-simd-detect \
lal-version \
lal_simd_detect \
lal_version \
$(END_OF_LIST)
lal_simd_detect_SOURCES = lal-simd-detect.c
lal_version_SOURCES = lal-version.c
lal_simd_detect_SOURCES = simd_detect.c
lal_version_SOURCES = version.c
TESTS = $(bin_PROGRAMS)
TESTS = \
lal_simd_detect \
lal_version \
$(END_OF_LIST)
/*
* Copyright (C) 2007 Jolien Creighton
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with with program; see the file COPYING. If not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
/**
* \file
* \author Jolien Creighton
* \brief Prints the version and configure options of the LAL library being used.
*
* ### Usage ###
*
* \code
* lal-version
* \endcode
*
* ### Description ###
*
* This program prints the current version of LAL.\@ If the version information
* in the library differs from the version information in the header file, this
* program prints the two versions and exits with code 1. This is useful for
* determining which version of the LAL library and header files you are linking
* to.
*
* ### Exit codes ###
*
* <table><tr><th> Code</th><th>Explanation</th></tr>
* <tr><td> 0</td><td>Success, normal exit.</td></tr>
* <tr><td> 1</td><td>Version info in library disagrees with header file.</td></tr>
* <tr><td> 2</td><td>Subroutine failed.</td></tr>
* </table>
*
*/
#include <stdio.h>
#include <string.h>
#include <lal/LALStdlib.h>
#include <lal/LALVersion.h>
int main( void )
{
static LALStatus status;
char msg[16384];
int verbose = 1;
if ( strcmp( LAL_VERSION, lalVersion ) )
{
fputs( "LAL Version Mismatch!\n\n", stderr );
fputs( "Header Version ", stderr );
fputs( LAL_VERSION, stderr );
fputs( "\n\n", stderr );
fputs( "Library Version ", stderr );
fputs( lalVersion, stderr );
fputs( "\n", stderr );
return 1;
}
LALVersion( &status, msg, sizeof( msg ), verbose );
if ( status.statusCode )
{
LALStatus *next = &status;
do
{
fputs( next->statusDescription, stderr );
fputs( "\n", stderr );
next = next->statusPtr;
}
while ( next );
return 2;
}
puts( msg );
return 0;
}
/*
* Copyright (C) 2007 Jolien Creighton
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with with program; see the file COPYING. If not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
/*
*
* Use LAL's config.h file rather than LALConfig.h which may be from some
* previous installation.
*
*/
#include <config.h>
#include <stdio.h>
#include <lal/LALStatusMacros.h>
#include <lal/LALStdio.h>
#include <lal/LALVersion.h>
#include <lal/LALVCSInfo.h>
const char *const lalVersion = LAL_VERSION;
const int lalVersionMajor = LAL_VERSION_MAJOR;
const int lalVersionMinor = LAL_VERSION_MINOR;
const int lalVersionMicro = LAL_VERSION_MICRO;
const int lalVersionDevel = LAL_VERSION_DEVEL;
/**
* \ingroup LALVersion_h
* Routine that returns the version of LAL.
* This function writes a version message into the string buffer of specified
* size (and is truncated if the buffer is too small). Configuration information
* is also provided if the verbose flag is set.
*
*/
void
LALVersion(LALStatus * status, CHAR * message, UINT4 size, INT4 verbose)
{
INT4 nchar;
INITSTATUS(status);
ASSERT(message, status, LALVERSIONH_ENULL, LALVERSIONH_MSGENULL);
ASSERT(size > 0, status, LALVERSIONH_ESIZE, LALVERSIONH_MSGESIZE);
nchar = verbose ?
snprintf(message, size,
"LAL Version: %s\n"
"Git ID: %s\n"
"Git Tag: %s\n"
"Build Date: %s\n"
"Configure Date: %s\n"
"Configure Arguments: %s\n",
lalVersion, lalVCSInfo.vcsId,
lalVCSInfo.vcsTag, lalVCSInfo.buildDate, lalVCSInfo.configureDate,
lalVCSInfo.configureArgs) : snprintf(message, size,
"LAL Version: %s\n",
lalVersion);
if (nchar < 0) {
ABORT(status, LALVERSIONH_ESPRN, LALVERSIONH_MSGESPRN);
}
if (nchar > (INT4) size) {
ABORT(status, LALVERSIONH_ESHRT, LALVERSIONH_MSGESHRT);
}
RETURN(status);
}
/*
* Copyright (C) 2007 Jolien Creighton
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with with program; see the file COPYING. If not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
#ifndef _LALVERSION_H
#define _LALVERSION_H
#include <lal/LALDatatypes.h>
#ifdef __cplusplus
extern "C" {
#elif 0
} /* so that editors will match preceding brace */
#endif
/**
* \defgroup LALVersion_h Header LALVersion.h
* \ingroup lal_std
*
* \brief Provides routines for reporting the LAL version.
*
* ### Synopsis ###
*
* \code
* #include <lal/LALVersion.h>
* \endcode
*
* \section ss_globals Global variables
*
* \code
* extern const char *lalVersion;
* extern const int lalVersionMajor;
* extern const int lalVersionMinor;
* extern const char *lalConfigureArgs;
* extern const char *lalConfigureDate;
* \endcode
*
* These constant variables are set at compile time and included into the LAL
* library. They contain the information about the version of LAL and the
* configuration information.
*
*/
/*@{*/
/**\name Error Codes */ /*@{ */
#define LALVERSIONH_ENULL 1 /**< Null string pointer */
#define LALVERSIONH_ESIZE 2 /**< Zero string size */
#define LALVERSIONH_ESPRN 4 /**< Error in snprintf */
#define LALVERSIONH_ESHRT 8 /**< String too short */
/*@}*/
#define LALVERSIONH_MSGENULL "Null string pointer."
#define LALVERSIONH_MSGESIZE "Zero string size."
#define LALVERSIONH_MSGESPRN "Error in snprintf."
#define LALVERSIONH_MSGESHRT "String too short."
extern const char *const lalVersion;
extern const int lalVersionMajor;
extern const int lalVersionMinor;
extern const int lalVersionMicro;
extern const int lalVersionDevel;
void LALVersion(LALStatus * status, CHAR * message, UINT4 size,
INT4 verbose);
/*@}*/
#if 0
{ /* so that editors will match succeeding brace */
#elif defined(__cplusplus)
}
#endif
#endif /* _LALVERSION_H */
......@@ -16,7 +16,6 @@ pkginclude_HEADERS = \
LALStdlib.h \
LALString.h \
LALVCSInfoType.h \
LALVersion.h \
StringInput.h \
XLALError.h \
XLALGSL.h \
......@@ -33,7 +32,6 @@ libstd_la_SOURCES = \
LALSIMD.c \
LALString.c \
LALVCSInfoType.c \
LALVersion.c \
StringConvert.c \
StringToken.c \
XLALError.c \
......
/*
* Copyright (C) 2016 Karl Wette
* Copyright (C) 2007 Jolien Creighton
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with with program; see the file COPYING. If not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
#include <stdio.h>
#include <config.h>
#include <lal/LALStdlib.h>
#include "@PACKAGE_NAME@VCSInfo.h"
/*
* Utility for printing version information for @PACKAGE_NAME@
*/
int main(int argc, char **argv) {
/* Parse command line */
int verbose = 0;
if ( argc == 2 && ( strcmp( argv[1], "-v" ) == 0 || strcmp( argv[1], "-verbose" ) == 0 || strcmp( argv[1], "--verbose" ) == 0 ) ) {
verbose = 1;
} else if ( argc > 1 ) {
fprintf(stderr,
"Usage: %s [-h|--help] [-v|--verbose]\n"
" --help display this messgage and exit\n"
" --verbose display verbose version information\n",
argv[0]
);
if ( strcmp( argv[1], "-h" ) == 0 || strcmp( argv[1], "-help" ) == 0 || strcmp( argv[1], "--help" ) == 0 ) {
return EXIT_SUCCESS;
} else {
return EXIT_FAILURE;
}
}
/* Print version information */
char *str = XLALVCSInfoString( lal@PACKAGE_NAME_NOLAL@VCSInfoList, verbose, NULL );
XLAL_CHECK_MAIN( str != NULL, XLAL_EFUNC );
fprintf( stdout, "%s", str );
/* Cleanup */
XLALFree( str );
LALCheckMemoryLeaks();
return EXIT_SUCCESS;
}
/*
* Copyright (C) 2007 Bernd Machenschalk, Jolien Creighton
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with with program; see the file COPYING. If not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
/**
* \file
* \ingroup LALVersion_h
*
* \brief Prints the version and configure options of the LAL library being used.
*
* ### Usage ###
*
* \code
* LALVersionTest
* \endcode
*
* ### Description ###
*
* This program prints the current version of LAL.\@ If the version information
* in the library differs from the version information in the header file, this
* program prints the two versions and exits with code 1. This is useful for
* determining which version of the LAL library and header files you are linking
* to.
*
* ### Exit codes ###
*
* <table>
* <tr><th>Code</th><th>Explanation</th></tr>
* <tr><td> 0</td><td>Success, normal exit.</td></tr>
* <tr><td> 1</td><td>Version info in library disagrees with header file.</td></tr>
* <tr><td> 2</td><td>Subroutine failed.</td></tr>
* </table>
*
*/
/** \cond DONT_DOXYGEN */
#include <stdio.h>
#include <string.h>
#include <lal/LALStdlib.h>
#include <lal/LALVersion.h>
int main( void )
{
static LALStatus status;
char msg[16384];
int verbose = 1;
if ( strcmp( LAL_VERSION, lalVersion ) )
{
fputs( "LAL Version Mismatch!\n\n", stderr );
fputs( "Header Version ", stderr );
fputs( LAL_VERSION, stderr );
fputs( "\n\n", stderr );
fputs( "Library Version ", stderr );
fputs( lalVersion, stderr );
fputs( "\n", stderr );
return 1;
}
LALVersion( &status, msg, sizeof( msg ), verbose );
if ( status.statusCode )
{
LALStatus *next = &status;
do
{
fputs( next->statusDescription, stderr );
fputs( "\n", stderr );
next = next->statusPtr;
}
while ( next );
return 2;
}
puts( msg );
return 0;
}
/** \endcond */
......@@ -7,7 +7,6 @@ test_programs += LALGSLTest
test_programs += LALMallocTest
test_programs += LALMallocPerf
test_programs += LALStringTest
test_programs += LALVersionTest
test_programs += StringConvertTest
# Add shell, Python, etc. test scripts to this variable
......
#!/bin/sh
# check for lal-simd-detect
lal_simd_detect="${LAL_TEST_BUILDDIR}/../../src/lal-simd-detect"
# check for lal_simd_detect
lal_simd_detect="${LAL_TEST_BUILDDIR}/../../src/lal_simd_detect"
if test ! -x ${lal_simd_detect}; then
echo "$0: could not execute ${lal_simd_detect}" >&2
exit 1
......
......@@ -153,6 +153,7 @@ src/lalapps/LALAppsBuildInfoHeader.h
src/lalapps/LALAppsVCSInfo.c
src/lalapps/LALAppsVCSInfo.h
src/lalapps/LALAppsVCSInfoHeader.h
src/lalapps/version2.c
src/lalapps/git_version.py
src/lalapps/lalapps_cache
src/lalapps/lalapps_fftw*_wisdom
......
......@@ -23,6 +23,7 @@ AC_CONFIG_FILES([\
src/lalapps/LALAppsVCSInfo.c \
src/lalapps/LALAppsVCSInfo.h \
src/lalapps/Makefile \
src/lalapps/version2.c \
src/online/Makefile \
src/power/Makefile \
src/pulsar/CreateEphemeris/Makefile \
......@@ -375,7 +376,7 @@ if test "${boinc}" = "true" ; then
fi
# check for lal libararies and headers
LALSUITE_CHECK_LIB([LAL],[${MIN_LAL_VERSION}],[LALVersion],[lal/LALStdio.h])
LALSUITE_CHECK_LIB([LAL],[${MIN_LAL_VERSION}],[XLALPerror],[lal/XLALError.h])
LALSUITE_CHECK_LIB([LALSupport],[${MIN_LAL_VERSION}],[XLALCacheImport],[lal/LALCache.h])
LALSUITE_CHECK_OPT_LIB([LALFrame],[${MIN_LALFRAME_VERSION}],[LALFrOpen],[lal/LALFrameL.h])
LALSUITE_CHECK_OPT_LIB([LALMetaIO],[${MIN_LALMETAIO_VERSION}],[XLALCreateMetaTableDir],[lal/LIGOLwXMLRead.h])
......
......@@ -72,7 +72,6 @@ int main(void) {fputs("disabled, no gsl or no lal frame library support.\n", std
#include <lal/ConfigFile.h>
#include <lal/ReadFiltersFile.h>
#include <lal/TimeSeries.h>
#include <lal/LALVersion.h>
#include <lal/LALFrameIO.h>
#include <lal/LALDetectors.h>
#include <lal/Date.h>
......
......@@ -52,14 +52,13 @@ bin_PROGRAMS = \
lalapps_cache \
$(FFTWPROGS)
lalapps_version_SOURCES = \
version.c \
lalapps.h \
LALAppsVCSInfo.h
lalapps_version_SOURCES = version2.c
lalapps_tconvert_SOURCES = \
tconvert.c \
getdate.c \
getdate.h
lalapps_cache_SOURCES = \
cache.c
......@@ -74,7 +73,9 @@ pybin_scripts = \
lalapps_searchsum2cache
endif
TESTS = lalapps_version
TESTS = \
lalapps_version
$(END_OF_LIST)
vcs_build_info_source = LALAppsVCSInfo.c
vcs_info_sources = LALAppsVCSInfoHeader.h git_version.py
......
/*
* Copyright (C) 2007 Jolien Creighton
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with with program; see the file COPYING. If not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
#include "config.h"
#include "LALAppsVCSInfo.h"
#include "lalapps.h"
#include <stdio.h>
#include <stdlib.h>
#include <lal/LALMalloc.h>
#include <lal/LALgetopt.h>
/* program information */
#define PROGRAM_NAME "lalapps_version"
/* verbose flag */
extern int vrbflg;
/* function prototypes */
static void parse_options(int argc, char **argv);
static void print_usage(FILE *ptr, const char *program_name);
/*
* main program entry point
*/
int main(int argc, char **argv)
{
/* setup error handler */
lal_errhandler = LAL_ERR_EXIT;
/* parse command line options */
parse_options(argc, argv);
/* print version information */
XLALOutputVersionString(stderr, vrbflg);
/* clean up and exit */
LALCheckMemoryLeaks();
return 0;
}
/*
* local helper functions
*/
/* parse command line options */
static void parse_options(int argc, char **argv)
{
/* counters */
int c;
/* LALgetopt arguments */
struct LALoption long_options[] =
{
/* options that set a flag */
{"verbose", no_argument, &vrbflg, 1},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
/* initialise vrbflg */
vrbflg = 0;
/* parse the arguments */
while(1)
{
/* LALgetopt_long stores option here */
int option_index = 0;
/* parse options */
c = LALgetopt_long_only(argc, argv, "h", long_options, &option_index);
/* detect the end of the options */
if (c == -1)
break;
switch(c)
{
case 0:
/* if this option sets a flag, do nothing else for now */
if (long_options[option_index].flag != 0)
break;
else
{
fprintf(stderr, "Error parsing option %s with argument %s\n",
long_options[option_index].name, LALoptarg);
exit(1);
}
break;
case 'h':
/* print help message, and exit */
print_usage(stderr, PROGRAM_NAME);
exit(0);
break;
case '?':
print_usage(stderr, PROGRAM_NAME);
exit(1);
break;
default:
fprintf(stderr, "Unknown error while parsing arguments\n");
print_usage(stderr, PROGRAM_NAME);
exit(1);
break;
}
}
/* check for extraneous command line arguments */
if (LALoptind < argc)
{
fprintf(stderr, "Extraneous command line arguments:\n");
while(LALoptind < argc)
fprintf(stderr, "\t%s\n", argv[LALoptind++]);
exit(1);
}
}
/* function to display program usage information */
static void print_usage(FILE *ptr, const char *program_name)
{
/* print usage information */
fprintf(ptr,
"Usage: %s [options]\n"