1
0
mirror of https://github.com/TREX-CoE/qmckl.git synced 2024-11-19 20:42:50 +01:00
qmckl/tools/create_makefile.sh

172 lines
3.6 KiB
Bash
Raw Normal View History

2020-10-16 13:58:05 +02:00
#!/bin/bash
2021-03-09 01:16:23 +01:00
# Script to generate auto-generated Makefile
# :PROPERTIES:
# :header-args: :tangle create_makefile.sh :noweb yes :shebang #!/bin/bash :comments org
# :END:
# This script generates the Makefile that compiles the library.
# The ~OUTPUT~ variable contains the name of the generated Makefile,typically
# =Makefile.generated=.
2021-03-19 13:47:50 +01:00
2021-03-09 01:16:23 +01:00
# This file was created by tools/Building.org
2020-10-16 13:58:05 +02:00
2021-03-06 14:46:01 +01:00
2021-05-07 12:47:56 +02:00
OUTPUT=Makefile.generated.in
2020-10-16 13:58:05 +02:00
2021-03-09 01:16:23 +01:00
# We start by tangling all the org-mode files.
${QMCKL_ROOT}/tools/tangle.sh *.org
2021-04-21 12:44:03 +02:00
${QMCKL_ROOT}/tools/build_qmckl_h.sh
2021-03-09 01:16:23 +01:00
# Then we create the list of ~*.o~ files to be created, for library
# functions:
2020-10-16 13:58:05 +02:00
2021-03-18 18:02:06 +01:00
OBJECTS="qmckl_f.o"
2021-03-19 13:47:50 +01:00
for i in $(ls qmckl_*.c qmckl_*f.f90) ; do
FILE=${i%.*}
OBJECTS+=" ${FILE}.o"
2020-10-16 13:58:05 +02:00
done >> $OUTPUT
2021-03-09 01:16:23 +01:00
# for tests in C:
2020-10-17 00:28:49 +02:00
TESTS=""
2020-10-21 19:50:18 +02:00
for i in $(ls test_qmckl_*.c) ; do
2021-03-19 13:47:50 +01:00
FILE=${i%.c}
TESTS+=" ${FILE}.o"
2020-10-17 00:28:49 +02:00
done >> $OUTPUT
2021-03-09 01:16:23 +01:00
# and for tests in Fortran:
2020-10-26 16:51:16 +01:00
TESTS_F=""
2021-03-09 01:16:23 +01:00
for i in $(ls test_qmckl_*_f.f90) ; do
2021-03-19 13:47:50 +01:00
FILE=${i%.f90}
TESTS_F+=" ${FILE}.o"
2020-10-26 16:51:16 +01:00
done >> $OUTPUT
2020-10-16 13:58:05 +02:00
2021-05-04 17:10:20 +02:00
# Finally, we append the variables to the Makefile
2021-03-09 01:16:23 +01:00
cat << EOF > ${OUTPUT}
2021-04-20 18:33:36 +02:00
.POSIX:
.SUFFIXES:
2021-05-07 12:47:56 +02:00
package = @PACKAGE_TARNAME@
version = @PACKAGE_VERSION@
2021-04-20 18:33:36 +02:00
2021-05-07 12:47:56 +02:00
prefix = @prefix@
2020-10-16 13:58:05 +02:00
2021-05-07 12:47:56 +02:00
CC = @CC@
CFLAGS= @CFLAGS@ -I../munit/ -I../include
FC = @FC@
FCFLAGS= @FCFLAGS@
2021-04-20 18:33:36 +02:00
2020-10-16 13:58:05 +02:00
OBJECT_FILES=$OBJECTS
2021-05-07 12:47:56 +02:00
TESTS = $TESTS
TESTS_F = $TESTS_F
LIBS = @LIBS@
FCLIBS = @FCLIBS@
2021-05-04 17:10:20 +02:00
EOF
2020-10-22 00:50:07 +02:00
2021-05-04 17:10:20 +02:00
echo '
QMCKL_ROOT=$(shell dirname $(CURDIR))
shared_lib=$(QMCKL_ROOT)/lib/libqmckl.so
static_lib=$(QMCKL_ROOT)/lib/libqmckl.a
qmckl_h=$(QMCKL_ROOT)/include/qmckl.h
qmckl_f=$(QMCKL_ROOT)/share/qmckl/fortran/qmckl_f.f90
munit=$(QMCKL_ROOT)/munit/munit.c
2021-03-19 13:47:50 +01:00
2021-05-04 17:10:20 +02:00
datarootdir=$(prefix)/share
datadir=$(datarootdir)
docdir=$(datarootdir)/doc/$(package)
htmldir=$(docdir)/html
libdir=$(prefix)/lib
includedir=$(prefix)/include
fortrandir=$(datarootdir)/$(package)/fortran
shared: $(shared_lib)
static: $(static_lib)
2021-04-20 18:33:36 +02:00
all: shared static
2021-05-04 17:10:20 +02:00
$(shared_lib): $(OBJECT_FILES)
$(CC) -shared $(OBJECT_FILES) -o $(shared_lib)
2021-04-20 18:33:36 +02:00
2021-05-04 17:10:20 +02:00
$(static_lib): $(OBJECT_FILES)
$(AR) rcs $(static_lib) $(OBJECT_FILES)
2020-10-16 13:58:05 +02:00
2021-04-20 18:33:36 +02:00
# Test
2021-04-21 12:44:03 +02:00
2021-05-04 17:10:20 +02:00
qmckl_f.o: $(qmckl_f)
2021-05-07 12:47:56 +02:00
$(FC) $(FCFLAGS) -c $(qmckl_f) -o $@
2021-03-18 18:02:06 +01:00
2021-05-04 17:10:20 +02:00
test_qmckl: test_qmckl.c $(qmckl_h) $(static_lib) $(TESTS) $(TESTS_F)
2021-05-07 12:47:56 +02:00
$(CC) $(CFLAGS) $(munit) $(TESTS) $(TESTS_F) $(static_lib) $(LIBS) \
$(FCLIBS) test_qmckl.c -o $@
2021-03-09 01:16:23 +01:00
2021-05-04 17:10:20 +02:00
test_qmckl_shared: test_qmckl.c $(qmckl_h) $(shared_lib) $(TESTS) $(TESTS_F)
$(CC) $(CFLAGS) -Wl,-rpath,$(QMCKL_ROOT)/lib -L$(QMCKL_ROOT)/lib \
2021-05-07 12:47:56 +02:00
$(munit) $(TESTS) $(TESTS_F) -lqmckl $(LIBS) $(FCLIBS) test_qmckl.c -o $@
2020-10-17 00:28:49 +02:00
2021-04-20 18:33:36 +02:00
check: test_qmckl test_qmckl_shared
2020-10-21 19:50:18 +02:00
./test_qmckl
2020-10-17 00:28:49 +02:00
2021-04-20 18:33:36 +02:00
clean:
2021-05-04 17:10:20 +02:00
$(RM) -- *.o *.mod $(shared_lib) $(static_lib) test_qmckl
2021-04-20 18:33:36 +02:00
2021-04-30 01:26:19 +02:00
2021-04-21 12:44:03 +02:00
install:
2021-05-04 17:10:20 +02:00
install -d $(DESTDIR)$(prefix)/lib
install -d $(DESTDIR)$(prefix)/include
install -d $(DESTDIR)$(prefix)/share/qmckl/fortran
install -d $(DESTDIR)$(prefix)/share/doc/qmckl/html/
install -d $(DESTDIR)$(prefix)/share/doc/qmckl/text/
install $(shared_lib) $(DESTDIR)$(libdir)/
install $(static_lib) $(DESTDIR)$(libdir)/
install $(qmckl_h) $(DESTDIR)$(includedir)
install $(qmckl_f) $(DESTDIR)$(fortrandir)
install $(QMCKL_ROOT)/share/doc/qmckl/html/*.html $(DESTDIR)$(docdir)/html/
install $(QMCKL_ROOT)/share/doc/qmckl/html/*.css $(DESTDIR)$(docdir)/html/
install $(QMCKL_ROOT)/share/doc/qmckl/text/*.txt $(DESTDIR)$(docdir)/text/
2021-04-30 01:26:19 +02:00
uninstall:
2021-05-04 17:10:20 +02:00
rm $(DESTDIR)$(libdir)/libqmckl.so
rm $(DESTDIR)$(libdir)/libqmckl.a
rm $(DESTDIR)$(includedir)/qmckl.h
rm -rf $(DESTDIR)$(datarootdir)/$(package)
rm -rf $(DESTDIR)$(docdir)
2021-04-21 12:44:03 +02:00
2021-04-20 18:33:36 +02:00
.SUFFIXES: .c .f90 .o
.c.o:
2021-05-04 17:10:20 +02:00
$(CC) $(CFLAGS) -c $*.c -o $*.o
2021-04-20 18:33:36 +02:00
.f90.o: qmckl_f.o
2021-05-07 12:47:56 +02:00
$(FC) $(FCFLAGS) -c $*.f90 -o $*.o
2021-04-20 18:33:36 +02:00
2021-05-07 12:47:56 +02:00
.PHONY: check cppcheck clean all
2021-05-04 17:10:20 +02:00
' >> ${OUTPUT}