commit 8065eb81f4078ffd2cbbeadb6322d3bc3523044c
parent 355830a979e443a427fa75bf721f32d12802bf9b
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 15 Sep 2023 15:18:04 +0200
Write a POSIX Makefile to replace CMake
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 already provided in its CMake alternative,
this Makefile supports the construction of static libraries and provides
an uninstall target. 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.
Diffstat:
| M | .gitignore | | | 14 | +++++++------- |
| A | Makefile | | | 164 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | config.mk | | | 103 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | make.sh | | | 44 | ++++++++++++++++++++++++++++++++++++++++++++ |
| A | rngrd.pc.in | | | 12 | ++++++++++++ |
5 files changed, 330 insertions(+), 7 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,12 +1,12 @@
.gitignore
-CMakeCache.txt
-CMakeFiles
-Makefile
-tmp
[Bb]uild*
*.sw[po]
-*.[ao]
-*.orig
+*.[aod]
+*.so
*~
+test*
+!test*.[ch]
+.config
+.test
tags
-
+*.pc
diff --git a/Makefile b/Makefile
@@ -0,0 +1,164 @@
+# 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/>.
+
+.POSIX:
+.SUFFIXES: # Clean up default inference rules
+
+include config.mk
+
+LIBNAME_STATIC = librngrd.a
+LIBNAME_SHARED = librngrd.so
+LIBNAME = $(LIBNAME_$(LIB_TYPE))
+
+################################################################################
+# Library building
+################################################################################
+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)
+ @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) \
+ $$(if [ -n "$(LIBNAME)" ]; then \
+ echo "$(LIBNAME)"; \
+ else \
+ echo "$(LIBNAME_SHARED)"; \
+ fi)
+
+$(DEP) $(OBJ): config.mk
+
+$(LIBNAME_SHARED): $(OBJ)
+ $(CC) $(CFLAGS) $(DPDC_CFLAGS) -o $@ $(OBJ) $(LDFLAGS) $(SOFLAGS) $(DPDC_LIBS)
+
+$(LIBNAME_STATIC): $(OBJ)
+ $(AR) -rc $@ $?
+ $(RANLIB) $@
+
+.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" > $@
+
+.SUFFIXES: .c .d .o
+.c.d:
+ @$(CC) $(CFLAGS) $(DPDC_CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@
+
+.c.o:
+ $(CC) $(CFLAGS) $(DPDC_CFLAGS) -DRNGRD_SHARED_BUILD -c $< -o $@
+
+################################################################################
+# Installation
+################################################################################
+pkg:
+ sed -e 's#@PREFIX@#$(PREFIX)#g'\
+ -e 's#@VERSION@#$(VERSION)#g'\
+ -e 's#@MRUMTL_VERSION@#$(MRUMTL_VERSION)#g'\
+ -e 's#@RNSL_VERSION@#$(RNSL_VERSION)#g'\
+ -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
+ -e 's#@S3D_VERSION@#$(S3D_VERSION)#g'\
+ -e 's#@SBUF_VERSION@#$(SBUF_VERSION)#g'\
+ -e 's#@SMSH_VERSION@#$(SMSH_VERSION)#g'\
+ -e 's#@SSF_VERSION@#$(SSF_VERSION)#g'\
+ rngrd.pc.in > rngrd.pc
+
+rngrd-local.pc: rngrd.pc.in
+ sed -e '1d'\
+ -e 's#^includedir=.*#includedir=./src/#'\
+ -e 's#^libdir=.*#libdir=./#'\
+ -e 's#@VERSION@#$(VERSION)#g'\
+ -e 's#@MRUMTL_VERSION@#$(MRUMTL_VERSION)#g'\
+ -e 's#@RNSL_VERSION@#$(RNSL_VERSION)#g'\
+ -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
+ -e 's#@S3D_VERSION@#$(S3D_VERSION)#g'\
+ -e 's#@SBUF_VERSION@#$(SBUF_VERSION)#g'\
+ -e 's#@SMSH_VERSION@#$(SMSH_VERSION)#g'\
+ -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
+
+uninstall:
+ rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)"
+ rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/rngrd.pc"
+ 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) .config 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 ]
+
+################################################################################
+# Tests
+################################################################################
+TEST_SRC = src/test_rngrd.c
+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)
+
+build_tests: build_library src/test_rngrd.d
+ @$(MAKE) -fMakefile -f src/test_rngrd.d test_rngrd
+
+clean_test:
+ rm -f test_rngrd src/test_rngrd.o
+
+$(TEST_DEP): config.mk rngrd-local.pc
+ @$(CC) $(CFLAGS) $(RSYS_CFLAGS) $(RNGRD_CFLAGS) \
+ -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
+
+src/test_rngrd.o: config.mk rngrd-local.pc
+ $(CC) $(CFLAGS) $(RSYS_CFLAGS) $(RNGRD_CFLAGS) -c $(@:.o=.c) -o $@
+
+test_rngrd: src/test_rngrd.o config.mk rngrd-local.pc
+ $(CC) -o $@ src/$@.o $(RSYS_LIBS) $(RNGRD_LIBS)
diff --git a/config.mk b/config.mk
@@ -0,0 +1,103 @@
+VERSION = 0.0.0
+PREFIX = /usr/local
+
+LIB_TYPE = SHARED
+#LIB_TYPE = STATIC
+
+BUILD_TYPE = RELEASE
+#BUILD_TYPE = DEBUG
+
+################################################################################
+# Tools
+################################################################################
+AR = ar
+CC = cc
+PKG_CONFIG = pkg-config
+RANLIB = ranlib
+
+################################################################################
+# Dependencies
+################################################################################
+PCFLAGS_SHARED =
+PCFLAGS_STATIC = --static
+PCFLAGS = $(PCFLAGS_$(LIB_TYPE))
+
+MRUMTL_VERSION = 0.1
+MRUMTL_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags mrumtl)
+MRUMTL_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs mrumtl)
+
+RNSL_VERSION = 0.0
+RNSL_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rnsl)
+RNSL_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rnsl)
+
+RSYS_VERSION = 0.13
+RSYS_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rsys)
+RSYS_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rsys)
+
+S3D_VERSION = 0.8
+S3D_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags s3d)
+S3D_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs s3d)
+
+SBUF_VERSION = 0.0
+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.8
+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
+
+################################################################################
+# Compilation options
+################################################################################
+WFLAGS =\
+ -Wall\
+ -Wcast-align\
+ -Wconversion\
+ -Wextra\
+ -Wmissing-declarations\
+ -Wmissing-prototypes\
+ -Wshadow
+
+CFLAGS_COMMON =\
+ -std=c89\
+ -pedantic\
+ -fPIC\
+ -fvisibility=hidden\
+ -fstrict-aliasing\
+ $(WFLAGS)
+
+CFLAGS_RELEASE = -O2 -DNDEBUG $(CFLAGS_COMMON)
+CFLAGS_DEBUG = -g $(CFLAGS_COMMON)
+CFLAGS = $(CFLAGS_$(BUILD_TYPE))
+
+################################################################################
+# Linker options
+################################################################################
+SOFLAGS = -shared -Wl,--no-undefined
+
+LDFLAGS_DEBUG =
+LDFLAGS_RELEASE = -s
+LDFLAGS = $(LDFLAGS_$(BUILD_TYPE))
diff --git a/make.sh b/make.sh
@@ -0,0 +1,44 @@
+#!/bin/sh -e
+
+# 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/>.
+
+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/rngrd.pc.in b/rngrd.pc.in
@@ -0,0 +1,12 @@
+prefix=@PREFIX@
+includedir=${prefix}/include
+libdir=${prefix}/lib
+
+Requires: rsys >= @RSYS_VERSION@, s3d >= @S3D_VERSION@
+Requires.private: mrumtl >= @MRUMTL_VERSION@, rnsl >= @RNSL_VERSION@, sbuf >= @SBUF_VERSION@, smsh >= @SMSH_VERSION@, ssf >= @SSF_VERSION@
+Name: rngrd
+Description: Rad-Net GRounD
+Version: @VERSION@
+Libs: -L${libdir} -lrngrd
+Libs.private: -lm
+CFlags: -I${includedir}