commit 5aba96caf56e4880059dbfb5c8f2502f7fb1e092
parent 3d5a4880bb97478eb151366bf9434c695eeb929c
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 22 May 2026 16:45:37 +0200
Several updates to the Makefile
Delete the make.sh script. It implemented an install function which, while
contributing to the clarity of the Makefile, 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 libraries, header and man pages 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 tests have been written into their own
macro to make the command lines more compact.
Dependency checking is now performed with as few 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:
| M | Makefile | | | 100 | +++++++++++++++++++++++++++++++++++++++---------------------------------------- |
| M | config.mk | | | 48 | +++++++++--------------------------------------- |
| D | make.sh | | | 46 | ---------------------------------------------- |
3 files changed, 58 insertions(+), 136 deletions(-)
diff --git a/Makefile b/Makefile
@@ -29,6 +29,9 @@ LIBNAME_STATIC = librngrd.a
LIBNAME_SHARED = librngrd.so
LIBNAME = $(LIBNAME_$(LIB_TYPE))
+default: library
+all: library tests
+
################################################################################
# Library building
################################################################################
@@ -36,7 +39,10 @@ SRC = src/rngrd.c src/rngrd_log.c src/rngrd_mesh.c src/rngrd_properties.c
OBJ = $(SRC:.c=.o)
DEP = $(SRC:.c=.d)
-build_library: .config $(DEP)
+CFLAGS_LIB = $(CFLAGS_SO) $(INCS) -DRNGRD_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)"; \
@@ -47,7 +53,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): librngrd.o
$(AR) -rc $@ $?
@@ -58,28 +64,21 @@ librngrd.o: $(OBJ)
$(OBJCOPY) $(OCPFLAGS) $@
.config: config.mk
- @if ! $(PKG_CONFIG) --atleast-version $(MRUMTL_VERSION) mrumtl; then \
- echo "mrumtl $(MRUMTL_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 $(S3D_VERSION) s3d; then \
- echo "s3d $(S3D_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 $(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
- @echo "config done" > $@
+ $(PKG_CONFIG) --atleast-version $(MRUMTL_VERSION) mrumtl
+ $(PKG_CONFIG) --atleast-version $(RNSL_VERSION) rnsl
+ $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys
+ $(PKG_CONFIG) --atleast-version $(S3D_VERSION) s3d
+ $(PKG_CONFIG) --atleast-version $(SBUF_VERSION) sbuf
+ $(PKG_CONFIG) --atleast-version $(SMSH_VERSION) smsh
+ $(PKG_CONFIG) --atleast-version $(SSF_VERSION) ssf
+ 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) -DRNGRD_SHARED_BUILD -c $< -o $@
+ $(CC) $(CFLAGS_LIB) -c $< -o $@
################################################################################
# Installation
@@ -110,36 +109,36 @@ rngrd-local.pc: rngrd.pc.in
-e 's#@SSF_VERSION@#$(SSF_VERSION)#g'\
rngrd.pc.in > $@
-install: build_library pkg
- @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" $(LIBNAME)
- @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" rngrd.pc
- @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/rad-net" src/rngrd.h
- @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/rngrd" COPYING README.md
- @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/man/man5" rnsp.5
+install: library pkg
+ install() { mode="$$1"; prefix="$$2"; shift 2; \
+ mkdir -p "$${prefix}"; \
+ cp "$$@" "$${prefix}"; \
+ printf '%s\n' "$${@}" | while read -r i; do \
+ chmod "$${mode}" "$${prefix}/$${i##*/}"; \
+ done; \
+ }; \
+ if [ "$(LIB_TYPE)" = "STATIC" ]; then mode=644; else mode=755; fi; \
+ install "$${mode}" "$(DESTDIR)$(LIBPREFIX)" $(LIBNAME); \
+ install 644 "$(DESTDIR)$(LIBPREFIX)/pkgconfig" rngrd.pc; \
+ install 644 "$(DESTDIR)$(INCPREFIX)/rad-net" src/rngrd.h; \
+ install 644 "$(DESTDIR)$(MANPREFIX)/man5" rnsp.5; \
+ install 644 "$(DESTDIR)$(PREFIX)/share/doc/rngrd" COPYING README.md
uninstall:
- rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)"
- rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/rngrd.pc"
+ rm -f "$(DESTDIR)$(LIBPREFIX)/$(LIBNAME)"
+ rm -f "$(DESTDIR)$(LIBPREFIX)/pkgconfig/rngrd.pc"
+ rm -f "$(DESTDIR)$(INCPREFIX)/rad-net/rngrd.h"
+ rm -f "$(DESTDIR)$(MANPREFIX)/man5/rnsp.5"
rm -f "$(DESTDIR)$(PREFIX)/share/doc/rngrd/COPYING"
rm -f "$(DESTDIR)$(PREFIX)/share/doc/rngrd/README.md"
- rm -f "$(DESTDIR)$(PREFIX)/include/rad-net/rngrd.h"
- rm -f "$(DESTDIR)$(PREFIX)/share/man/man5/rnsp.5"
-
-################################################################################
-# Miscellaneous targets
-################################################################################
-all: build_library build_tests
-clean: clean_test
- rm -f $(OBJ) $(LIBNAME)
+clean:
+ rm -f $(OBJ) $(DEP) $(LIBNAME)
+ rm -f test_rngrd src/test_rngrd.o src/test_rngrd.d
rm -f .config librngrd.o rngrd.pc rngrd-local.pc
-distclean: clean
- rm -f $(DEP) src/test_rngrd.d
-
lint:
- shellcheck -o all make.sh
- mandoc -Tlint -Wall rnsp.5 || [ $$? -le 1 ]
+ mandoc -Tlint -Wwarning rnsp.5
################################################################################
# Tests
@@ -149,21 +148,20 @@ TEST_OBJ = $(TEST_SRC:.c=.o)
TEST_DEP = $(TEST_SRC:.c=.d)
PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG)
-RNGRD_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rngrd-local.pc)
-RNGRD_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rngrd-local.pc)
+INCS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rngrd-local rsys)
+LIBS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rngrd-local rsys)
-build_tests: build_library src/test_rngrd.d
- @$(MAKE) -fMakefile -f src/test_rngrd.d test_rngrd
+CFLAGS_TEST = $(CFLAGS_EXE) $(INCS_TEST)
+LDFLAGS_TEST = $(LDFLAGS_EXE) $(LIBS_TEST)
-clean_test:
- rm -f test_rngrd src/test_rngrd.o
+tests: library src/test_rngrd.d
+ @$(MAKE) -fMakefile -f src/test_rngrd.d test_rngrd
$(TEST_DEP): config.mk rngrd-local.pc
- @$(CC) $(CFLAGS_EXE) $(RNGRD_CFLAGS) $(RSYS_CFLAGS) \
- -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
+ @$(CC) $(CFLAGS_TEST) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
src/test_rngrd.o: config.mk rngrd-local.pc
- $(CC) $(CFLAGS_EXE) $(RNGRD_CFLAGS) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@
+ $(CC) $(CFLAGS_TEST) -c $(@:.o=.c) -o $@
test_rngrd: src/test_rngrd.o config.mk rngrd-local.pc $(LIBNAME)
- $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(RNGRD_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.2.0
+
PREFIX = /usr/local
+LIBPREFIX = $(PREFIX)/lib
+INCPREFIX = $(PREFIX)/include
+MANPREFIX = $(PREFIX)/share/man
LIB_TYPE = SHARED
#LIB_TYPE = STATIC
@@ -25,51 +29,17 @@ PCFLAGS_STATIC = --static
PCFLAGS = $(PCFLAGS_$(LIB_TYPE))
MRUMTL_VERSION = 0.2
-MRUMTL_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags mrumtl)
-MRUMTL_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs mrumtl)
-
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)
-
S3D_VERSION = 0.10
-S3D_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags s3d)
-S3D_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs s3d)
-
SBUF_VERSION = 0.1
-SBUF_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags sbuf)
-SBUF_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs sbuf)
-
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)
-
-DPDC_CFLAGS =\
- $(MRUMTL_CFLAGS)\
- $(RNSL_CFLAGS)\
- $(RSYS_CFLAGS)\
- $(S3D_CFLAGS)\
- $(SBUF_CFLAGS)\
- $(SMSH_CFLAGS)\
- $(SSF_CFLAGS)
-
-DPDC_LIBS =\
- $(MRUMTL_LIBS)\
- $(RNSL_LIBS)\
- $(RSYS_LIBS)\
- $(S3D_LIBS)\
- $(SBUF_LIBS)\
- $(SMSH_LIBS)\
- $(SSF_LIBS)\
- -lm
+
+PC = mrumtl rnsl rsys s3d sbuf smsh ssf
+
+INCS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags $(PC))
+LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs $(PC)) -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
-}
-
-"$@"