stardis

Perform coupled heat transfer calculations
git clone git://git.meso-star.fr/stardis.git
Log | Files | Refs | README | LICENSE

commit 8537d3dee9959a415e06d25214c3dcf8205f40a3
parent 227fbf464035219aec1fe5cabdacc34480827074
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue, 23 Jan 2024 11:31:58 +0100

Replace CMake by POSIX make

The build procedure is written in POSIX make, which the user can
configure via the config.mk file. The make.sh script contains commands
that could be found directly in POSIX make, but which are placed here to
simplify writing the Makefile. Finally, a pkg-config file is provided to
link the library as an external dependency.

In addition to the features previously provided by its CMake
alternative, this Makefile supports the use of static libraries and
provides an uninstall target. It also enable compiler and linker options
that activate various hardening features aimed at increasing the
security and robustness of generated binaries. In any case, the main
motivation behind its writing is to use a good old well-established
standard with simple features, available on all UNIX systems, thus
simplifying its portability and support while being much lighter

Please note that the generation of man pages is not managed by the
Makefile. Current manual pages will be translated into mandoc macros to
avoid using the cumbersome asciidoc tool suite, and to ensure
consistency with other manual pages by construction. As a result, no
intermediate manual page generation step will be necessary.

Diffstat:
M.gitignore | 14+++++++-------
AMakefile | 161+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aconfig.mk | 154+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Amake.sh | 39+++++++++++++++++++++++++++++++++++++++
Msrc/stardis-version.h.in | 6+++---
5 files changed, 364 insertions(+), 10 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,12 +1,12 @@ .gitignore -CMakeCache.txt -CMakeFiles -Makefile -tmp [Bb]uild* *.sw[po] -*.[ao] +*.[aod] *~ tags -*.orig - +.config +src/stardis-default.h +src/stardis-green-types.h +src/stardis-prog-properties.h +src/stardis-version.h +stardis diff --git a/Makefile b/Makefile @@ -0,0 +1,161 @@ +# Copyright (C) 2018-2023 |Méso|Star> (contact@meso-star.com) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +.POSIX: +.SUFFIXES: # Clean up default inference rules + +include config.mk + +MPI_DEF = -DSTARDIS_ENABLE_MPI + +################################################################################ +# Library building +################################################################################ +SRC =\ + src/stardis-app.c\ + src/stardis-args.c\ + src/stardis-compute.c\ + src/stardis-description.c\ + src/stardis-fluid.c\ + src/stardis-fluid-prog.c\ + src/stardis-fbound.c\ + src/stardis-fbound-prog.c\ + src/stardis-hbound.c\ + src/stardis-hbound-prog.c\ + src/stardis-hfbound.c\ + src/stardis-hfbound-prog.c\ + src/stardis-intface.c\ + src/stardis-main.c\ + src/stardis-output.c\ + src/stardis-parsing.c\ + src/stardis-program.c\ + src/stardis-sfconnect.c\ + src/stardis-sfconnect-prog.c\ + src/stardis-ssconnect.c\ + src/stardis-ssconnect-prog.c\ + src/stardis-solid.c\ + src/stardis-solid-prog.c\ + src/stardis-tbound.c\ + src/stardis-tbound-prog.c + +# Headers to configure +HDR=\ + src/stardis-default.h\ + src/stardis-green-types.h\ + src/stardis-prog-properties.h\ + src/stardis-version.h + +OBJ = $(SRC:.c=.o) +DEP = $(SRC:.c=.d) + +build_executable: .config $(HDR) $(DEP) + @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) stardis + +$(DEP) $(OBJ): config.mk + +stardis: $(OBJ) + $(CC) $(CFLAGS) $(DPDC_CFLAGS) -o $@ $(OBJ) $(LDFLAGS) $(DPDC_LIBS) + +.config: config.mk + @if [ "$(DISTRIB_PARALLELISM)" = "MPI" ]; then \ + if ! $(PKG_CONFIG) --atleast-version $(MPI_VERSION) $(MPI_PC); then \ + echo "$(MPI_PC) $(MPI_VERSION) not found" >&2; exit 1; fi; fi + @if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \ + echo "rsys $(RSYS_VERSION) not found" >&2; exit 1; fi + @if ! $(PKG_CONFIG) --atleast-version $(S3D_VERSION) s3d; then \ + echo "s3d $(S3D_VERSION) not found" >&2; exit 1; fi + @if ! $(PKG_CONFIG) --atleast-version $(SDIS_VERSION) sdis; then \ + echo "sdis $(SDIS_VERSION) not found" >&2; exit 1; fi + @if ! $(PKG_CONFIG) --atleast-version $(SENC3D_VERSION) senc3d; then \ + echo "senc3d $(SENC3D_VERSION) not found" >&2; exit 1; fi + @if ! $(PKG_CONFIG) --atleast-version $(SG3D_VERSION) sg3d; then \ + echo "sg3d $(SG3D_VERSION) not found" >&2; exit 1; fi + @if ! $(PKG_CONFIG) --atleast-version $(SSP_VERSION) star-sp; then \ + echo "star-sp $(SSP_VERSION) not found" >&2; exit 1; fi + @if ! $(PKG_CONFIG) --atleast-version $(SSTL_VERSION) sstl; then \ + echo "sstl $(SSTL_VERSION) not found" >&2; exit 1; fi + @echo "config done" > $@ + +src/stardis-default.h: config.mk src/stardis-default.h.in + sed -e 's/@STARDIS_ARGS_DEFAULT_TRAD@/$(STARDIS_ARGS_DEFAULT_TRAD)/' \ + -e 's/@STARDIS_ARGS_DEFAULT_TRAD_REFERENCE@/$(STARDIS_ARGS_DEFAULT_TRAD_REFERENCE)/' \ + -e 's/@STARDIS_ARGS_DEFAULT_COMPUTE_TIME@/$(STARDIS_ARGS_DEFAULT_COMPUTE_TIME)/' \ + -e 's/@STARDIS_ARGS_DEFAULT_PICARD_ORDER@/$(STARDIS_ARGS_DEFAULT_PICARD_ORDER)/' \ + -e 's/@STARDIS_ARGS_DEFAULT_RENDERING_FOV@/$(STARDIS_ARGS_DEFAULT_RENDERING_FOV)/' \ + -e 's/@STARDIS_ARGS_DEFAULT_RENDERING_IMG_HEIGHT@/$(STARDIS_ARGS_DEFAULT_RENDERING_IMG_HEIGHT)/' \ + -e 's/@STARDIS_ARGS_DEFAULT_RENDERING_IMG_WIDTH@/$(STARDIS_ARGS_DEFAULT_RENDERING_IMG_WIDTH)/' \ + -e 's/@STARDIS_ARGS_DEFAULT_RENDERING_OUTPUT_FILE_FMT@/$(STARDIS_ARGS_DEFAULT_RENDERING_OUTPUT_FILE_FMT)/' \ + -e 's/@STARDIS_ARGS_DEFAULT_RENDERING_POS@/$(STARDIS_ARGS_DEFAULT_RENDERING_POS)/' \ + -e 's/@STARDIS_ARGS_DEFAULT_RENDERING_SPP@/$(STARDIS_ARGS_DEFAULT_RENDERING_SPP)/' \ + -e 's/@STARDIS_ARGS_DEFAULT_RENDERING_TGT@/$(STARDIS_ARGS_DEFAULT_RENDERING_TGT)/' \ + -e 's/@STARDIS_ARGS_DEFAULT_RENDERING_TIME@/$(STARDIS_ARGS_DEFAULT_RENDERING_TIME)/' \ + -e 's/@STARDIS_ARGS_DEFAULT_RENDERING_UP@/$(STARDIS_ARGS_DEFAULT_RENDERING_UP)/' \ + -e 's/@STARDIS_ARGS_DEFAULT_SAMPLES_COUNT@/$(STARDIS_ARGS_DEFAULT_SAMPLES_COUNT)/' \ + -e 's/@STARDIS_ARGS_DEFAULT_SCALE_FACTOR@/$(STARDIS_ARGS_DEFAULT_SCALE_FACTOR)/' \ + -e 's/@STARDIS_ARGS_DEFAULT_VERBOSE_LEVEL@/$(STARDIS_ARGS_DEFAULT_VERBOSE_LEVEL)/' \ + $@.in > $@ + +src/stardis-version.h: config.mk src/stardis-version.h.in + sed -e 's/@STARDIS_APP_VERSION_MAJOR@/$(VERSION_MAJOR)/' \ + -e 's/@STARDIS_APP_VERSION_MINOR@/$(VERSION_MINOR)/' \ + -e 's/@STARDIS_APP_VERSION_PATCH@/$(VERSION_PATCH)/' \ + $@.in > $@ + +src/stardis-green-types.h: config.mk src/stardis-green-types.h.in + sed -e 's/@STARDIS_GREEN_TYPES_VERSION@/$(GREEN_TYPES_VERSION)/' \ + $@.in > $@ + +src/stardis-prog-properties.h: config.mk src/stardis-prog-properties.h.in + sed -e 's/@STARDIS_PROG_PROPERTIES_VERSION@/$(PROG_PROPERTIES_VERSION)/' \ + $@.in > $@ + +.SUFFIXES: .c .d .o +.c.d: + @$(CC) $(CFLAGS) $(DPDC_CFLAGS) $($(DISTRIB_PARALLELISM)_DEF) -MM -MT \ + "$(@:.d=.o) $@" $< -MF $@ + +.c.o: + $(CC) $(CFLAGS) $(DPDC_CFLAGS) $($(DISTRIB_PARALLELISM)_DEF) -c $< -o $@ + +################################################################################ +# Installation +################################################################################ +install: build_executable src/stardis-green-types.h src/stardis-prog-properties.h + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/bin" stardis + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/stardis" \ + src/stardis-green-types.h src/stardis-prog-properties.h + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/stardis" \ + COPYING README.md + +uninstall: + rm -f "$(DESTDIR)$(PREFIX)/bin/stardis" + rm -f "$(DESTDIR)$(PREFIX)/include/stardis/stardis-green-types.h" + rm -f "$(DESTDIR)$(PREFIX)/include/stardis/stardis-prog-properties.h" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/stardis/COPYING" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/stardis/README.md" + +################################################################################ +# Miscellaneous targets +################################################################################ +all: build_executable + +clean: + rm -f $(HDR) $(OBJ) .config stardis + +distclean: clean + rm -f $(DEP) + +lint: + shellcheck -o all make.sh diff --git a/config.mk b/config.mk @@ -0,0 +1,154 @@ +VERSION_MAJOR = 0 +VERSION_MINOR = 10 +VERSION_PATCH = 0 +VERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH) +PREFIX = /usr/local + +GREEN_TYPES_VERSION = 4 +PROG_PROPERTIES_VERSION = 1 + +LIB_TYPE = SHARED +#LIB_TYPE = STATIC + +BUILD_TYPE = RELEASE +#BUILD_TYPE = DEBUG + +# Defines whether distributed parallelism is supported. Any value other +# than MPI disables its supports. So, simply comment the macro to +# deactivate it. +DISTRIB_PARALLELISM = MPI + +# MPI pkg-config file +MPI_PC = ompi + +################################################################################ +# Configuration values +################################################################################ +STARDIS_ARGS_DEFAULT_TRAD = 300 +STARDIS_ARGS_DEFAULT_TRAD_REFERENCE = 300 +STARDIS_ARGS_DEFAULT_COMPUTE_TIME = INF +STARDIS_ARGS_DEFAULT_PICARD_ORDER = 1 +STARDIS_ARGS_DEFAULT_RENDERING_FOV = 70# Degrees +STARDIS_ARGS_DEFAULT_RENDERING_IMG_HEIGHT = 480 +STARDIS_ARGS_DEFAULT_RENDERING_IMG_WIDTH = 640 +STARDIS_ARGS_DEFAULT_RENDERING_OUTPUT_FILE_FMT = HT +#STARDIS_ARGS_DEFAULT_RENDERING_OUTPUT_FILE_FMT = VTK +STARDIS_ARGS_DEFAULT_RENDERING_POS = 1,1,1 +STARDIS_ARGS_DEFAULT_RENDERING_SPP = 4 +STARDIS_ARGS_DEFAULT_RENDERING_TGT = 0,0,0 +STARDIS_ARGS_DEFAULT_RENDERING_TIME = INF,INF +STARDIS_ARGS_DEFAULT_RENDERING_UP = 0,0,1 +STARDIS_ARGS_DEFAULT_SAMPLES_COUNT = 10000 +STARDIS_ARGS_DEFAULT_SCALE_FACTOR = 1 +STARDIS_ARGS_DEFAULT_VERBOSE_LEVEL = 1 + +################################################################################ +# Tools +################################################################################ +AR = ar +CC = cc +LD = ld +OBJCOPY = objcopy +PKG_CONFIG = pkg-config +RANLIB = ranlib + +################################################################################ +# Dependencies +################################################################################ +PCFLAGS_SHARED = +PCFLAGS_STATIC = --static +PCFLAGS = $(PCFLAGS_$(LIB_TYPE)) + +MPI_VERSION = 2 +MPI_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags $(MPI_PC)) +MPI_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs $(MPI_PC)) + +RSYS_VERSION = 0.14 +RSYS_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rsys) +RSYS_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rsys) + +S3D_VERSION = 0.10 +S3D_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags s3d) +S3D_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs s3d) + +SDIS_VERSION = 0.15 +SDIS_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags sdis) +SDIS_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs sdis) + +SENC3D_VERSION = 0.5 +SENC3D_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags senc3d) +SENC3D_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs senc3d) + +SG3D_VERSION = 0.2 +SG3D_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags sg3d) +SG3D_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs sg3d) + +SSP_VERSION = 0.14 +SSP_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags star-sp) +SSP_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs star-sp) + +SSTL_VERSION = 0.5 +SSTL_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags sstl) +SSTL_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs sstl) + +DPDC_CFLAGS =\ + $(RSYS_CFLAGS)\ + $(S3D_CFLAGS)\ + $(SDIS_CFLAGS)\ + $(SENC3D_CFLAGS)\ + $(SG3D_CFLAGS)\ + $(SSP_CFLAGS)\ + $(SSTL_CFLAGS)\ + $($(DISTRIB_PARALLELISM)_CFLAGS) +DPDC_LIBS =\ + $(RSYS_LIBS)\ + $(S3D_LIBS)\ + $(SDIS_LIBS)\ + $(SENC3D_LIBS)\ + $(SG3D_LIBS)\ + $(SSP_LIBS)\ + $(SSTL_LIBS)\ + $($(DISTRIB_PARALLELISM)_LIBS)\ + -lm + +################################################################################ +# Compilation options +################################################################################ +WFLAGS =\ + -Wall\ + -Wcast-align\ + -Wconversion\ + -Wextra\ + -Wmissing-declarations\ + -Wmissing-prototypes\ + -Wshadow + +CFLAGS_HARDENED =\ + -D_FORTIFY_SOURCES=2\ + -fcf-protection=full\ + -fstack-clash-protection\ + -fstack-protector-strong + +CFLAGS_COMMON =\ + -std=c89\ + -pedantic\ + -fvisibility=hidden\ + -fstrict-aliasing\ + $(CFLAGS_HARDENED)\ + $(WFLAGS) + +CFLAGS_RELEASE = -O3 -DNDEBUG $(CFLAGS_COMMON) +CFLAGS_DEBUG = -g $(CFLAGS_COMMON) +CFLAGS = $(CFLAGS_$(BUILD_TYPE)) -fPIE + +################################################################################ +# Linker options +################################################################################ +LDFLAGS_HARDENED = -Wl,-z,relro,-z,now +LDFLAGS_DEBUG = $(LDFLAGS_HARDENED) +LDFLAGS_RELEASE = -s $(LDFLAGS_HARDENED) +LDFLAGS = $(LDFLAGS_$(BUILD_TYPE)) -pie + +OCPFLAGS_DEBUG = --localize-hidden +OCPFLAGS_RELEASE = --localize-hidden --strip-unneeded +OCPFLAGS = $(OCPFLAGS_$(BUILD_TYPE)) diff --git a/make.sh b/make.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +# Copyright (C) 2018-2023 |Méso|Star> (contact@meso-star.com) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +set -e + +install() +{ + prefix=$1 + shift 1 + + mkdir -p "${prefix}" + + for i in "$@"; do + dst="${prefix}/${i##*/}" + + if cmp -s "${i}" "${dst}"; then + printf "Up to date %s\n" "${dst}" + else + printf "Installing %s\n" "${dst}" + cp "${i}" "${prefix}" + fi + done +} + +"$@" diff --git a/src/stardis-version.h.in b/src/stardis-version.h.in @@ -16,9 +16,9 @@ #ifndef STARDIS_APP_VERSION_H #define STARDIS_APP_VERSION_H -#define STARDIS_APP_VERSION_MAJOR @SDIS_VERSION_MAJOR@ -#define STARDIS_APP_VERSION_MINOR @SDIS_VERSION_MINOR@ -#define STARDIS_APP_VERSION_PATCH @SDIS_VERSION_PATCH@ +#define STARDIS_APP_VERSION_MAJOR @STARDIS_APP_VERSION_MAJOR@ +#define STARDIS_APP_VERSION_MINOR @STARDIS_APP_VERSION_MINOR@ +#define STARDIS_APP_VERSION_PATCH @STARDIS_APP_VERSION_PATCH@ #endif /* STARDIS_APP_VERSION_H */