commit 5e01f778adb7898b9d120b05255d627f540f9828
parent fbc4eaef6d801b77df11e5e0c2f1de9282e08d07
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 13 Oct 2022 10:59:21 +0200
Write a POSIX Makefile as an alternative to CMake
Diffstat:
| M | .gitignore | | | 14 | ++++++++------ |
| A | Makefile | | | 164 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | config.mk | | | 41 | +++++++++++++++++++++++++++++++++++++++++ |
| A | make.sh | | | 90 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | smc.pc.in | | | 10 | ++++++++++ |
5 files changed, 313 insertions(+), 6 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,11 +1,13 @@
.gitignore
-CMakeCache.txt
-CMakeFiles
-Makefile
-tmp
[Bb]uild*
*.sw[po]
-*.[ao]
+*.[aod]
+*.so
*~
+test*
+!test*.[ch]
+.config
+.test
tags
-
+smc.pc
+image.ppm
diff --git a/Makefile b/Makefile
@@ -0,0 +1,164 @@
+# Copyright (C) 2015-2018, 2021, 2022 |Meso|Star> (contact@meso-star.com)
+#
+# This software is a computer program whose purpose is to generate files
+# used to build the Star-MC library.
+#
+# This software is governed by the CeCILL license under French law and
+# abiding by the rules of distribution of free software. You can use,
+# modify and/or redistribute the software under the terms of the CeCILL
+# license as circulated by CEA, CNRS and INRIA at the following URL
+# "http://www.cecill.info".
+#
+# As a counterpart to the access to the source code and rights to copy,
+# modify and redistribute granted by the license, users are provided only
+# with a limited warranty and the software's author, the holder of the
+# economic rights, and the successive licensors have only limited
+# liability.
+#
+# In this respect, the user's attention is drawn to the risks associated
+# with loading, using, modifying and/or developing or reproducing the
+# software by the user in light of its specific status of free software,
+# that may mean that it is complicated to manipulate, and that also
+# therefore means that it is reserved for developers and experienced
+# professionals having in-depth computer knowledge. Users are therefore
+# encouraged to load and test the software's suitability as regards their
+# requirements in conditions enabling the security of their systems and/or
+# data to be ensured and, more generally, to use and operate it in the
+# same conditions as regards security.
+#
+# The fact that you are presently reading this means that you have had
+# knowledge of the CeCILL license and that you accept its terms.
+
+.POSIX:
+.SUFFIXES: # Clean up default inference rules
+
+include config.mk
+
+################################################################################
+# Star-MC building
+################################################################################
+SRC =\
+ src/smc_device.c\
+ src/smc_doubleN.c\
+ src/smc_estimator.c\
+ src/smc_type.c
+
+OBJ = $(SRC:.c=.o)
+DEP = $(SRC:.c=.d)
+
+build_library: .config $(DEP)
+ @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) libsmc.so
+
+$(OBJ): config.mk
+
+libsmc.so: $(OBJ)
+ @echo "LD $@"
+ @$(CC) $(CFLAGS) $(LIBS) -fopenmp -o $@ $(OBJ) $(LDFLAGS)
+
+.config: config.mk
+ @echo "Find packages"; rm -f $@
+ @$(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys \
+ || (echo "RSys $(RSYS_VERSION) not found" >&2; exit 1)
+ @$(PKG_CONFIG) --atleast-version $(STAR-SP_VERSION) star-sp \
+ || (echo "Star-SP $(STAR-SP_VERSION) not found" >&2; exit 1)
+ @$(PKG_CONFIG) --atleast-version $(STAR-3D_VERSION) s3d \
+ || echo "Star-3D $(STAR-3D_VERSION) not found" >&2 # Not required
+ @echo "config done" > $@
+
+.SUFFIXES: .c .d .o
+.c.d:
+ @echo "DEP $@"
+ @$(CC) $(CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@
+
+.c.o:
+ @echo "CC $@"
+ @$(CC) $(CFLAGS) $(INCS) -fopenmp -DSMC_SHARED_BUILD -c $< -o $@
+
+################################################################################
+# Installation
+################################################################################
+pkg:
+ @echo "Setup smc.pc"
+ @sed -e 's#@PREFIX@#$(PREFIX)#g' \
+ -e 's#@VERSION@#$(VERSION)#g' \
+ -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g' \
+ -e 's#@STAR-3D_VERSION@#$(STAR-3D_VERSION)#g' \
+ -e 's#@STAR-SP_VERSION@#$(STAR-SP_VERSION)#g' \
+ smc.pc.in > smc.pc
+
+install: build_library pkg
+ mkdir -p $(DESTDIR)$(PREFIX)/lib
+ mkdir -p $(DESTDIR)$(PREFIX)/lib/pkgconfig
+ mkdir -p $(DESTDIR)$(PREFIX)/include/star
+ mkdir -p $(DESTDIR)$(PREFIX)/share/doc/star-mc
+ cp libsmc.so $(DESTDIR)$(PREFIX)/lib
+ cp smc.pc $(DESTDIR)$(PREFIX)/lib/pkgconfig
+ cp src/smc.h $(DESTDIR)$(PREFIX)/include/star
+ cp COPYING.en COPYING.fr README.md $(DESTDIR)$(PREFIX)/share/doc/star-mc
+
+uninstall:
+ rm -f $(DESTDIR)$(PREFIX)/lib/libsmc.so
+ rm -f $(DESTDIR)$(PREFIX)/lib/pkgconfig/smc.pc
+ rm -f $(DESTDIR)$(PREFIX)/include/star/smc.h
+ rm -f $(DESTDIR)$(PREFIX)/share/doc/star-mc/COPYING.en
+ rm -f $(DESTDIR)$(PREFIX)/share/doc/star-mc/COPYING.fr
+ rm -f $(DESTDIR)$(PREFIX)/share/doc/star-mc/README.md
+
+################################################################################
+# Miscellaneous targets
+################################################################################
+all: build_library build_tests
+
+clean: clean_test
+ @rm -f $(OBJ) $(TEST_OBJ) libsmc.so .test smc.pc .config
+
+distclean: clean
+ @rm -f $(DEP) $(TEST_DEP)
+
+################################################################################
+# Tests
+################################################################################
+TEST_SRC =\
+ src/test_smc_device.c\
+ src/test_smc_doubleN.c\
+ src/test_smc_errors.c\
+ src/test_smc_light_path.c\
+ src/test_smc_solve.c
+
+TEST_OBJ = $(TEST_SRC:.c=.o)
+TEST_DEP = $(TEST_SRC:.c=.d)
+
+test: build_tests
+ @$(SHELL) make.sh run_test $(TEST_SRC)
+
+build_tests: build_library $(TEST_DEP) .test
+ @$(MAKE) -fMakefile -f.test $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) test_bin
+
+.test: Makefile
+ @echo "Setup tests"
+ @$(SHELL) make.sh config_test $(PKG_CONFIG) $(TEST_SRC) > .test
+
+test_run: test_bin
+ @$(SHELL) make.sh run_test $(TEST_SRC)
+
+clean_test:
+ @$(SHELL) make.sh clean_test $(TEST_SRC)
+
+$(TEST_OBJ): config.mk
+ @echo "CC $@"
+ @$(CC) $(CFLAGS) $(INCS) -c $(@:.o=.c) -o $@
+
+test_smc_device: libsmc.so
+ @echo "LD $@"
+ @$(CC) $(CFLAGS) -fopenmp -o $@ src/$@.o -L$$(pwd) -lsmc $(LIBS)
+
+test_smc_doubleN\
+test_smc_errors \
+test_smc_solve \
+: libsmc.so
+ @echo "LD $@"
+ @$(CC) $(CFLAGS) -o $@ src/$@.o -L$$(pwd) -lsmc $(LIBS)
+
+test_smc_light_path: libsmc.so
+ @echo "LD $@"
+ @$(CC) $(CFLAGS) -o $@ src/$@.o -L$$(pwd) -lsmc $(LIBS) $(STAR-3D_LIB)
diff --git a/config.mk b/config.mk
@@ -0,0 +1,41 @@
+VERSION = 0.5.0
+
+PREFIX = /usr/local
+PKG_CONFIG = pkg-config
+
+################################################################################
+# Dependencies
+################################################################################
+RSYS_VERSION = 0.6
+RSYS_INC = $$($(PKG_CONFIG) --cflags rsys)
+RSYS_LIB = $$($(PKG_CONFIG) --libs rsys)
+
+STAR-SP_VERSION = 0.12.1
+STAR-SP_INC = $$($(PKG_CONFIG) --cflags star-sp)
+STAR-SP_LIB = $$($(PKG_CONFIG) --libs star-sp)
+
+# Optional
+STAR-3D_VERSION = 0.4
+STAR-3D_INC = $$($(PKG_CONFIG) --cflags s3d)
+STAR-3D_LIB = $$($(PKG_CONFIG) --libs s3d)
+
+INCS=$(RSYS_INC) $(STAR-SP_INC)
+LIBS=$(RSYS_LIB) $(STAR-SP_LIB)
+
+################################################################################
+# Compilation options
+################################################################################
+CC = cc
+
+CPPFLAGS = -DNDEBUG
+WFLAGS =\
+ -Wall\
+ -Wconversion\
+ -Wextra\
+ -Wmissing-declarations\
+ -Wmissing-prototypes\
+ -Wshadow
+CFLAGS = -O3 -std=c89 -pedantic -fPIC -fvisibility=hidden -fstrict-aliasing\
+ -Wl,--no-undefined $(WFLAGS) $(CPPFLAGS) # Compiler options
+LDFLAGS = -shared # Linker options
+
diff --git a/make.sh b/make.sh
@@ -0,0 +1,90 @@
+#!/bin/sh -e
+
+# Copyright (C) 2015-2018, 2021, 2022 |Meso|Star> (contact@meso-star.com)
+#
+# This software is a computer program whose purpose is to generate files
+# used to build the Star-MC library.
+#
+# This software is governed by the CeCILL license under French law and
+# abiding by the rules of distribution of free software. You can use,
+# modify and/or redistribute the software under the terms of the CeCILL
+# license as circulated by CEA, CNRS and INRIA at the following URL
+# "http://www.cecill.info".
+#
+# As a counterpart to the access to the source code and rights to copy,
+# modify and redistribute granted by the license, users are provided only
+# with a limited warranty and the software's author, the holder of the
+# economic rights, and the successive licensors have only limited
+# liability.
+#
+# In this respect, the user's attention is drawn to the risks associated
+# with loading, using, modifying and/or developing or reproducing the
+# software by the user in light of its specific status of free software,
+# that may mean that it is complicated to manipulate, and that also
+# therefore means that it is reserved for developers and experienced
+# professionals having in-depth computer knowledge. Users are therefore
+# encouraged to load and test the software's suitability as regards their
+# requirements in conditions enabling the security of their systems and/or
+# data to be ensured and, more generally, to use and operate it in the
+# same conditions as regards security.
+#
+# The fact that you are presently reading this means that you have had
+# knowledge of the CeCILL license and that you accept its terms.
+
+config_test()
+{
+ if [ $# -lt 2 ]; then
+ echo "usage: config_test pkg-config [src ...]" >&2
+ exit 1
+ fi
+
+ PKG_CONFIG="$1"
+ shift 1
+
+ for i in "$@"; do
+ test=$(echo "${i}" | sed 's/src\/\(.\{1,\}\).c$/\1/')
+
+ if ! [ ${test} == "test_smc_light_path" ] \
+ || "${PKG_CONFIG}" --exists s3d; then
+ test_list="${test_list} ${test}"
+ printf "%s: %s\n" "${test}" "src/${test}.o"
+ fi
+ done
+ printf "test_bin: %s\n" "${test_list}"
+}
+
+run_test()
+{
+ n=0
+
+ for i in "$@"; do
+ test=$(echo "${i}" | sed 's/src\/\(.\{1,\}\).c$/\1/')
+
+ if [ ! -f "${test}" ]; then
+ continue;
+ fi
+
+ printf "%s " "${test}"
+ if ./"${test}" > /dev/null 2>&1; then
+ printf "\e[1;32mOK\e[m\n"
+ else
+ printf "\e[1;31mErreur\e[m\n"
+ n=$((n+1))
+ fi
+ done
+
+ if [ "${n}" -ne 0 ]; then
+ printf "%d errors\n" "${n}"
+ exit 1
+ fi
+}
+
+clean_test()
+{
+ for i in "$@"; do
+ test=$(echo "${i}" | sed 's/src\/\(.\{1,\}\).c$/\1/')
+ rm -f "${test}"
+ done
+}
+
+"$@"
diff --git a/smc.pc.in b/smc.pc.in
@@ -0,0 +1,10 @@
+prefix=@PREFIX@
+includedir=${prefix}/include
+libdir=${prefix}/lib
+
+Requires.private: rsys > @RSYS_VERSION@, s3d > @STAR-3D_VERSION@, star-sp > @STAR-SP_VERSION@
+Name: Star-MonteCarlo
+Description: Star-MonteCarlo library
+Version: @VERSION@
+Libs: -L${libdir} -lsmc
+CFlags: -I${includedir}