rnatm

Load and structure data describing an atmosphere
git clone git://git.meso-star.fr/rnatm.git
Log | Files | Refs | README | LICENSE

commit 018caeab084f4d5b8622cd6bfa106a28d3eb3940
parent adc282578b503f76e9451672f199018a4980af34
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed,  1 Oct 2025 09:39:08 +0200

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. In the Makefile, the CFLAGS and LDFLAGS
variables for the library and test have been written into their own
macro to make the command lines more compact.

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 | 104+++++++++++++++++++++++++++++++++++++++----------------------------------------
Mconfig.mk | 63++++++++-------------------------------------------------------
Dmake.sh | 46----------------------------------------------
3 files changed, 59 insertions(+), 154 deletions(-)

diff --git a/Makefile b/Makefile @@ -29,6 +29,9 @@ LIBNAME_STATIC = librnatm.a LIBNAME_SHARED = librnatm.so LIBNAME = $(LIBNAME_$(LIB_TYPE)) +default: library +all: default tests + ################################################################################ # Library building ################################################################################ @@ -45,7 +48,10 @@ SRC =\ OBJ = $(SRC:.c=.o) DEP = $(SRC:.c=.d) -build_library: .config $(DEP) +CFLAGS_LIB = $(CFLAGS_SO) $(INCS) -DRNATM_SHARED_BUILD +LDFLAGS_LIB = $(LDFLAGS_SO) $(LIBS) + +library: .config $(DEP) @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) \ $$(if [ -n "$(LIBNAME)" ]; then \ echo "$(LIBNAME)"; \ @@ -56,7 +62,7 @@ build_library: .config $(DEP) $(DEP) $(OBJ): config.mk $(LIBNAME_SHARED): $(OBJ) - $(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -o $@ $(OBJ) $(LDFLAGS_SO) $(DPDC_LIBS) + $(CC) $(CFLAGS_LIB) -o $@ $(OBJ) $(LDFLAGS_LIB) $(LIBNAME_STATIC): librnatm.o $(AR) -rc $@ $? @@ -67,34 +73,24 @@ librnatm.o: $(OBJ) $(OBJCOPY) $(OCPFLAGS) $@ .config: config.mk - @if ! $(PKG_CONFIG) --atleast-version $(RNSF_VERSION) rnsf; then \ - echo "rnsf $(RNSF_VERSION) not found" >&2; exit 1; fi - @if ! $(PKG_CONFIG) --atleast-version $(RNSL_VERSION) rnsl; then \ - echo "rnsl $(RNSL_VERSION) not found" >&2; exit 1; 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 $(SARS_VERSION) sars; then \ - echo "sars $(SARS_VERSION) not found" >&2; exit 1; fi - @if ! $(PKG_CONFIG) --atleast-version $(SBUF_VERSION) sbuf; then \ - echo "sbuf $(SBUF_VERSION) not found" >&2; exit 1; fi - @if ! $(PKG_CONFIG) --atleast-version $(SCK_VERSION) sck; then \ - echo "sck $(SCK_VERSION) not found" >&2; exit 1; fi - @if ! $(PKG_CONFIG) --atleast-version $(SMSH_VERSION) smsh; then \ - echo "smsh $(SMSH_VERSION) not found" >&2; exit 1; fi - @if ! $(PKG_CONFIG) --atleast-version $(SSF_VERSION) ssf; then \ - echo "ssf $(SSF_VERSION) not found" >&2; exit 1; fi - @if ! $(PKG_CONFIG) --atleast-version $(SUVM_VERSION) suvm; then \ - echo "suvm $(SUVM_VERSION) not found" >&2; exit 1; fi - @if ! $(PKG_CONFIG) --atleast-version $(SVX_VERSION) svx; then \ - echo "svx $(SVX_VERSION) not found" >&2; exit 1; fi - @echo "config done" > $@ + $(PKG_CONFIG) --atleast-version $(RNSF_VERSION) rnsf + $(PKG_CONFIG) --atleast-version $(RNSL_VERSION) rnsl + $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys + $(PKG_CONFIG) --atleast-version $(SARS_VERSION) sars + $(PKG_CONFIG) --atleast-version $(SBUF_VERSION) sbuf + $(PKG_CONFIG) --atleast-version $(SCK_VERSION) sck + $(PKG_CONFIG) --atleast-version $(SMSH_VERSION) smsh + $(PKG_CONFIG) --atleast-version $(SSF_VERSION) ssf + $(PKG_CONFIG) --atleast-version $(SUVM_VERSION) suvm + $(PKG_CONFIG) --atleast-version $(SVX_VERSION) svx + echo "config done" > $@ .SUFFIXES: .c .d .o .c.d: - @$(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@ + @$(CC) $(CFLAGS_LIB) -MM -MT "$(@:.d=.o) $@" $< -MF $@ .c.o: - $(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -DRNATM_SHARED_BUILD -c $< -o $@ + $(CC) $(CFLAGS_LIB) -c $< -o $@ ################################################################################ # Installation @@ -131,36 +127,37 @@ rnatm-local.pc: rnatm.pc.in -e 's#@SVX_VERSION@#$(SVX_VERSION)#g'\ rnatm.pc.in > $@ -install: build_library pkg - @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" $(LIBNAME) - @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" rnatm.pc - @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/rad-net" src/rnatm.h - @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/rnatm" COPYING README.md - @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/man/man5" rngt.5 rnpfi.5 +install: library pkg + install() { mode="$$1"; prefix="$$2"; shift 2; \ + mkdir -p "$${prefix}"; \ + cp "$$@" "$${prefix}"; \ + chmod "$${mode}" "$${prefix}/$${@##*/}"; \ + }; \ + install 755 "$(DESTDIR)$(LIBPREFIX)" $(LIBNAME); \ + install 644 "$(DESTDIR)$(LIBPREFIX)/pkgconfig" rnatm.pc; \ + install 644 "$(DESTDIR)$(INCPREFIX)/rad-net" src/rnatm.h; \ + install 644 "$(DESTDIR)$(MANPREFIX)/man5" rngt.5; \ + install 644 "$(DESTDIR)$(MANPREFIX)/man5" rnpfi.5; \ + install 644 "$(DESTDIR)$(PREFIX)/share/doc/rnatm" COPYING; \ + install 644 "$(DESTDIR)$(PREFIX)/share/doc/rnatm" README.md uninstall: - rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)" - rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/rnatm.pc" + rm -f "$(DESTDIR)$(LIBPREFIX)/$(LIBNAME)" + rm -f "$(DESTDIR)$(LIBPREFIX)/pkgconfig/rnatm.pc" + rm -f "$(DESTDIR)$(INCPREFIX)/rad-net/rnatm.h" + rm -f "$(DESTDIR)$(MANPREFIX)/man5/rngt.5" + rm -f "$(DESTDIR)$(MANPREFIX)/man5/rnpfi.5" rm -f "$(DESTDIR)$(PREFIX)/share/doc/rnatm/COPYING" rm -f "$(DESTDIR)$(PREFIX)/share/doc/rnatm/README.md" - rm -f "$(DESTDIR)$(PREFIX)/include/rad-net/rnatm.h" - rm -f "$(DESTDIR)$(PREFIX)/share/man/man5/rngt.5" - rm -f "$(DESTDIR)$(PREFIX)/share/man/man5/rnpfi.5" ################################################################################ # Miscellaneous targets ################################################################################ -all: build_library build_tests - clean: clean_test - rm -f $(OBJ) $(LIBNAME) + rm -f $(DEP) $(OBJ) $(LIBNAME) rm -f .config librnatm.o rnatm.pc rnatm-local.pc -distclean: clean - rm -f $(DEP) src/test_rnatm.d - lint: - shellcheck -o all make.sh mandoc -Tlint -Wall rngt.5 || [ $$? -le 1 ] mandoc -Tlint -Wall rnpfi.5 || [ $$? -le 1 ] @@ -172,22 +169,23 @@ TEST_OBJ = $(TEST_SRC:.c=.o) TEST_DEP = $(TEST_SRC:.c=.d) PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG) -RNATM_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rnatm-local.pc) -RNATM_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rnatm-local.pc) +INCS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rnatm-local rsys) +LIBS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rnatm-local rsys) + +CFLAGS_TEST = $(CFLAGS_EXE) $(INCS_TEST) +LDFLAGS_TEST = $(LDFLAGS_EXE) $(LIBS_TEST) -build_tests: build_library src/test_rnatm.d +tests: library $(TEST_DEP) src/test_rnatm.d @$(MAKE) -fMakefile -f src/test_rnatm.d test_rnatm clean_test: - rm -f test_rnatm src/test_rnatm.o + rm -f test_rnatm src/test_rnatm.d src/test_rnatm.o $(TEST_DEP): config.mk rnatm-local.pc - @$(CC) $(CFLAGS_EXE) $(RNATM_CFLAGS) $(RSYS_CFLAGS) \ - -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ + @$(CC) $(CFLAGS_TEST) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ -src/test_rnatm.o: config.mk rnatm-local.pc - $(CC) $(CFLAGS_EXE) $(RNATM_CFLAGS) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@ +$(TEST_OBJ): config.mk rnatm-local.pc + $(CC) $(CFLAGS_TEST) -c $(@:.o=.c) -o $@ test_rnatm: src/test_rnatm.o config.mk rnatm-local.pc $(LIBNAME) - $(CC) $(CFLAGS_EXE) $(RNATM_CFLAGS) $(RSYS_CFLAGS) -o $@ src/$@.o \ - $(LDFLAGS_EXE) $(RNATM_LIBS) $(RSYS_LIBS) + $(CC) $(CFLAGS_TEST) -o $@ src/$@.o $(LDFLAGS_TEST) diff --git a/config.mk b/config.mk @@ -1,5 +1,9 @@ VERSION = 0.1.0 + PREFIX = /usr/local +LIBPREFIX = $(PREFIX)/lib +INCPREFIX = $(PREFIX)/include +MANPREFIX = $(PREFIX)/share/man LIB_TYPE = SHARED #LIB_TYPE = STATIC @@ -25,71 +29,20 @@ PCFLAGS_STATIC = --static PCFLAGS = $(PCFLAGS_$(LIB_TYPE)) RNSF_VERSION = 0.1 -RNSF_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rnsf) -RNSF_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rnsf) - RNSL_VERSION = 0.1 -RNSL_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rnsl) -RNSL_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rnsl) - RSYS_VERSION = 0.14 -RSYS_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rsys) -RSYS_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rsys) - SARS_VERSION = 0.1 -SARS_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags sars) -SARS_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs sars) - SBUF_VERSION = 0.1 -SBUF_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags sbuf) -SBUF_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs sbuf) - SCK_VERSION = 0.1 -SCK_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags sck) -SCK_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs sck) - SMSH_VERSION = 0.1 -SMSH_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags smsh) -SMSH_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs smsh) - SSF_VERSION = 0.9 -SSF_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags ssf) -SSF_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs ssf) - SUVM_VERSION = 0.3 -SUVM_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags suvm) -SUVM_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs suvm) - SVX_VERSION = 0.3 -SVX_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags svx) -SVX_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs svx) - -DPDC_CFLAGS =\ - $(RNSF_CFLAGS)\ - $(RNSL_CFLAGS)\ - $(RSYS_CFLAGS)\ - $(SARS_CFLAGS)\ - $(SBUF_CFLAGS)\ - $(SCK_CFLAGS)\ - $(SMSH_CFLAGS)\ - $(SSF_CFLAGS)\ - $(SUVM_CFLAGS)\ - $(SVX_CFLAGS)\ - -fopenmp -DPDC_LIBS =\ - $(RNSF_LIBS)\ - $(RNSL_LIBS)\ - $(RSYS_LIBS)\ - $(SARS_LIBS)\ - $(SBUF_LIBS)\ - $(SCK_LIBS)\ - $(SMSH_LIBS)\ - $(SSF_LIBS)\ - $(SUVM_LIBS)\ - $(SVX_LIBS)\ - -fopenmp\ - -lm +INCS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags\ + rnsf rnsl rsys sars sbuf sck smsh ssf suvm svx) -fopenmp +LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs\ + rnsf rnsl rsys sars sbuf sck smsh ssf suvm svx) -fopenmp -lm ################################################################################ # Compilation options diff --git a/make.sh b/make.sh @@ -1,46 +0,0 @@ -#!/bin/sh - -# Copyright (C) 2022, 2023 Centre National de la Recherche Scientifique -# Copyright (C) 2022, 2023 Institut Pierre-Simon Laplace -# Copyright (C) 2022, 2023 Institut de Physique du Globe de Paris -# Copyright (C) 2022, 2023 |Méso|Star> (contact@meso-star.com) -# Copyright (C) 2022, 2023 Observatoire de Paris -# Copyright (C) 2022, 2023 Université de Reims Champagne-Ardenne -# Copyright (C) 2022, 2023 Université de Versaille Saint-Quentin -# Copyright (C) 2022, 2023 Université Paul Sabatier -# -# 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 -} - -"$@"