Commit 8d779869 authored by Sergey Kosukhin's avatar Sergey Kosukhin

Add an example of how to generate and use a public configuration header.

parent 9d4b517a
......@@ -8,6 +8,8 @@
/m4/ltsugar.m4
/m4/ltversion.m4
/m4/lt~obsolete.m4
/src/config.h.in
/src/config.h.in~
Makefile.in
# Configure stage files
......@@ -15,6 +17,10 @@ Makefile.in
/config.log
/config.status
/libtool
/src/banana_config.h
/src/config.h
/src/stamp-h1
/src/stamp-h2
Makefile
# Build stage files
......@@ -24,8 +30,8 @@ Makefile
*.mod
*.o
.libs
/example/example
/example/example_f
/examples/example
/examples/example_f
# Test stage files
*.nc
......
SUBDIRS = src example tests
SUBDIRS = src examples tests
ACLOCAL_AMFLAGS = -I m4
......@@ -4,7 +4,20 @@ AC_INIT([libbanana], [1.0])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_AUX_DIR([config])
AC_CONFIG_SRCDIR([src/banana.h])
AC_CONFIG_HEADERS([config/config.h])
dnl Generate the private config header:
AC_CONFIG_HEADERS([src/config.h])
dnl Generate the public config header and avoid C-style block comments in
dnl it to safely include it into a Fortran source file:
AC_CONFIG_HEADERS([src/banana_config.h],
[sed 's%/\*.*\*/%%g' "$ac_file" > "$tmp/banana_config.h" || dnl
AC_MSG_ERROR([could not postprocess $ac_file])
rm -f "$ac_file"
mv "$tmp/banana_config.h" "$ac_file" || dnl
AC_MSG_ERROR([could not postprocess $ac_file])])
dnl Prevent banana_config from overriding macros defined in config.h when both
dnl headers are included:
AC_DEFINE([BANANA_CONFIG_H], [], [do not include banana_config.h])
AM_INIT_AUTOMAKE([foreign])
AM_MAINTAINER_MODE([enable])
......@@ -78,7 +91,7 @@ AM_CONDITIONAL([HAVE_NETCDF], [test x"$enable_netcdf" = xyes])
AC_CONFIG_FILES([
Makefile
example/Makefile
examples/Makefile
src/Makefile
tests/Makefile
])
......
#include "banana.h"
int main() {
banana_give_me();
banana_netcdf("banana.nc");
}
......@@ -4,9 +4,12 @@ AM_CPPFLAGS= -I$(top_srcdir)/src
example_SOURCES = example.c
example_LDADD = $(top_builddir)/src/libbanana.la
AM_FCFLAGS= $(FCMODINC)$(top_builddir)/src
AM_FCFLAGS= $(FCMODINC)$(top_builddir)/src $(FCPPINC)$(top_builddir)/src
example_f_SOURCES = example_f.f90
example_f_LDADD = $(top_builddir)/src/libbanana_f.la $(top_builddir)/src/libbanana.la
mostlyclean-local:
-rm -f *.i
clean-local:
-rm -f *.nc
#include <stdio.h>
#include <banana.h>
int main() {
banana_give_me();
#ifdef BANANA_NETCDF_ENABLED
banana_netcdf("banana.nc");
#else
printf("Avoid calling 'banana_netcdf' because NetCDF is disabled.\n");
#endif // BANANA_NETCDF_ENABLED
}
#include <banana_config.h>
program example_f
use banana, only : banana_give_me, &
& banana_netcdf
implicit none
call banana_give_me()
#ifdef BANANA_NETCDF_ENABLED
call banana_netcdf('banana_f.nc')
#else
print *, "Avoid calling 'banana_netcdf' because NetCDF is disabled."
#endif
end program example_f
......@@ -3,6 +3,7 @@ lib_LTLIBRARIES = \
libbanana_f.la
include_HEADERS = banana.h
nodist_include_HEADERS = banana_config.h
libbanana_la_SOURCES = \
banana.c \
......@@ -20,7 +21,7 @@ else
banana_mod = banana.$(FCMODEXT)
endif
nodist_include_HEADERS = $(banana_mod)
nodist_include_HEADERS += $(banana_mod)
libbanana_f_la_SOURCES = \
banana_f.f90
......
#ifndef BANANA_H
#define BANANA_H
#include "banana_config.h"
// All interface functions should have the same prefix 'banana_'
void banana_give_me();
void banana_netcdf(const char* filename);
......
#ifndef BANANA_CONFIG_H
# define BANANA_CONFIG_H
# undef BANANA_NETCDF_ENABLED
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment