commit b9f57ec3f68b4c635abca6a04f474bb7576bb44e
parent 3f6326900f9e3f52f6c6ff2033116b57cda89484
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 13 May 2026 17:24:10 +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.
In addition to the features already offered by its CMake counterpart,
this Makefile allows the programmer to specify static libraries as the
preferred type of libraries during the linking process. It also provides
an uninstallation target. In any case, the main reason for writing it is
to use a classic, well-established standard with simple features
available on all UNIX systems, which simplifies portability and support
while being much lighter.
Note that currently, test execution is still not automated in POSIX
make, unlike its CMake alternative.
Diffstat:
| M | .gitignore | | | 15 | +++++++-------- |
| A | Makefile | | | 106 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | config.mk | | | 91 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
3 files changed, 204 insertions(+), 8 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,11 +1,10 @@
-.gitignore
-CMakeCache.txt
-CMakeFiles
-Makefile
-tmp
-[Bb]uild*
+*.[aod]
*.sw[po]
-*.[ao]
*~
+.config
+.gitignore
+doc/schiff.1
+src/schiff_args.h
+src/schiff_version.h
tags
-
+schiff
diff --git a/Makefile b/Makefile
@@ -0,0 +1,106 @@
+# Copyright (C) 2020, 2021 |Meso|Star> (contact@meso-star.com)
+# Copyright (C) 2015, 2016 CNRS
+#
+# 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
+
+default: program
+all: default
+
+################################################################################
+# Star-3D building
+################################################################################
+SRC =\
+ src/schiff.c\
+ src/schiff_args.c\
+ src/schiff_geometry.c\
+ src/schiff_mesh.c\
+ src/schiff_optical_properties.c
+OBJ = $(SRC:.c=.o)
+DEP = $(SRC:.c=.d)
+
+CFLAGS_PROG = $(CFLAGS) $(INCS)
+LDFLAGS_PROG = $(LDFLAGS) $(LIBS)
+
+program: .config $(DEP)
+ @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f "$${i}"; done) schiff
+
+$(DEP): src/schiff_args.h src/schiff_version.h
+$(DEP) $(OBJ): config.mk
+
+schiff: $(OBJ)
+ $(CC) $(CFLAGS_PROG) -o $@ $(OBJ) $(LDFLAGS_PROG)
+
+.config: config.mk
+ $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys
+ $(PKG_CONFIG) --atleast-version $(S3D_VERSION) s3d
+ $(PKG_CONFIG) --atleast-version $(SSCHIFF_VERSION) sschiff
+ $(PKG_CONFIG) --atleast-version $(SSP_VERSION) star-sp
+ $(PKG_CONFIG) --atleast-version $(YAML_VERSION) yaml-0.1
+ echo "config done" > $@
+
+src/schiff_args.h: src/schiff_args.h.in
+src/schiff_version.h: src/schiff_version.h.in
+doc/schiff.1: doc/schiff.1.in
+
+src/schiff_version.h src/schiff_args.h doc/schiff.1: config.mk
+ @sed -e 's#@SCHIFF_ARGS_DEFAULT_NINSAMPLES@#$(SCHIFF_ARGS_DEFAULT_NINSAMPLES)#g' \
+ -e 's#@SCHIFF_ARGS_DEFAULT_NREALISATIONS@#$(SCHIFF_ARGS_DEFAULT_NREALISATIONS)#g' \
+ -e 's#@SCHIFF_ARGS_DEFAULT_NANGLES@#$(SCHIFF_ARGS_DEFAULT_NANGLES)#g' \
+ -e 's#@SCHIFF_ARGS_DEFAULT_NANGLES_INV@#$(SCHIFF_ARGS_DEFAULT_NANGLES_INV)#g' \
+ -e 's#@VERSION_MAJOR@#$(VERSION_MAJOR)#g' \
+ -e 's#@VERSION_MINOR@#$(VERSION_MINOR)#g' \
+ -e 's#@VERSION_PATCH@#$(VERSION_PATCH)#g' \
+ $@.in > $@
+
+.SUFFIXES: .c .d .o
+.c.d:
+ $(CC) $(CFLAGS_PROG) -MM -MT "$(@:.d=.o) $@" $< -MF $@
+
+.c.o:
+ $(CC) $(CFLAGS_PROG) -c $< -o $@
+
+################################################################################
+# Installation
+################################################################################
+install: program doc/schiff.1
+ 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; \
+ }; \
+ install 755 "$(DESTDIR)$(BINPREFIX)" schiff; \
+ install 644 "$(DESTDIR)$(MANPREFIX)/man1" doc/schiff.1; \
+ install 644 "$(DESTDIR)$(MANPREFIX)/man5" doc/schiff-geometry.5; \
+ install 644 "$(DESTDIR)$(MANPREFIX)/man5" doc/schiff-output.5; \
+ install 644 "$(DESTDIR)$(PREFIX)/share/doc/schiff" COPYING README.md
+
+uninstall:
+ rm -f "$(DESTDIR)$(BINPREFIX)/schiff"
+ rm -f "$(DESTDIR)$(MANPREFIX)/man1/schiff.1"
+ rm -f "$(DESTDIR)$(MANPREFIX)/man5/schiff-geometry.5"
+ rm -f "$(DESTDIR)$(MANPREFIX)/man5/schiff-output.5"
+ rm -f "$(DESTDIR)$(PREFIX)/share/doc/schiff/COPYING"
+ rm -f "$(DESTDIR)$(PREFIX)/share/doc/schiff/README.md"
+
+clean:
+ rm -f $(OBJ) $(DEP) $(LIBNAME)
+ rm -f src/schiff_version.h src/schiff_args.h doc/schiff.1
+ rm -f .config schiff
diff --git a/config.mk b/config.mk
@@ -0,0 +1,91 @@
+VERSION_MAJOR = 0
+VERSION_MINOR = 5
+VERSION_PATCH = 0
+VERSION = $(VERSION).$(MINOR).$(PATCH)
+
+PREFIX = /usr/local
+BINPREFIX = $(PREFIX)/bin
+MANPREFIX = $(PREFIX)/share/man
+
+LIB_TYPE = SHARED
+#LIB_TYPE = STATIC
+
+BUILD_TYPE = RELEASE
+#BUILD_TYPE = DEBUG
+
+################################################################################
+# Default argument values
+################################################################################
+SCHIFF_ARGS_DEFAULT_NINSAMPLES = 100
+SCHIFF_ARGS_DEFAULT_NREALISATIONS = 10000
+SCHIFF_ARGS_DEFAULT_NANGLES = 1000
+SCHIFF_ARGS_DEFAULT_NANGLES_INV = 2000
+
+################################################################################
+# 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))
+
+RSYS_VERSION = 0.8
+S3D_VERSION = 0.8
+SSP_VERSION = 0.12
+SSCHIFF_VERSION = 0.5
+YAML_VERSION = 0.1
+
+INCS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rsys s3d star-sp sschiff yaml-0.1)
+LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rsys s3d star-sp sschiff yaml-0.1) -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 = -O2 -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))