stardis

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

commit bbaf49af8216c1882636d90ddb51b091a4c26bd5
parent 1d20a099d57794477e1ed78034891bd91fb467ce
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri, 14 Nov 2025 11:05:47 +0100

Rewriting the Makefile

Delete the make.sh script. It implemented the "install" function which,
made the build system less compact. This function can be implemented
with just a few lines of shell code, without any major impact on the
clarity of the Makefile.  Perhaps on the contrary, since it's all in one
place.

Add the LIBPREFIX, INCPREFIX and MANPREFIX macros to control the
subdirectories into which binaries, libraries, header files and
documentation are copied. Systems may use locations other than those
proposed by default.

Remove the "distclean" Makefile target. In fact, it does the wrong
thing. distclean, in addition to a normal cleanup target, should also
delete files created by a dist target, i.e.  a target generating files
for distribution, such as a compressed archive. But it was used to
delete automatically generated dependency files. These files can simply
be removed by normal cleanup. What's more, as the project is designed to
be installed by compiling its sources directly, no distribution target
is implemented, so no distclean is required.

Dependencies are grouped in the INCS and LIBS macros using a single call
to the pkg-config program.

Dependency checking is now performed with only one call to pkg-config,
without any additional code, because displaying a hand-written error
message adds no value to the clarity of what is being done and what
happens in case of missing dependencies.

Diffstat:
MMakefile | 78++++++++++++++++++++++++++++++++++++++----------------------------------------
Mconfig.mk | 53++++++++++-------------------------------------------
2 files changed, 48 insertions(+), 83 deletions(-)

diff --git a/Makefile b/Makefile @@ -68,31 +68,24 @@ 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 + @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f "$${i}"; done) stardis -$(DEP) $(OBJ): config.mk +stardis $(DEP) $(OBJ): config.mk stardis: $(OBJ) - $(CC) $(CFLAGS) $(DPDC_CFLAGS) -o $@ $(OBJ) $(LDFLAGS) $(DPDC_LIBS) + $(CC) $(CFLAGS) $(INCS) -o $@ $(OBJ) $(LDFLAGS) $(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 + if [ "$(DISTRIB_PARALLELISM)" = "MPI" ]; then \ + $(PKG_CONFIG) --atleast-version $(MPI_VERSION) $(MPI_PC); \ + fi + $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys + $(PKG_CONFIG) --atleast-version $(S3D_VERSION) s3d + $(PKG_CONFIG) --atleast-version $(SDIS_VERSION) sdis + $(PKG_CONFIG) --atleast-version $(SENC3D_VERSION) senc3d + $(PKG_CONFIG) --atleast-version $(SG3D_VERSION) sg3d + $(PKG_CONFIG) --atleast-version $(SSP_VERSION) star-sp + $(PKG_CONFIG) --atleast-version $(SSTL_VERSION) sstl @echo "config done" > $@ src/stardis-default.h: config.mk src/stardis-default.h.in @@ -135,11 +128,11 @@ src/stardis-prog-properties.h: config.mk src/stardis-prog-properties.h.in .SUFFIXES: .c .d .o .c.d: - @$(CC) $(CFLAGS) $(DPDC_CFLAGS) $($(DISTRIB_PARALLELISM)_DEF) -MM -MT \ + @$(CC) $(CFLAGS) $(INCS) $($(DISTRIB_PARALLELISM)_DEF) -MM -MT \ "$(@:.d=.o) $@" $< -MF $@ .c.o: - $(CC) $(CFLAGS) $(DPDC_CFLAGS) $($(DISTRIB_PARALLELISM)_DEF) -c $< -o $@ + $(CC) $(CFLAGS) $(INCS) $($(DISTRIB_PARALLELISM)_DEF) -c $< -o $@ ################################################################################ # Man pages @@ -176,35 +169,40 @@ pkg: stardis.pc.in > stardis.pc install: all pkg - @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/bin" stardis - @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/stardis" src/stardis-green-types.h - @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/stardis" src/stardis-prog-properties.h - @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" stardis.pc - @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/stardis" COPYING README.md - @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/man/man1" doc/stardis.1 - @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/man/man5" doc/stardis-input.5 - @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/man/man5" doc/stardis-output.5 + install() { mode="$$1"; prefix="$$2"; shift 2; \ + mkdir -p "$${prefix}"; \ + cp "$$@" "$${prefix}"; \ + for i in "$$@"; do \ + chmod "$${mode}" "$${prefix}/$$(basename "$${i}")";\ + done; \ + }; \ + install 755 "$(DESTDIR)$(BINPREFIX)" stardis; \ + install 644 "$(DESTDIR)$(INCPREFIX)/stardis" src/stardis-green-types.h; \ + install 644 "$(DESTDIR)$(INCPREFIX)/stardis" src/stardis-prog-properties.h; \ + install 644 "$(DESTDIR)$(LIBPREFIX)/pkgconfig" stardis.pc; \ + install 644 "$(DESTDIR)$(PREFIX)/share/doc/stardis" COPYING README.md; \ + install 644 "$(DESTDIR)$(MANPREFIX)/man1" doc/stardis.1; \ + install 644 "$(DESTDIR)$(MANPREFIX)/man5" doc/stardis-input.5; \ + install 644 "$(DESTDIR)$(MANPREFIX)/man5" doc/stardis-output.5 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)/lib/pkgconfig/stardis.pc" + rm -f "$(DESTDIR)$(BINPREFIX)/stardis" + rm -f "$(DESTDIR)$(INCPREFIX)/stardis/stardis-green-types.h" + rm -f "$(DESTDIR)$(INCPREFIX)/stardis/stardis-prog-properties.h" + rm -f "$(DESTDIR)$(LIBPREFIX)/pkgconfig/stardis.pc" rm -f "$(DESTDIR)$(PREFIX)/share/doc/stardis/COPYING" rm -f "$(DESTDIR)$(PREFIX)/share/doc/stardis/README.md" - rm -f "$(DESTDIR)$(PREFIX)/share/man/man1/stardis.1" - rm -f "$(DESTDIR)$(PREFIX)/share/man/man5/stardis-input.5" - rm -f "$(DESTDIR)$(PREFIX)/share/man/man5/stardis-output.5" + rm -f "$(DESTDIR)$(MANPREFIX)/man1/stardis.1" + rm -f "$(DESTDIR)$(MANPREFIX)/man5/stardis-input.5" + rm -f "$(DESTDIR)$(MANPREFIX)/man5/stardis-output.5" ################################################################################ # Miscellaneous targets ################################################################################ clean: rm -f $(HDR) $(OBJ) .config stardis stardis.pc - rm -f doc/stardis.1 doc/stardis-input.5 - -distclean: clean rm -f $(DEP) + rm -f doc/stardis.1 doc/stardis-input.5 lint: man shellcheck -o all make.sh diff --git a/config.mk b/config.mk @@ -13,6 +13,11 @@ LIB_TYPE = SHARED BUILD_TYPE = RELEASE #BUILD_TYPE = DEBUG +BINPREFIX = $(PREFIX)/bin +LIBPREFIX = $(PREFIX)/lib +INCPREFIX = $(PREFIX)/include +MANPREFIX = $(PREFIX)/share/man + # Defines whether distributed parallelism is supported. Any value other # than MPI disables its supports. So, simply comment the macro to # deactivate it. @@ -63,56 +68,18 @@ 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.16 -SDIS_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags sdis) -SDIS_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs sdis) - SENC3D_VERSION = 0.7.2 -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 + +INCS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags\ + rsys s3d sdis senc3d sg3d star-sp sstl $($(DISTRIB_PARALLELISM)_PC)) +LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs\ + rsys s3d sdis senc3d sg3d star-sp sstl $($(DISTRIB_PARALLELISM)_PC)) -lm ################################################################################ # Compilation options