1
0
mirror of https://github.com/TREX-CoE/qmckl.git synced 2024-11-19 12:32:40 +01:00
qmckl/tools/Building.org

642 lines
14 KiB
Org Mode
Raw Normal View History

2021-03-09 01:16:23 +01:00
#+TITLE: Building tools
2021-05-04 17:10:20 +02:00
#+STARTUP: indent overview
#+PROPERTY: header-args: :comments both
2021-03-09 01:16:23 +01:00
This file contains all the tools needed to build the QMCkl library.
* Helper functions
#+NAME: header
#+begin_src sh :tangle no :exports none :output none
echo "This file was created by tools/Building.org"
#+end_src
#+NAME: check-src
#+begin_src bash
2021-03-19 13:47:50 +01:00
if [[ $(basename ${PWD}) != "src" ]] ; then
echo "This script needs to be run in the src directory"
exit -1
2021-03-09 01:16:23 +01:00
fi
#+end_src
#+NAME: url-issues
: https://github.com/trex-coe/qmckl/issues
2021-03-18 18:02:06 +01:00
2021-03-09 01:16:23 +01:00
#+NAME: url-web
: https://trex-coe.github.io/qmckl
2021-03-18 18:02:06 +01:00
2021-03-09 01:16:23 +01:00
#+NAME: license
#+begin_example
BSD 3-Clause License
Copyright (c) 2020, TREX Center of Excellence
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#+end_example
2021-05-04 17:10:20 +02:00
* Makefiles
** Makefile.in
:PROPERTIES:
:header-args: :tangle ../src/Makefile.in :noweb yes :comments org
:END:
This is the main Makefile invoked by the ~make~ command at the root
of the package. To compile the sources, it calls the =Makefile=
located in the =src= directory. This Makefile creates the source
file from the org-mode file, as well as a Makefile,
=Makefile.generated=, dedicated to the compilation of the sources.
2021-05-07 12:47:56 +02:00
2021-05-04 17:10:20 +02:00
*** Header
2021-03-09 01:16:23 +01:00
2021-05-04 17:10:20 +02:00
We want the Makefile to be POSIX-compliant, such that it works not
only with GNU Make.
2021-03-09 01:16:23 +01:00
2021-05-04 17:10:20 +02:00
#+begin_src makefile
2021-03-09 01:16:23 +01:00
# <<header()>>
2021-04-20 18:33:36 +02:00
2021-04-21 13:17:33 +02:00
.POSIX:
2021-05-04 17:10:20 +02:00
#+end_src
*** Compiler options
2021-03-09 01:16:23 +01:00
2021-05-04 17:10:20 +02:00
Compiler variables are obtained from the configure script (see =configure.ac=)
2021-03-18 18:02:06 +01:00
2021-05-04 17:10:20 +02:00
#+begin_src makefile
2021-05-07 12:47:56 +02:00
CC = @CC@
FC = @FC@
CFLAGS = @CFLAGS@
FCFLAGS = @FCFLAGS@
LDFLAGS = @LDFLAGS@
2021-05-09 02:12:38 +02:00
DEFS = @DEFS@
2021-05-04 17:10:20 +02:00
#+end_src
*** Variables
#+begin_src makefile
HAS_CPPCHECK = @HAS_CPPCHECK@
2021-03-09 01:16:23 +01:00
2021-05-09 01:27:07 +02:00
# VPATH-related substitution variables
srcdir = @srcdir@
VPATH = @srcdir@
2021-03-09 01:16:23 +01:00
2021-05-10 10:05:50 +02:00
top_srcdir=$(srcdir)/..
shared_lib=$(top_srcdir)/lib/libqmckl.so
static_lib=$(top_srcdir)/lib/libqmckl.a
qmckl_h=$(top_srcdir)/include/qmckl.h
qmckl_f=$(top_srcdir)/share/qmckl/fortran/qmckl_f.f90
2021-04-20 18:33:36 +02:00
2021-05-10 10:05:50 +02:00
export CC CFLAGS DEFS FC FCFLAGS LIBS top_srcdir
2021-03-09 01:16:23 +01:00
2021-05-10 10:05:50 +02:00
ORG_SOURCE_FILES=$(wildcard $(srcdir)/*.org)
2021-04-20 18:33:36 +02:00
C_SOURCE_FILES=$(patsubst %.org,%.c,$(ORG_SOURCE_FILES))
2021-05-10 10:05:50 +02:00
INCLUDE=-I$(top_srcdir)/include/
2021-05-04 17:10:20 +02:00
#+end_src
2021-03-09 01:16:23 +01:00
2021-05-04 17:10:20 +02:00
*** Rules
2021-03-18 18:02:06 +01:00
2021-05-04 17:10:20 +02:00
The source files are created during the generation of the file ~Makefile.generated~.
The Makefile.generated is the one that will be distributed with the library.
2021-03-09 01:16:23 +01:00
2021-05-04 17:10:20 +02:00
#+begin_src makefile
2021-04-21 12:44:03 +02:00
.PHONY: clean shared static doc all check install uninstall
2021-03-09 01:16:23 +01:00
.SECONDARY: # Needed to keep the produced C and Fortran files
2021-04-30 01:26:19 +02:00
$(shared_lib) $(static_lib): $(qmckl_h) $(qmckl_f) Makefile.generated
$(MAKE) -f Makefile.generated $@
install uninstall: Makefile.generated
2021-04-20 18:33:36 +02:00
$(MAKE) -f Makefile.generated $@
$(qmckl_f) $(qmckl_h): Makefile.generated
2021-05-10 10:05:50 +02:00
$(top_srcdir)/tools/build_qmckl_h.sh
2021-03-09 01:16:23 +01:00
2021-04-20 18:33:36 +02:00
shared: $(shared_lib)
static: $(static_lib)
2021-04-21 12:44:03 +02:00
all: shared static doc check
2021-03-10 12:58:38 +01:00
2021-04-20 18:33:36 +02:00
check: $(static_lib)
$(MAKE) -f Makefile.generated check
2021-03-09 01:16:23 +01:00
2021-05-04 17:10:20 +02:00
ifeq ($(HAS_CPPCHECK),1)
2021-04-30 01:26:19 +02:00
cppcheck:
cppcheck \
2021-05-04 17:10:20 +02:00
--addon=cert \
--enable=warning,style,performance,portability,information \
qmckl_*.c
endif
2021-04-30 01:26:19 +02:00
2021-03-09 01:16:23 +01:00
doc: $(ORG_SOURCE_FILES)
2021-05-10 10:05:50 +02:00
$(top_srcdir)/tools/build_doc.sh
2021-03-09 01:16:23 +01:00
clean:
2021-04-20 18:33:36 +02:00
- $(MAKE) -f Makefile.generated clean
- $(RM) test_qmckl_* test_qmckl.c \
$(qmckl_h) $(qmckl_f) \
qmckl_*.f90 qmckl_*.c qmckl_*.h \
2021-04-21 13:26:11 +02:00
Makefile.generated *.html *.txt
veryclean: clean FORCE
2021-05-10 10:05:50 +02:00
- $(RM) $(top_srcdir)/share/doc/qmckl/html/*.html \
$(top_srcdir)/share/doc/qmckl/text/*.txt
2021-03-09 01:16:23 +01:00
2021-05-10 10:05:50 +02:00
Makefile.generated.in: Makefile $(top_srcdir)/tools/create_makefile.sh $(ORG_SOURCE_FILES) $(top_srcdir)/tools/Building.org
$(top_srcdir)/tools/create_makefile.sh
2021-04-20 18:33:36 +02:00
2021-05-07 12:47:56 +02:00
Makefile.generated: Makefile.generated.in
cd .. ; ./config.status
2021-04-20 18:33:36 +02:00
.SUFFIXES: .org .c
.org.c:
2021-05-10 10:05:50 +02:00
$(top_srcdir)/tools/tangle.sh $<
2021-04-20 18:33:36 +02:00
2021-05-04 17:10:20 +02:00
#+end_src
2021-03-09 01:16:23 +01:00
2021-05-04 17:10:20 +02:00
** Script to generate auto-generated Makefile
2021-03-09 01:16:23 +01:00
: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-18 18:02:06 +01:00
#+begin_src bash
2021-03-09 01:16:23 +01:00
# <<header()>>
<<check_src>>
2021-05-07 12:47:56 +02:00
OUTPUT=Makefile.generated.in
2021-03-09 01:16:23 +01:00
#+end_src
We start by tangling all the org-mode files.
2021-03-18 18:02:06 +01:00
#+begin_src bash
2021-05-10 10:05:50 +02:00
${top_srcdir}/tools/tangle.sh *.org
${top_srcdir}/tools/build_qmckl_h.sh
2021-03-09 01:16:23 +01:00
#+end_src
Then we create the list of ~*.o~ files to be created, for library
functions:
2021-03-18 18:02:06 +01:00
#+begin_src bash
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"
2021-03-09 01:16:23 +01:00
done >> $OUTPUT
#+end_src
for tests in C:
2021-03-18 18:02:06 +01:00
#+begin_src bash
2021-03-09 01:16:23 +01:00
TESTS=""
for i in $(ls test_qmckl_*.c) ; do
2021-03-19 13:47:50 +01:00
FILE=${i%.c}
TESTS+=" ${FILE}.o"
2021-03-09 01:16:23 +01:00
done >> $OUTPUT
#+end_src
and for tests in Fortran:
2021-03-18 18:02:06 +01:00
#+begin_src bash
2021-03-09 01:16:23 +01:00
TESTS_F=""
for i in $(ls test_qmckl_*_f.f90) ; do
2021-03-19 13:47:50 +01:00
FILE=${i%.f90}
TESTS_F+=" ${FILE}.o"
2021-03-09 01:16:23 +01:00
done >> $OUTPUT
#+end_src
2021-05-04 17:10:20 +02:00
Finally, we append the variables to the Makefile
2021-03-09 01:16:23 +01:00
2021-05-04 17:10:20 +02:00
#+begin_src bash :noweb yes
2021-03-09 01:16:23 +01:00
cat << EOF > ${OUTPUT}
2021-04-20 18:33:36 +02:00
.POSIX:
.SUFFIXES:
2021-05-10 10:05:50 +02:00
package = @PACKAGE_TARNAME@
version = @PACKAGE_VERSION@
# VPATH-related substitution variables
srcdir = @srcdir@
VPATH = @srcdir@
2021-05-07 12:47:56 +02:00
prefix = @prefix@
2021-04-20 18:33:36 +02:00
2021-05-09 02:12:38 +02:00
CC = @CC@
DEFS = @DEFS@
2021-05-10 10:05:50 +02:00
CFLAGS = @CFLAGS@ -I\$(top_srcdir)/munit/ -I\$(top_srcdir)/include -I.
2021-05-09 02:12:38 +02:00
CPPFLAGS = @CPPFLAGS@
LIBS = @LIBS@
2021-03-09 01:16:23 +01:00
2021-05-07 12:47:56 +02:00
FC = @FC@
FCFLAGS= @FCFLAGS@
2021-04-20 18:33:36 +02:00
2021-03-09 01:16:23 +01: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
2021-03-09 01:16:23 +01:00
2021-05-10 10:05:50 +02:00
export
2021-05-04 17:10:20 +02:00
echo '
2021-05-07 12:47:56 +02:00
<<rules>>
2021-05-04 17:10:20 +02:00
' >> ${OUTPUT}
2021-05-07 12:47:56 +02:00
2021-05-04 17:10:20 +02:00
#+end_src
and the rules:
#+NAME: rules
#+begin_src makefile :tangle no
2021-05-10 10:05:50 +02:00
top_srcdir=$(srcdir)/..
shared_lib=$(top_srcdir)/lib/libqmckl.so
static_lib=$(top_srcdir)/lib/libqmckl.a
qmckl_h=$(top_srcdir)/include/qmckl.h
qmckl_f=$(top_srcdir)/share/qmckl/fortran/qmckl_f.f90
munit=$(top_srcdir)/munit/munit.c
2021-03-09 01:16:23 +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)
2021-03-09 01:16:23 +01: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-09 02:12:38 +02:00
$(CC) $(CFLAGS) $(CPPFLAGS) $(DEFS) $(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)
2021-05-09 02:12:38 +02:00
$(CC) $(CFLAGS) $(CPPFLAGS) $(DEFS) \
2021-05-10 10:05:50 +02:00
-Wl,-rpath,$(top_srcdir)/lib -L$(top_srcdir)/lib $(munit) $(TESTS) \
2021-05-09 02:12:38 +02:00
$(TESTS_F) -lqmckl $(LIBS) $(FCLIBS) test_qmckl.c -o $@
2021-03-09 01:16:23 +01:00
2021-04-20 18:33:36 +02:00
check: test_qmckl test_qmckl_shared
2021-03-09 01:16:23 +01:00
./test_qmckl
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)
2021-05-10 10:05:50 +02:00
install $(top_srcdir)/share/doc/qmckl/html/*.html $(DESTDIR)$(docdir)/html/
install $(top_srcdir)/share/doc/qmckl/html/*.css $(DESTDIR)$(docdir)/html/
install $(top_srcdir)/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-09 02:12:38 +02:00
$(CC) $(CFLAGS) $(CPPFLAGS) $(DEFS) -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-04-30 01:26:19 +02:00
.PHONY: check cppcheck clean all
2021-05-04 17:10:20 +02:00
#+end_src
* Script to tangle the org-mode files
:PROPERTIES:
:header-args: :tangle tangle.sh :noweb yes :shebang #!/bin/bash :comments org
:END:
2021-03-09 01:16:23 +01:00
2021-05-04 17:10:20 +02:00
#+begin_src bash
# <<header()>>
<<check_src>>
#+end_src
This file needs to be run from the QMCKL =src= directory.
It tangles all the files in the directory. It uses the
=config_tangle.el= file, which contains information required to
compute the current file names using for example ~(eval c)~ to get
the name of the produced C file.
The file is not tangled if the last modification date of the org
file is less recent than one of the tangled files.
#+begin_src bash
function tangle()
{
local org_file=$1
local c_file=${org_file%.org}.c
local f_file=${org_file%.org}.f90
if [[ ${org_file} -ot ${c_file} ]] ; then
return
elif [[ ${org_file} -ot ${f_file} ]] ; then
return
fi
2021-05-10 10:05:50 +02:00
emacs --batch ${org_file} --load=${top_srcdir}/tools/config_tangle.el -f org-babel-tangle
2021-05-04 17:10:20 +02:00
}
for i in $@
do
echo "--- ${i} ----"
tangle ${i}
done
2021-03-18 18:02:06 +01:00
#+end_src
2021-03-09 01:16:23 +01:00
* Script to build the final qmckl.h file
:PROPERTIES:
:header-args:bash: :tangle build_qmckl_h.sh :noweb yes :shebang #!/bin/bash :comments org
:END:
#+begin_src bash :noweb yes
# <<header()>>
#+end_src
#+NAME: qmckl-header
#+begin_src text :noweb yes
------------------------------------------
QMCkl - Quantum Monte Carlo kernel library
------------------------------------------
Documentation : <<url-web()>>
Issues : <<url-issues()>>
<<license()>>
2021-03-18 18:02:06 +01:00
2021-03-09 01:16:23 +01:00
#+end_src
All the produced header files are concatenated in the =qmckl.h=
file, located in the include directory. The =*_private.h= files
are excluded.
Put =.h= files in the correct order:
2021-03-18 18:02:06 +01:00
#+begin_src bash
2021-03-09 01:16:23 +01:00
HEADERS=""
for i in $(cat table_of_contents)
do
2021-03-30 14:51:23 +02:00
HEADERS+="${i%.org}_type.h "
done
for i in $(cat table_of_contents)
do
HEADERS+="${i%.org}_func.h "
2021-03-09 01:16:23 +01:00
done
#+end_src
Generate C header file
2021-03-18 18:02:06 +01:00
#+begin_src bash
2021-05-10 10:05:50 +02:00
OUTPUT="${top_srcdir}/include/qmckl.h"
2021-03-09 01:16:23 +01:00
cat << EOF > ${OUTPUT}
/*
,* <<qmckl-header>>
,*/
#ifndef __QMCKL_H__
#define __QMCKL_H__
#include <stdlib.h>
#include <stdint.h>
2021-04-21 12:44:03 +02:00
#include <stdbool.h>
2021-03-09 01:16:23 +01:00
EOF
for i in ${HEADERS}
do
if [[ -f $i ]] ; then
cat $i >> ${OUTPUT}
fi
done
cat << EOF >> ${OUTPUT}
#endif
EOF
#+end_src
Generate Fortran interface file from all =qmckl_*_fh.f90= files
2021-03-18 18:02:06 +01:00
#+begin_src bash
2021-03-30 14:51:23 +02:00
HEADERS_TYPE="qmckl_*_fh_type.f90"
HEADERS="qmckl_*_fh_func.f90"
2021-03-09 01:16:23 +01:00
2021-05-10 10:05:50 +02:00
OUTPUT="${top_srcdir}/share/qmckl/fortran/qmckl_f.f90"
2021-03-09 01:16:23 +01:00
cat << EOF > ${OUTPUT}
!
! <<qmckl-header>>
!
module qmckl
use, intrinsic :: iso_c_binding
EOF
2021-03-30 14:51:23 +02:00
for i in ${HEADERS_TYPE}
do
cat $i >> ${OUTPUT}
done
2021-03-09 01:16:23 +01:00
for i in ${HEADERS}
do
cat $i >> ${OUTPUT}
done
cat << EOF >> ${OUTPUT}
end module qmckl
EOF
#+end_src
* Script to build the documentation
2021-03-23 22:23:49 +01:00
:PROPERTIES:
:header-args:bash: :tangle build_doc.sh :noweb yes :shebang #!/bin/bash :comments org
:END:
First define readonly global variables.
2021-04-21 13:17:33 +02:00
2021-03-23 22:23:49 +01:00
#+begin_src bash :noweb yes
2021-05-10 10:05:50 +02:00
readonly DOCS=${top_srcdir}/share/doc/qmckl/
readonly SRC=${top_srcdir}/src/
2021-04-30 01:26:19 +02:00
readonly HTMLIZE=${DOCS}/html/htmlize.el
2021-05-10 10:05:50 +02:00
readonly CONFIG_DOC=${top_srcdir}/tools/config_doc.el
readonly CONFIG_TANGLE=${top_srcdir}/tools/config_tangle.el
2021-03-23 22:23:49 +01:00
#+end_src
Check that all the defined global variables correspond to files.
#+begin_src bash :noweb yes
function check_preconditions()
{
2021-05-10 10:05:50 +02:00
if [[ -z ${top_srcdir} ]]
2021-03-23 22:23:49 +01:00
then
2021-05-10 10:05:50 +02:00
print "top_srcdir is not defined"
2021-03-23 22:23:49 +01:00
exit 1
fi
2021-04-30 01:26:19 +02:00
for dir in ${DOCS}/html ${DOCS}/text ${SRC}
2021-03-23 22:23:49 +01:00
do
if [[ ! -d ${dir} ]]
then
print "${dir} not found"
exit 2
fi
done
2021-04-21 13:17:33 +02:00
2021-03-23 22:23:49 +01:00
for file in ${CONFIG_DOC} ${CONFIG_TANGLE}
do
if [[ ! -f ${file} ]]
then
print "${file} not found"
exit 3
fi
done
}
#+end_src
~install_htmlize~ installs the htmlize Emacs plugin if the
=htmlize.el= file is not present.
#+begin_src bash :noweb yes
function install_htmlize()
{
local url="https://github.com/hniksic/emacs-htmlize"
local repo="emacs-htmlize"
2021-04-21 13:17:33 +02:00
2021-03-23 22:23:49 +01:00
[[ -f ${HTMLIZE} ]] || (
2021-04-30 01:26:19 +02:00
cd ${DOCS}/html
2021-03-23 22:23:49 +01:00
git clone ${url} \
&& cp ${repo}/htmlize.el ${HTMLIZE} \
&& rm -rf ${repo}
cd -
)
# Assert htmlize is installed
[[ -f ${HTMLIZE} ]] \
|| exit 1
}
#+end_src
Extract documentation from an org-mode file.
#+begin_src bash :noweb yes
function extract_doc()
{
local org=$1
2021-04-21 13:17:33 +02:00
local local_html=${SRC}/${org%.org}.html
2021-04-21 13:26:11 +02:00
local local_text=${SRC}/${org%.org}.txt
2021-04-30 01:26:19 +02:00
local html=${DOCS}/html/${org%.org}.html
local text=${DOCS}/text/${org%.org}.txt
2021-03-23 22:23:49 +01:00
if [[ -f ${html} && ${org} -ot ${html} ]]
then
return
fi
emacs --batch \
--load ${HTMLIZE} \
--load ${CONFIG_DOC} \
${org} \
--load ${CONFIG_TANGLE} \
2021-04-21 13:26:11 +02:00
-f org-html-export-to-html \
-f org-ascii-export-to-ascii
2021-04-30 01:26:19 +02:00
mv ${local_html} ${DOCS}/html
mv ${local_text} ${DOCS}/text
2021-03-23 22:23:49 +01:00
}
#+end_src
The main function of the script.
2021-04-21 13:17:33 +02:00
2021-03-23 22:23:49 +01:00
#+begin_src bash :noweb yes
function main() {
2021-04-21 13:17:33 +02:00
check_preconditions || exit 1
2021-03-23 22:23:49 +01:00
# Install htmlize if needed
2021-04-21 13:17:33 +02:00
install_htmlize || exit 2
2021-03-23 22:23:49 +01:00
# Create documentation
cd ${SRC} \
|| exit 3
for i in *.org
do
echo
echo "======= ${i} ======="
extract_doc ${i}
done
if [[ $? -eq 0 ]]
then
2021-04-30 01:26:19 +02:00
cd ${DOCS}/html
2021-03-23 22:23:49 +01:00
rm -f index.html
ln README.html index.html
exit 0
else
exit 3
fi
}
main
#+end_src