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
|
|
|
|
2020-10-16 13:58:05 +02:00
|
|
|
OUTPUT=Makefile.generated
|
|
|
|
|
|
|
|
|
|
|
|
|
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-03-09 01:16:23 +01:00
|
|
|
# Finally, we append the rules to the Makefile
|
|
|
|
|
|
|
|
|
|
|
|
cat << EOF > ${OUTPUT}
|
2021-04-20 18:33:36 +02:00
|
|
|
.POSIX:
|
|
|
|
.SUFFIXES:
|
|
|
|
|
2021-04-21 12:44:03 +02:00
|
|
|
prefix=/usr/local
|
2021-04-20 18:33:36 +02:00
|
|
|
|
2020-10-16 13:58:05 +02:00
|
|
|
CC=$CC
|
2021-03-19 13:47:50 +01:00
|
|
|
CFLAGS=$CFLAGS -I../munit/
|
2020-10-16 13:58:05 +02:00
|
|
|
|
|
|
|
FC=$FC
|
|
|
|
FFLAGS=$FFLAGS
|
2021-04-20 18:33:36 +02:00
|
|
|
|
2020-10-16 13:58:05 +02:00
|
|
|
OBJECT_FILES=$OBJECTS
|
2020-10-17 00:28:49 +02:00
|
|
|
TESTS=$TESTS
|
2020-10-26 16:51:16 +01:00
|
|
|
TESTS_F=$TESTS_F
|
2020-10-16 13:58:05 +02:00
|
|
|
|
2020-10-22 00:50:07 +02:00
|
|
|
LIBS=$LIBS
|
|
|
|
|
2021-04-20 18:33:36 +02:00
|
|
|
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
|
2021-04-21 12:44:03 +02:00
|
|
|
qmckl_f=\$(QMCKL_ROOT)/share/qmckl/fortran/qmckl_f.f90
|
2021-04-21 13:17:33 +02:00
|
|
|
munit=\$(QMCKL_ROOT)/munit/munit.c
|
2021-03-19 13:47:50 +01:00
|
|
|
|
2021-04-20 18:33:36 +02:00
|
|
|
shared: \$(shared_lib)
|
|
|
|
static: \$(static_lib)
|
|
|
|
all: shared static
|
|
|
|
|
|
|
|
\$(shared_lib): \$(OBJECT_FILES)
|
|
|
|
\$(CC) -shared \$(OBJECT_FILES) -o \$(shared_lib)
|
|
|
|
|
|
|
|
\$(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-04-20 18:33:36 +02:00
|
|
|
qmckl_f.o: \$(qmckl_f)
|
|
|
|
\$(FC) \$(FFLAGS) -c \$(qmckl_f) -o \$@
|
2021-03-18 18:02:06 +01:00
|
|
|
|
2021-04-20 18:33:36 +02:00
|
|
|
test_qmckl: test_qmckl.c \$(qmckl_h) \$(static_lib) \$(TESTS) \$(TESTS_F)
|
|
|
|
\$(CC) \$(CFLAGS) \
|
|
|
|
\$(munit) \$(TESTS) \$(TESTS_F) \$(static_lib) \$(LIBS) test_qmckl.c -o \$@
|
2021-03-09 01:16:23 +01:00
|
|
|
|
2021-04-20 18:33:36 +02:00
|
|
|
test_qmckl_shared: test_qmckl.c \$(qmckl_h) \$(shared_lib) \$(TESTS) \$(TESTS_F)
|
2021-04-21 12:44:03 +02:00
|
|
|
\$(CC) \$(CFLAGS) -Wl,-rpath,\$(QMCKL_ROOT)/lib -L\$(QMCKL_ROOT)/lib \
|
2021-04-20 18:33:36 +02:00
|
|
|
\$(munit) \$(TESTS) \$(TESTS_F) -lqmckl \$(LIBS) 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:
|
|
|
|
\$(RM) -- *.o *.mod \$(shared_lib) \$(static_lib) test_qmckl
|
|
|
|
|
2021-04-21 12:44:03 +02:00
|
|
|
install:
|
|
|
|
install -d \$(prefix)/lib
|
|
|
|
install -d \$(prefix)/include
|
|
|
|
install -d \$(prefix)/share/qmckl/fortran
|
|
|
|
install -d \$(prefix)/man
|
|
|
|
install \$(shared_lib) \$(prefix)/lib
|
|
|
|
install \$(static_lib) \$(prefix)/lib
|
|
|
|
install \$(qmckl_h) \$(prefix)/include
|
|
|
|
install \$(qmckl_f) \$(prefix)/share/qmckl/fortran
|
|
|
|
|
2021-04-20 18:33:36 +02:00
|
|
|
.SUFFIXES: .c .f90 .o
|
|
|
|
|
|
|
|
.c.o:
|
|
|
|
\$(CC) \$(CFLAGS) -c \$*.c -o \$*.o
|
|
|
|
|
|
|
|
.f90.o: qmckl_f.o
|
|
|
|
\$(FC) \$(FFLAGS) -c \$*.f90 -o \$*.o
|
|
|
|
|
|
|
|
.PHONY: check clean all
|
2020-10-16 13:58:05 +02:00
|
|
|
EOF
|