commit 0d21b5ed9636029cfef77be2631886bc612ce5cb
parent ce88348a7fd2fdedd12b012bc4c5f4c04ea8f3c5
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 20 Jul 2022 20:50:51 +0200
Write a POSIX Makefile as an alternative to CMake
Diffstat:
| M | .gitignore | | | 12 | +++++++----- |
| A | Makefile | | | 171 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | config.mk | | | 45 | +++++++++++++++++++++++++++++++++++++++++++++ |
| A | make.sh | | | 92 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | star-sp.pc.in | | | 10 | ++++++++++ |
5 files changed, 325 insertions(+), 5 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
+star-sp.pc
diff --git a/Makefile b/Makefile
@@ -0,0 +1,171 @@
+# Copyright (C) 2015-2022 |Meso|Star> (contact@meso-star.com)
+#
+# This software is a library whose purpose is to generate [pseudo] random
+# numbers and random variates.
+#
+# 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
+
+################################################################################
+# RSys building
+################################################################################
+SRC =\
+ src/ssp_ran.c\
+ src/ssp_ranst_discrete.c\
+ src/ssp_ranst_gaussian.c\
+ src/ssp_ranst_piecewise_linear.c\
+ src/ssp_rng.c\
+ src/ssp_rng_proxy.c
+
+OBJ = $(SRC:.c=.o)
+DEP = $(SRC:.c=.d)
+
+build_library: .config $(DEP)
+ @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) libstar-sp.so
+
+$(OBJ): config.mk
+
+libstar-sp.so: $(OBJ)
+ @echo "LD $@"
+ @$(CXX) $(CXXFLAGS) $(LDFLAGS) $(LIBS) -o $@ $(OBJ)
+
+.config: Makefile
+ @echo "Find packages"
+ @if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \
+ echo "rsys $(RSYS_VERSION) not found" >&2; exit 1; fi
+ @if ! $(PKG_CONFIG) --atleast-version $(RANDOM123_VERSION) random123; then \
+ echo "random123 $(RANDOM123_VERSION) not found" >&2; exit 1; fi
+ @echo "config done" > .config
+
+.SUFFIXES: .c .d .o
+.c.d:
+ @echo "DEP $@"
+ @$(CXX) $(CXXFLAGS) $(INCS) -MM -MT "$(@:.d=.o) $@" $< -MF $@
+
+.c.o:
+ @echo "CXX $@"
+ @$(CXX) $(CXXFLAGS) $(INCS) -DSSP_SHARED_BUILD -c $< -o $@
+
+################################################################################
+# Installation
+################################################################################
+pkg:
+ @echo "Setup star-sp.pc"
+ @sed -e 's#@PREFIX@#$(PREFIX)#g' \
+ -e 's#@VERSION@#$(VERSION)#g' \
+ -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g' \
+ -e 's#@RANDOM123_VERSION@#$(RANDOM123_VERSION)#g' \
+ star-sp.pc.in > star-sp.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-sp
+ cp libstar-sp.so $(DESTDIR)$(PREFIX)/lib
+ cp star-sp.pc $(DESTDIR)$(PREFIX)/lib/pkgconfig
+ cp src/ssp.h $(DESTDIR)$(PREFIX)/include/star
+ cp COPYING.en COPYING.fr README.md $(DESTDIR)$(PREFIX)/share/doc/star-sp
+
+uninstall:
+ rm -f $(DESTDIR)$(PREFIX)/lib/libstar-sp.so
+ rm -f $(DESTDIR)$(PREFIX)/lib/pkgconfig/star-sp.pc
+ rm -f $(DESTDIR)$(PREFIX)/share/doc/star-sp/COPYING.en
+ rm -f $(DESTDIR)$(PREFIX)/share/doc/star-sp/COPYING.fr
+ rm -f $(DESTDIR)$(PREFIX)/share/doc/star-sp/README.md
+ rm -f $(DESTDIR)$(PREFIX)/include/star/ssp.h
+
+################################################################################
+# Miscellaneous targets
+################################################################################
+all: build_library build_tests
+
+clean: clean_test
+ @rm -f $(OBJ) $(TEST_OBJ) libstar-sp.so .test star-sp.pc .config
+
+distclean: clean
+ @rm -f $(DEP) $(TEST_DEP)
+
+################################################################################
+# Tests
+################################################################################
+TEST_SRC =\
+ src/test_ssp_ran_circle.c\
+ src/test_ssp_ran_discrete.c\
+ src/test_ssp_ran_gaussian.c\
+ src/test_ssp_ran_hemisphere.c\
+ src/test_ssp_ran_hg.c\
+ src/test_ssp_ran_piecewise_linear.c\
+ src/test_ssp_ran_sphere.c\
+ src/test_ssp_ran_sphere_cap.c\
+ src/test_ssp_ran_spherical_zone.c\
+ src/test_ssp_ran_tetrahedron.c\
+ src/test_ssp_ran_triangle.c\
+ src/test_ssp_ran_uniform_disk.c\
+ src/test_ssp_rng.c\
+ src/test_ssp_rng_proxy.c
+
+TEST_OBJ = $(TEST_SRC:.c=.o)
+TEST_DEP = $(TEST_SRC:.c=.d)
+
+test: build_tests
+ @$(SHELL) make.sh run_test "$(BUILD_R123_AES)" $(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 $(TEST_SRC) > .test
+
+clean_test:
+ @$(SHELL) make.sh clean_test $(TEST_SRC)
+
+test_ssp_ran_circle \
+test_ssp_ran_discrete \
+test_ssp_ran_gaussian \
+test_ssp_ran_hemisphere \
+test_ssp_ran_hg \
+test_ssp_ran_piecewise_linear \
+test_ssp_ran_sphere \
+test_ssp_ran_sphere_cap \
+test_ssp_ran_spherical_zone \
+test_ssp_ran_tetrahedron \
+test_ssp_ran_triangle \
+test_ssp_ran_uniform_disk \
+test_ssp_rng \
+test_ssp_rng_proxy : libstar-sp.so
+ @echo "LD $@"
+ @$(CC) $(CFLAGS) -o $@ src/$@.o -L$$(pwd) -lstar-sp $(RSYS_LIB)
+
+$(TEST_OBJ): config.mk
+ @echo "CC $@"
+ @$(CC) $(CFLAGS) $(RSYS_INC) -c $(@:.o=.c) -o $@
diff --git a/config.mk b/config.mk
@@ -0,0 +1,45 @@
+VERSION = 0.13.0 # Library version
+
+PREFIX = /usr/local
+PKG_CONFIG = pkg-config
+
+BUILD_R123_AES = 1
+
+################################################################################
+# Dependencies
+################################################################################
+RSYS_VERSION = 0.6
+RSYS_INC = $$($(PKG_CONFIG) --cflags rsys)
+RSYS_LIB = $$($(PKG_CONFIG) --libs rsys)
+
+RANDOM123_VERSION = 1.09
+RANDOM123_INC = $$($(PKG_CONFIG) --cflags random123)
+RANDOM123_LIB = $$($(PKG_CONFIG) --libs random123)
+
+INCS=$(RSYS_INC) $(RANDOM123_INC)
+LIBS=$(RSYS_LIB) $(RANDOM123_LIB)
+
+################################################################################
+# Compilation options
+################################################################################
+
+# Compilers
+CC = cc
+CXX = c++
+
+CPPFLAGS = -DNDEBUG $$([ ! "$(BUILD_R123_AES)" = 0 ] && echo -DWITH_R123_AES)
+
+WFLAGS =\
+ -Wall\
+ -Wconversion\
+ -Wextra\
+ -Wmissing-declarations\
+ -Wshadow
+
+# Compiler options
+FLAGS = -O3 -pedantic -fPIC -fvisibility=hidden -fstrict-aliasing \
+ -Wl,--no-undefined $(WFLAGS) $(CPPFLAGS)
+CFLAGS = $(FLAGS) -std=c89 -Wmissing-prototypes
+CXXFLAGS = $(FLAGS) -std=c++11 $$([ ! "$(BUILD_R123_AES)" = 0 ] && echo -maes)
+
+LDFLAGS = -shared # Linker options
diff --git a/make.sh b/make.sh
@@ -0,0 +1,92 @@
+#!/bin/sh -e
+
+# Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com)
+#
+# This software is a computer program whose purpose is to generate files used
+# to build the Star-3D 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()
+{
+ for i in "$@"; do
+ test=$(echo "${i}" | sed 's/src\/\(.\{1,\}\).c$/\1/')
+ test_list="${test_list} ${test}"
+ printf "%s: %s\n" "${test}" "src/${test}.o"
+ done
+ printf "test_bin: %s\n" "${test_list}"
+}
+
+check()
+{
+ if [ $# -lt 1 ]; then
+ echo "usage: check <name> <prog>" >&2
+ exit 1
+ fi
+
+ name="$1"
+ prog="$2"
+ shift 2
+ printf "%s " "${name}"
+ if ./"${prog}" "$@" > /dev/null 2>&1; then
+ printf "\e[1;32mOK\e[m\n"
+ else
+ printf "\e[1;31mError\e[m\n"
+ fi
+}
+
+run_test()
+{
+ build_r123_aes=$1
+ shift 1
+
+ for i in "$@"; do
+ test=$(echo "${i}" | sed 's/src\/\(.\{1,\}\).c$/\1/')
+ if ! [ "${test}" = "test_ssp_rng" ]; then
+ check "${test}" "${test}"
+ else
+ if [ ! "${build_r123_aes}" = 0 ]; then
+ check "${test}_aes" "${test}" aes
+ fi
+ check "${test}_kiss" "${test}" kiss
+ check "${test}_mt19937_64" "${test}" mt19937_64
+ check "${test}_ranlux48" "${test}" ranlux48
+ check "${test}_random_device" "${test}" random_device
+ check "${test}_threefry" "${test}" threefry
+ fi
+ done
+}
+
+clean_test()
+{
+ for i in "$@"; do
+ test=$(echo "${i}" | sed 's/src\/\(.\{1,\}\).c$/\1/')
+ rm -f "${test}"
+ done
+}
+
+"$@"
diff --git a/star-sp.pc.in b/star-sp.pc.in
@@ -0,0 +1,10 @@
+prefix=@PREFIX@
+includedir=${prefix}/include
+libdir=${prefix}/lib
+
+Requires.private: rsys >= @RSYS_VERSION@, random123 >= @RANDOM123_VERSION@
+Name: Star-SamPling
+Description: Star-Sampling library
+Version: @VERSION@
+Libs: -L${libdir} -lstar-sp
+CFlags: -I${includedir}