mirror of
https://github.com/TREX-CoE/trexio.git
synced 2024-12-22 04:14:40 +01:00
Autoconfig with optional HDF5 compilation (#42)
Makefile.in: * recursive build; * advanced make targets; * major support for autoconf and minor for package managers. configure.ac: * optional HDF5 compilation [default: --with-hdf5]; * add -fPIC to CFLAGS if missing.
This commit is contained in:
parent
08a28c9ae4
commit
818d66d4d3
13
.gitignore
vendored
Normal file
13
.gitignore
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
Makefile
|
||||
src/Makefile
|
||||
auto-bugs
|
||||
autogen.sh
|
||||
autom4te.cache/
|
||||
clean.sh
|
||||
config.*
|
||||
configure
|
||||
install-sh
|
||||
|
||||
trexio-*.tar.gz
|
||||
trexio-*/
|
83
Makefile.in
Normal file
83
Makefile.in
Normal file
@ -0,0 +1,83 @@
|
||||
# @configure_input@
|
||||
|
||||
# Package-specific substitution variables
|
||||
package = @PACKAGE_NAME@
|
||||
version = @PACKAGE_VERSION@
|
||||
tarname = @PACKAGE_TARNAME@
|
||||
distdir = $(tarname)-$(version)
|
||||
|
||||
# Prefix-specific substitution variables
|
||||
prefix = @prefix@
|
||||
includedir = @includedir@
|
||||
docdir = @docdir@
|
||||
htmldir = @htmldir@
|
||||
libdir = @libdir@
|
||||
# Supplementary
|
||||
exec_prefix = @exec_prefix@
|
||||
libexecdir = @libexecdir@
|
||||
lispdir = @lispdir@
|
||||
# VPATH-specific substitution variables
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
# Tool-specific substitution variables
|
||||
CC = @CC@
|
||||
CFLAGS = @CFLAGS@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
FC = @FC@
|
||||
FCFLAGS = @FCFLAGS@
|
||||
LIBS = @LIBS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
INSTALL = @INSTALL@
|
||||
|
||||
.PHONY: FORCE all install clean check dist distcheck
|
||||
.POSIX:
|
||||
.SUFFIXES:
|
||||
|
||||
all install clean check:
|
||||
cd src && $(MAKE) $@
|
||||
|
||||
|
||||
dist: $(distdir).tar.gz
|
||||
|
||||
|
||||
$(distdir).tar.gz: $(distdir)
|
||||
tar chof - $(distdir) | gzip -9 -c > $@
|
||||
rm -rf $(distdir)
|
||||
|
||||
# for now copy entire src/ directory into $(distdir) in order for distcheck rule to work
|
||||
# later on can be changed to ship only files like *.c *.h *.f90 *.so *.mod
|
||||
$(distdir): FORCE
|
||||
mkdir -p $(distdir)
|
||||
cp $(srcdir)/configure.ac $(distdir)
|
||||
cp $(srcdir)/configure $(distdir)
|
||||
cp $(srcdir)/config.h.in $(distdir)
|
||||
cp $(srcdir)/install-sh $(distdir)
|
||||
cp -r $(srcdir)/src $(distdir)
|
||||
cp $(srcdir)/Makefile.in $(distdir)
|
||||
cp $(srcdir)/LICENSE $(distdir)
|
||||
|
||||
|
||||
FORCE:
|
||||
-rm $(distdir).tar.gz >/dev/null 2>&1
|
||||
-rm -rf $(distdir) >/dev/null 2>&1
|
||||
|
||||
|
||||
distcheck: $(distdir).tar.gz
|
||||
gzip -cd $(distdir).tar.gz | tar xvf -
|
||||
cd $(distdir) && \
|
||||
./configure CC="$(CC)" CFLAGS="$(CFLAGS)" && \
|
||||
$(MAKE) all && \
|
||||
$(MAKE) check && \
|
||||
$(MAKE) DESTDIR=$${PWD}/_inst install && \
|
||||
$(MAKE) clean
|
||||
rm -rf $(distdir)
|
||||
@echo "*** Package $(distdir).tar.gz is ready for distribution."
|
||||
|
||||
|
||||
Makefile: Makefile.in config.status
|
||||
./config.status $@
|
||||
|
||||
|
||||
config.status: configure
|
||||
./config.status --recheck
|
||||
|
152
configure.ac
Normal file
152
configure.ac
Normal file
@ -0,0 +1,152 @@
|
||||
# -*- Autoconf -*-
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
|
||||
AC_PREREQ([2.69])
|
||||
AC_INIT([TREXIO], [0.2], [https://github.com/TREX-CoE/trexio/issues])
|
||||
AC_CONFIG_SRCDIR([src/trexio_text.h])
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
PKG_PROG_PKG_CONFIG()
|
||||
# Checks for programs.
|
||||
AC_PROG_CC
|
||||
AC_PROG_FC
|
||||
AC_PROG_INSTALL
|
||||
AC_PROG_LN_S
|
||||
AC_PROG_CC_C99
|
||||
|
||||
# Configure with HDF5 (default: --with-hdf5 using pkg-config) [optional]:
|
||||
# ./configure [--with-hdf5 or --with-hdf5=yes]
|
||||
# Configure with user-provided path to HDF5:
|
||||
# ./configure --with-hdf5=/usr/lib/x86_64-linux-gnu/hdf5/serial
|
||||
# Configure without HDF5:
|
||||
# ./configure --without-hdf5 [or --with-hdf5=no]
|
||||
|
||||
# Checks for basic libraries.
|
||||
AC_CHECK_LIB([m], [main])
|
||||
AC_CHECK_LIB([z], [main])
|
||||
# Checks for basic header files.
|
||||
AC_CHECK_HEADERS([fcntl.h stdint.h stdlib.h string.h unistd.h])
|
||||
|
||||
# Search for pthread
|
||||
have_pthreads=no
|
||||
AC_SEARCH_LIBS([pthread_create], [pthread], [have_pthreads=yes])
|
||||
|
||||
if test "x${have_pthreads}" = xyes; then
|
||||
AC_CHECK_HEADERS([pthread.h], [], [have_pthreads=no])
|
||||
fi
|
||||
|
||||
if test "x${have_pthreads}" = xno; then
|
||||
AC_MSG_ERROR([
|
||||
------------------------------------------
|
||||
The pthread library and header file
|
||||
required to build TREXIO. Stopping...
|
||||
Check 'config.log' for more information.
|
||||
------------------------------------------])
|
||||
fi
|
||||
|
||||
AC_ARG_WITH([hdf5],
|
||||
AS_HELP_STRING([--with-hdf5],
|
||||
[Include HDF5 functionality @<:@default: yes@:>@])],
|
||||
[hdf5=${withval}],
|
||||
[hdf5=yes])
|
||||
|
||||
have_hdf5=no
|
||||
have_hdf5_hl=no
|
||||
if test "x${hdf5}" = xno; then
|
||||
AC_MSG_WARN([
|
||||
------------------------------------------
|
||||
Configuring with the HDF5 library is
|
||||
recommended to build efficient TREXIO.
|
||||
------------------------------------------])
|
||||
elif test "x${hdf5}" = xyes; then
|
||||
|
||||
# Check if HDF5 is already configured (e.g. after calling `module load hdf5-<version>`)
|
||||
AC_CHECK_HEADERS([hdf5_hl.h])
|
||||
AC_CHECK_LIB([hdf5_hl], [H5LTfind_dataset], [], [have_hdf5_hl=no])
|
||||
|
||||
AC_CHECK_HEADERS([hdf5.h])
|
||||
AC_CHECK_LIB([hdf5], [H5open], [], [have_hdf5=no])
|
||||
|
||||
# If HDF5 is not configured, try using pkg-config
|
||||
if test "x${have_hdf5}" = xno; then
|
||||
PKG_CHECK_MODULES([HDF5], [hdf5 >= 1.8])
|
||||
CFLAGS="${HDF5_CFLAGS} ${CFLAGS}"
|
||||
LIBS="${HDF5_LIBS} -lhdf5_hl ${LIBS}"
|
||||
fi
|
||||
|
||||
else
|
||||
|
||||
if test "x${hdf5}" = x; then
|
||||
AC_MSG_ERROR([
|
||||
------------------------------------------
|
||||
The path to HDF5 library is required.
|
||||
Maybe you forgot to pass --with-hdf5="/your/path/" to configure script.
|
||||
Stopping...
|
||||
------------------------------------------])
|
||||
fi
|
||||
|
||||
CPPFLAGS="-I${hdf5}/include ${CPPFLAGS}"
|
||||
LDFLAGS="-L${hdf5} ${LDFLAGS}"
|
||||
|
||||
AC_CHECK_HEADERS([hdf5_hl.h], [], [have_hdf5_hl=no])
|
||||
AC_CHECK_LIB([hdf5_hl], [H5LTfind_dataset], [], [have_hdf5_hl=no])
|
||||
|
||||
AC_CHECK_HEADERS([hdf5.h], [], [have_hdf5=no])
|
||||
AC_CHECK_LIB([hdf5], [H5open], [], [have_hdf5=no])
|
||||
|
||||
fi
|
||||
|
||||
# add -fPIC if not present in CFLAGS, necessary to compile TREXIO
|
||||
# TODO: replace with AM_CFLAGS for appropriate targer once Automake is introduced
|
||||
case "${CFLAGS}" in
|
||||
*-fPIC*)
|
||||
;;
|
||||
*)
|
||||
AC_MSG_WARN([
|
||||
------------------------------------------
|
||||
Adding -fPIC option to CFLAGS.
|
||||
This is necessary to build TREXIO.
|
||||
------------------------------------------])
|
||||
CFLAGS="${CFLAGS} -fPIC"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Checks for typedefs, structures, and compiler characteristics.
|
||||
AC_TYPE_INT32_T
|
||||
AC_TYPE_INT64_T
|
||||
AC_TYPE_SIZE_T
|
||||
AC_TYPE_UINT32_T
|
||||
AC_TYPE_UINT64_T
|
||||
|
||||
# Checks for library functions.
|
||||
AC_FUNC_MALLOC
|
||||
AC_CHECK_FUNCS([memset mkdir strerror])
|
||||
|
||||
AC_CONFIG_FILES([Makefile
|
||||
src/Makefile])
|
||||
AC_OUTPUT
|
||||
|
||||
echo \
|
||||
"-------------------------------------------------
|
||||
|
||||
${PACKAGE_NAME} Version ${PACKAGE_VERSION}
|
||||
|
||||
Prefix: '${prefix}'.
|
||||
|
||||
CC: ${CC}
|
||||
CPPFLAGS: ${CPPFLAGS}
|
||||
CFLAGS: ${CFLAGS}
|
||||
FC: ${FC}
|
||||
FCLAGS: ${FCFLAGS}
|
||||
LDFLAGS: ${LDFLAGS}
|
||||
LIBS: ${LIBS}
|
||||
|
||||
Package features:
|
||||
Compilation with HDF5: ${hdf5}
|
||||
|
||||
Now type 'make @<:@<target>@:>@'
|
||||
where the optional <target> is:
|
||||
all - build C and Fortran APIs
|
||||
check - check C and Fortran APIs
|
||||
clean - clean the produced files
|
||||
--------------------------------------------------"
|
||||
|
95
src/Makefile
95
src/Makefile
@ -1,95 +0,0 @@
|
||||
COMPILER=GNU
|
||||
#COMPILER=INTEL
|
||||
#COMPILER=LLVM
|
||||
|
||||
ifeq ($(COMPILER),GNU)
|
||||
CC=gcc -g
|
||||
CFLAGS=-fPIC -fexceptions -Wall -Werror -Wpedantic -Wextra
|
||||
|
||||
FC=gfortran -g
|
||||
FFLAGS=-fPIC -fcheck=all -Waliasing -Wampersand -Wconversion -Wsurprising -Wintrinsics-std -Wno-tabs -Wintrinsic-shadow -Wline-truncation -Wreal-q-constant -Wuninitialized -fbacktrace -ffpe-trap=zero,overflow,underflow -finit-real=nan
|
||||
|
||||
LIBS= $(shell pkg-config --libs hdf5) -lhdf5_hl -lgfortran
|
||||
INCLUDE = $(shell pkg-config --cflags hdf5)
|
||||
endif
|
||||
|
||||
ifeq ($(COMPILER),INTEL)
|
||||
CC=icc -xHost
|
||||
CFLAGS=-fPIC -g -O2
|
||||
|
||||
FC=ifort -xHost
|
||||
FFLAGS=-fPIC -g -O2
|
||||
|
||||
LIBS= #-lm
|
||||
endif
|
||||
|
||||
#TODO
|
||||
ifeq ($(COMPILER),LLVM)
|
||||
CC=clang
|
||||
CFLAGS=-fPIC -g -O2
|
||||
|
||||
FC=flang
|
||||
FFLAGS=fPIC -g -O2
|
||||
|
||||
LIBS=-lm
|
||||
endif
|
||||
|
||||
OBJECT_FILES= trexio.o trexio_text.o trexio_hdf5.o
|
||||
SOURCE_FILES= test.c trexio.c trexio_hdf5.c trexio_text.c
|
||||
HEADER_FILES= trexio.h trexio_text.h trexio_hdf5.h trexio_s.h
|
||||
ORG_FILES= templates_front/templator_front.org templates_text/templator_text.org \
|
||||
templates_hdf5/templator_hdf5.org
|
||||
|
||||
|
||||
export CC CFLAGS FC FFLAGS LIBS
|
||||
|
||||
.PHONY: clean
|
||||
|
||||
|
||||
libtrexio.so: $(OBJECT_FILES) $(HEADER_FILES)
|
||||
$(CC) -shared $(OBJECT_FILES) -o libtrexio.so
|
||||
|
||||
|
||||
fortran: trexio_f.o
|
||||
|
||||
|
||||
trexio_f.o: libtrexio.so trexio_f.f90
|
||||
$(FC) $(FFLAGS) -c trexio_f.f90 -o trexio_f.o
|
||||
|
||||
|
||||
check: cppcheck.out
|
||||
cat cppcheck.out
|
||||
|
||||
cppcheck.out: $(HEADER_FILES) $(SOURCE_FILES)
|
||||
cppcheck --addon=cert -q --error-exitcode=0 \
|
||||
--enable=warning,performance,portability,missingInclude,information \
|
||||
--language=c --std=c99 -rp --platform=unix64 \
|
||||
$(INCLUDE) $(SOURCE_FILES) 2>$@
|
||||
|
||||
|
||||
trexio.c trexio_f.f90 trexio.h: $(ORG_FILES)
|
||||
./build_trexio.sh
|
||||
|
||||
|
||||
test_c: libtrexio.so test.c
|
||||
$(CC) $(CFLAGS) $(INCLUDE) -Wl,-rpath,$(PWD) -L. test.c -ltrexio $(LIBS) -o test_c
|
||||
|
||||
|
||||
test_f: libtrexio.so test.f90 trexio_f.o
|
||||
$(FC) $(FFLAGS) $(INCLUDE) -Wl,-rpath,$(PWD) -L. test.f90 trexio_f.o -ltrexio $(LIBS) -o test_f
|
||||
|
||||
|
||||
test: test_c test_f
|
||||
$(RM) -r trexio_test
|
||||
$(RM) -r trexio_test_fort
|
||||
./test_c
|
||||
./test_f
|
||||
|
||||
clean:
|
||||
$(RM) *.o libtrexio.so test_*.h5 test_f test_c
|
||||
$(RM) -r trexio_test/ trexio_test_fort/
|
||||
|
||||
|
||||
%.o: %.c $(HEADER_FILES)
|
||||
$(CC) $(CFLAGS) $(INCLUDE) -c $*.c -o $*.o
|
||||
|
133
src/Makefile.in
Normal file
133
src/Makefile.in
Normal file
@ -0,0 +1,133 @@
|
||||
# @configure_input@
|
||||
|
||||
# Package-specific substitution variables
|
||||
package = @PACKAGE_NAME@
|
||||
version = @PACKAGE_VERSION@
|
||||
tarname = @PACKAGE_TARNAME@
|
||||
distdir = $(tarname)-$(version)
|
||||
|
||||
# Prefix-specific substitution variables
|
||||
prefix = @prefix@
|
||||
includedir = @includedir@
|
||||
docdir = @docdir@
|
||||
htmldir = @htmldir@
|
||||
libdir = @libdir@
|
||||
# Supplementary
|
||||
exec_prefix = @exec_prefix@
|
||||
libexecdir = @libexecdir@
|
||||
lispdir = @lispdir@
|
||||
# VPATH-specific substitution variables
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
# Tool-specific substitution variables
|
||||
CC = @CC@
|
||||
CFLAGS = @CFLAGS@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
FC = @FC@
|
||||
FCFLAGS = @FCFLAGS@
|
||||
LIBS = @LIBS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
INSTALL = @INSTALL@
|
||||
|
||||
|
||||
ifeq ($(CC),gcc)
|
||||
#CFLAGS = -g -fPIC -O2 -fexceptions -Wall -Werror -Wpedantic -Wextra
|
||||
endif
|
||||
ifeq ($(FC),gfortran)
|
||||
#FCFLAGS = -g -fPIC -O2 -fcheck=all -Waliasing -Wampersand -Wconversion -Wsurprising -Wintrinsics-std -Wno-tabs -Wintrinsic-shadow -Wline-truncation -Wreal-q-constant -Wuninitialized -fbacktrace -ffpe-trap=zero,overflow,underflow -finit-real=nan
|
||||
endif
|
||||
|
||||
ifeq ($(CC),icc)
|
||||
#CFLAGS = -xHost -fPIC -g -O2 -fexceptions -Wall -Werror -Wpedantic -Wextra
|
||||
endif
|
||||
ifeq ($(FC),ifort)
|
||||
#FCFLAGS = -xHost -fPIC -g -O2
|
||||
endif
|
||||
|
||||
ifeq ($(CC),clang)
|
||||
#CFLAGS = -fPIC -g -O2
|
||||
endif
|
||||
ifeq ($(FC),flang)
|
||||
#FCFLAGS = -fPIC -g -O2
|
||||
endif
|
||||
|
||||
OBJECT_FILES= trexio.o trexio_text.o trexio_hdf5.o
|
||||
SOURCE_FILES= test.c trexio.c trexio_hdf5.c trexio_text.c
|
||||
HEADER_FILES= trexio.h trexio_text.h trexio_hdf5.h trexio_s.h
|
||||
ORG_FILES= templates_front/templator_front.org templates_text/templator_text.org \
|
||||
templates_hdf5/templator_hdf5.org
|
||||
|
||||
|
||||
.PHONY: all fortran clean install
|
||||
.POSIX:
|
||||
.SUFFIXES:
|
||||
|
||||
|
||||
all: libtrexio.so fortran
|
||||
|
||||
|
||||
libtrexio.so: $(OBJECT_FILES) $(HEADER_FILES)
|
||||
$(CC) -shared $(OBJECT_FILES) -o libtrexio.so
|
||||
|
||||
|
||||
fortran: trexio_f.o
|
||||
|
||||
|
||||
trexio_f.o: libtrexio.so trexio_f.f90
|
||||
$(FC) $(FCFLAGS) -c trexio_f.f90 -o trexio_f.o
|
||||
|
||||
|
||||
cppcheck: cppcheck.out
|
||||
cat cppcheck.out
|
||||
|
||||
|
||||
cppcheck.out: $(HEADER_FILES) $(SOURCE_FILES)
|
||||
cppcheck --addon=cert -q --error-exitcode=0 \
|
||||
--enable=warning,performance,portability,missingInclude,information \
|
||||
--language=c --std=c99 -rp --platform=unix64 \
|
||||
$(CPPFLAGS) $(SOURCE_FILES) 2>$@
|
||||
|
||||
|
||||
trexio.c trexio_f.f90 trexio.h: $(ORG_FILES)
|
||||
./build_trexio.sh
|
||||
|
||||
|
||||
test_c: libtrexio.so test.c
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) -Wl,-rpath,$(PWD) -L. test.c -ltrexio $(LDFLAGS) $(LIBS) -o test_c
|
||||
|
||||
|
||||
test_f: libtrexio.so trexio_f.o test.f90
|
||||
$(FC) $(CPPFLAGS) $(FCFLAGS) -Wl,-rpath,$(PWD) -L. test.f90 trexio_f.o -ltrexio $(LDFLAGS) $(LIBS) -o test_f
|
||||
|
||||
|
||||
check: test_c test_f
|
||||
$(RM) -r trexio_test
|
||||
$(RM) -r trexio_test_fort
|
||||
./test_c
|
||||
./test_f
|
||||
|
||||
# $(DESTDIR) is needed for future support of package managers
|
||||
# install should avoid build target due to possible conflict when prefix overriden
|
||||
install:
|
||||
$(INSTALL) -d $(DESTDIR)$(libdir) $(DESTDIR)$(includedir)
|
||||
cp libtrexio.so $(DESTDIR)$(libdir)
|
||||
cp trexio*.h $(DESTDIR)$(includedir)
|
||||
|
||||
|
||||
clean:
|
||||
$(RM) *.o libtrexio.so test_*.h5 test_f test_c
|
||||
$(RM) -r trexio_test/ trexio_test_fort/
|
||||
|
||||
|
||||
%.o: %.c $(HEADER_FILES)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) -c $*.c -o $*.o
|
||||
|
||||
|
||||
Makefile: Makefile.in ../config.status
|
||||
cd .. && ./config.status src/$@
|
||||
|
||||
|
||||
../config.status: ../configure
|
||||
cd .. && ./config.status --recheck
|
||||
|
@ -402,7 +402,7 @@ struct trexio_back_end_s {
|
||||
These names are populated by the generator.py (i.e. they are hard-coded), which is why the user
|
||||
should tend to avoid renaming the ~.txt~ data files.
|
||||
|
||||
#+begin_src c :tangle prefix_front.h
|
||||
#+begin_src c :tangle prefix_front.h :exports none
|
||||
trexio_t* trexio_open(const char* file_name, const char mode, const back_end_t back_end);
|
||||
#+end_src
|
||||
|
||||
@ -530,7 +530,7 @@ end interface
|
||||
output:
|
||||
~trexio_exit_code~ exit code.
|
||||
|
||||
#+begin_src c :tangle prefix_front.h
|
||||
#+begin_src c :tangle prefix_front.h :exports none
|
||||
trexio_exit_code trexio_close(trexio_t* file);
|
||||
#+end_src
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user