gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master e9e4c5f 1/3: Gnuastro's version is a macro in


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master e9e4c5f 1/3: Gnuastro's version is a macro in the library
Date: Fri, 16 Sep 2016 17:21:30 +0000 (UTC)

branch: master
commit e9e4c5f9e681c1526862b224e9a8fa1986c79f80
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    Gnuastro's version is a macro in the library
    
    Until now, Gnuastro's version was reported by a function declared in
    `gnuastro.h' and defined in `gnuastro.c'. The user would have to define a
    variable, the function would allocate space and pass the pointer to the
    user's variable, and the user would have to free the allocated space: all
    very complicated!
    
    The problem was that in Gnuastro, the version is recorded in
    `config.h'. This file is internal to Gnuastro and can't be installed, so
    the version couldn't directly be used from it. To fix the problem, the
    version is now written in `gnuastro.h' by `lib/Makefile' from
    `lib/gnuastro.h.in'. So any change that is to be added in the final
    `gnuastro.h' has to be implemented in `gnuastro.h.in'. But the great thing
    is that the version is now a macro and can be very easily used.
    
    With the change of this function, the tests (which currently only report
    the version) also had to be re-written.
---
 lib/Makefile.am          |   40 ++++++++++++++++++++------------
 lib/gnuastro.c           |   42 ----------------------------------
 lib/gnuastro/gnuastro.h  |   57 ----------------------------------------------
 tests/Makefile.am        |    9 ++++++++
 tests/lib/versionc.c     |   11 +--------
 tests/lib/versioncpp.cpp |    5 +---
 6 files changed, 37 insertions(+), 127 deletions(-)

diff --git a/lib/Makefile.am b/lib/Makefile.am
index 08babe1..549e2f0 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -31,33 +31,42 @@ libgnuastro_la_LDFLAGS = -version-info $(GAL_LT_VERSION)
 
 
 # Specify the library .c files
+BUILT_SOURCES = gnuastro/gnuastro.h
 libgnuastro_la_SOURCES = array.c box.c checkset.c configfiles.c fits.c  \
-  gnuastro.c linkedlist.c mesh.c mode.c polygon.c qsort.c               \
-  spatialconvolve.c statistics.c threads.c timing.c txtarray.c wcs.c
+  linkedlist.c mesh.c mode.c polygon.c qsort.c spatialconvolve.c        \
+  statistics.c threads.c timing.c txtarray.c wcs.c
 
 
 # Specify the installed headers, note that we are not blindly including all
 # `.h' files in the $(headersdir) directory. Some of the header files don't
 # need to be installed.
 headersdir=$(top_srcdir)/lib/gnuastro
-pkginclude_HEADERS = $(headersdir)/array.h $(headersdir)/box.h             \
-  $(headersdir)/checkset.h $(headersdir)/configfiles.h                     \
-  $(headersdir)/fits.h $(headersdir)/gnuastro.h $(headersdir)/linkedlist.h \
-  $(headersdir)/mesh.h $(headersdir)/mode.h $(headersdir)/polygon.h        \
-  $(headersdir)/qsort.h $(headersdir)/spatialconvolve.h                        
   \
-  $(headersdir)/statistics.h $(headersdir)/threads.h                       \
-  $(headersdir)/timing.h $(headersdir)/txtarray.h $(headersdir)/wcs.h
+pkginclude_HEADERS = gnuastro/gnuastro.h $(headersdir)/array.h             \
+  $(headersdir)/box.h $(headersdir)/checkset.h $(headersdir)/configfiles.h \
+  $(headersdir)/fits.h $(headersdir)/linkedlist.h $(headersdir)/mesh.h     \
+  $(headersdir)/mode.h $(headersdir)/polygon.h $(headersdir)/qsort.h       \
+  $(headersdir)/spatialconvolve.h $(headersdir)/statistics.h               \
+  $(headersdir)/threads.h $(headersdir)/timing.h $(headersdir)/txtarray.h  \
+  $(headersdir)/wcs.h
 
 
 # Definitions for Gnuastro's the pkg-config file (inspired from GSL's
 # Makefile.am)
-CLEANFILES = gnuastro.pc
-EXTRA_DIST = gnuastro.pc.in
 pkgconfig_DATA = gnuastro.pc
 pkgconfigdir = $(libdir)/pkgconfig
+EXTRA_DIST = gnuastro.pc.in gnuastro.h.in
+CLEANFILES = gnuastro.pc gnuastro/gnuastro.h
+
+
+# Build Gnuastro's pkg-config file and `gnuastro.h' based on the
+# information in the Makefile after the Makefile has been built.
+gnuastro/gnuastro.h: Makefile gnuastro.h.in
+       rm -f $@ address@hidden
+       $(MKDIR_P) gnuastro
+       $(SED) -e 's|@address@hidden|$(VERSION)|g' $(srcdir)/gnuastro.h.in >> 
address@hidden
+       chmod a-w address@hidden
+       mv address@hidden $@
 
-# Build Gnuastro's pkg-config file based on the information in the
-# Makefile after the Makefile has been built.
 gnuastro.pc: Makefile $(srcdir)/gnuastro.pc.in
        rm -f $@ address@hidden
        $(SED)                                      \
@@ -67,6 +76,9 @@ gnuastro.pc: Makefile $(srcdir)/gnuastro.pc.in
        -e 's|@address@hidden|$(includedir)|g'       \
        -e 's|@address@hidden|$(LIBS)|g'                   \
        -e 's|@address@hidden|$(VERSION)|g'             \
-       '$(srcdir)/address@hidden' >>address@hidden
+       '$(srcdir)/address@hidden' >> address@hidden
        chmod a-w address@hidden
        mv address@hidden $@
+
+clean-local:
+       rm -rf gnuastro
diff --git a/lib/gnuastro.c b/lib/gnuastro.c
deleted file mode 100644
index 578eef5..0000000
--- a/lib/gnuastro.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/*********************************************************************
-Functions dealing with general aspects of all Gnuastro.
-
-Original author:
-     Mohammad Akhlaghi <address@hidden>
-Contributing author(s):
-Copyright (C) 2016, Free Software Foundation, Inc.
-
-Gnuastro 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 3 of the License, or (at your
-option) any later version.
-
-Gnuastro 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 Gnuastro. If not, see <http://www.gnu.org/licenses/>.
-**********************************************************************/
-#include <config.h>
-
-#include <string.h>
-
-#include "gnuastro/checkset.h"
-#include "gnuastro/gnuastro.h"
-
-
-/* Return the version of Gnuastro. If the input argument is pointing to a
-   NULL pointer, then allocate the necessary space and copy version into
-   it. Otherwise, assume that the user has allocated the necessary space
-   (either statically or dynamically) and just copy the PACKAGE_VERSION
-   macro into the given pointer. The returned value is the pointer that the
-   arument is pointing to, so both can be used.*/
-char *
-gal_gnuastro_version(void)
-{
-  char *version=NULL;
-  gal_checkset_allocate_copy(PACKAGE_VERSION, &version);
-  return version;
-}
diff --git a/lib/gnuastro/gnuastro.h b/lib/gnuastro/gnuastro.h
deleted file mode 100644
index a9c56b1..0000000
--- a/lib/gnuastro/gnuastro.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*********************************************************************
-Functions dealing with general aspects of all Gnuastro.
-
-Original author:
-     Mohammad Akhlaghi <address@hidden>
-Contributing author(s):
-Copyright (C) 2016, Free Software Foundation, Inc.
-
-Gnuastro 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 3 of the License, or (at your
-option) any later version.
-
-Gnuastro 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 Gnuastro. If not, see <http://www.gnu.org/licenses/>.
-**********************************************************************/
-#ifndef __GAL_GNUASTRO_H__
-#define __GAL_GNUASTRO_H__
-
-/* Include other headers if necessary here. Note that other header files
-   must be included before the C++ preparations below */
-
-
-
-/* C++ Preparations */
-#undef __BEGIN_C_DECLS
-#undef __END_C_DECLS
-#ifdef __cplusplus
-# define __BEGIN_C_DECLS extern "C" {
-# define __END_C_DECLS }
-#else
-# define __BEGIN_C_DECLS                /* empty */
-# define __END_C_DECLS                  /* empty */
-#endif
-/* End of C++ preparations */
-
-
-
-/* Actual header contants (the above were for the Pre-processor). */
-__BEGIN_C_DECLS  /* From C++ preparations */
-
-
-
-/* Report the Gnuastro version number. */
-char *
-gal_gnuastro_version(void);
-
-
-
-__END_C_DECLS    /* From C++ preparations */
-
-#endif           /* __GAL_GNUASTRO_H__ */
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1ece32d..34ce751 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -35,6 +35,15 @@ endif
 
 
 
+# `gnuastro.h' is built by `../lib/Makefile.am' and is only meant for
+# outside users (internally `config.h' has everything. Thus, we need to add
+# it to the include directories of the test programs in this directory.
+AM_CPPFLAGS = -I../lib
+
+
+
+
+
 # Environment variables for the test scripts.
 AM_TESTS_ENVIRONMENT =                              \
 export topsrc=$(top_srcdir);                        \
diff --git a/tests/lib/versionc.c b/tests/lib/versionc.c
index 2044823..e25d051 100644
--- a/tests/lib/versionc.c
+++ b/tests/lib/versionc.c
@@ -28,17 +28,8 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 int
 main(void)
 {
-  /* Pointer to the string version */
-  char *version=NULL;
-
-  /* Fill in both with the version string. */
-  version=gal_gnuastro_version();
-
   /* Print the version. */
-  printf("Gnuastro version is: %s\n", version);
-
-  /* Free the allocated space for the version. */
-  free(version);
+  printf("Gnuastro version is: %s\n", GAL_GNUASTRO_VERSION);
 
   /* Cleanup and return */
   return EXIT_SUCCESS;
diff --git a/tests/lib/versioncpp.cpp b/tests/lib/versioncpp.cpp
index 14ff2a3..b82ce12 100644
--- a/tests/lib/versioncpp.cpp
+++ b/tests/lib/versioncpp.cpp
@@ -28,9 +28,6 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 int
 main(void)
 {
-  char *version=NULL;
-  version=gal_gnuastro_version();
-  std::cout << "Gnuastro version is: " << version << ".";
-  free(version);
+  std::cout << "Gnuastro version is: " << GAL_GNUASTRO_VERSION << ".\n";
   return EXIT_SUCCESS;
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]