star-meshtool

Mesh transformation
git clone git://git.meso-star.fr/star-meshtool.git
Log | Files | Refs | README | LICENSE

commit 4b8f9a09070b0fefd6a6f8f0fe172ae4cf11ab7b
parent d9e411a0230539f85ff192dd36aacd1d37034cbd
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon, 17 Nov 2025 11:58:44 +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 INCPREFIX and MANPREFIX macros to control the subdirectories
into which binaries, 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.

Delete the generated pkg-config file: it seems completely useless for an
executable tool. Its non-installation already makes this clear.

Diffstat:
MMakefile | 92+++++++++++++++++++++++++++++++++----------------------------------------------
Mconfig.mk | 28+++++++++-------------------
Dmake.sh | 70----------------------------------------------------------------------
3 files changed, 47 insertions(+), 143 deletions(-)

diff --git a/Makefile b/Makefile @@ -18,39 +18,28 @@ include config.mk -# Default target -all: build_executable man +default: tool +all: default ################################################################################ # Library building ################################################################################ -SRC = \ - src/mtool.c \ - src/mtool_actions.c\ - src/mtool_args.c\ - src/mtool_utils.c - -# Headers to configure -HDR= \ - src/mtool_version.h - +SRC =\ + src/mtool.c \ + src/mtool_actions.c\ + src/mtool_args.c\ + src/mtool_utils.c OBJ = $(SRC:.c=.o) DEP = $(SRC:.c=.d) +HDR = src/mtool_version.h -build_executable: .config $(HDR) $(DEP) - @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) mesh-tool - -$(DEP) $(OBJ): config.mk +CFLAGS_TOOL = $(CFLAGS) $(INCS) +LDFLAGS_TOOL = $(LDFLAGS) $(LIBS) -mesh-tool: $(OBJ) - $(CC) $(CFLAGS) $(DPDC_CFLAGS) -o $@ $(OBJ) $(LDFLAGS) $(DPDC_LIBS) - -.config: config.mk - @if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \ - echo "rsys $(RSYS_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 - @echo "config done" > $@ +tool: .config $(DEP) + @$(MAKE) -fMakefile \ + $$(for i in $(DEP); do printf -- '-f %s\n' "$${i}"; done) \ + mesh-tool src/mtool_version.h: config.mk src/mtool_version.h.in sed -e 's/@MTOOL_VERSION_MAJOR@/$(VERSION_MAJOR)/' \ @@ -58,46 +47,41 @@ src/mtool_version.h: config.mk src/mtool_version.h.in -e 's/@MTOOL_VERSION_PATCH@/$(VERSION_PATCH)/' \ $@.in > $@ +$(DEP) $(OBJ): config.mk $(HDR) + +mesh-tool: $(OBJ) + $(CC) $(CFLAGS_TOOL) -o $@ $(OBJ) $(LDFLAGS_TOOL) + +.config: config.mk + $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys + $(PKG_CONFIG) --atleast-version $(SSTL_VERSION) sstl + @echo "config done" > $@ + .SUFFIXES: .c .d .o .c.d: - @$(CC) $(CFLAGS) $(DPDC_CFLAGS) -MM -MT \ - "$(@:.d=.o) $@" $< -MF $@ + @$(CC) $(CFLAGS_TOOL) -MM -MT "$(@:.d=.o) $@" $< -MF $@ .c.o: - $(CC) $(CFLAGS) $(DPDC_CFLAGS) -c $< -o $@ - -################################################################################ -# Man pages -################################################################################ -man: + $(CC) $(CFLAGS_TOOL) -c $< -o $@ ################################################################################ # Installation ################################################################################ -pkg: - sed -e 's#@PREFIX@#$(PREFIX)#g'\ - -e 's#@VERSION@#$(VERSION)#g'\ - mesh-tool.pc.in > mesh-tool.pc - -install: all pkg - @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/bin" mesh-tool - @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/mesh-tool" COPYING README.md -# @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/man/man1" doc/mesh-tool.1 +install: all + 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)" mesh-tool; \ + install 644 "$(DESTDIR)$(PREFIX)/share/doc/mesh-tool" COPYING README.md uninstall: - rm -f "$(DESTDIR)$(PREFIX)/bin/mesh-tool" + rm -f "$(DESTDIR)$(BINPREFIX)/mesh-tool" rm -f "$(DESTDIR)$(PREFIX)/share/doc/mesh-tool/COPYING" rm -f "$(DESTDIR)$(PREFIX)/share/doc/mesh-tool/README.md" -# rm -f "$(DESTDIR)$(PREFIX)/share/man/man1/mesh-tool.1" -################################################################################ -# Miscellaneous targets -################################################################################ clean: - rm -f $(HDR) $(OBJ) .config mesh-tool mesh-tool.pc - -distclean: clean - rm -f $(DEP) - -lint: - shellcheck -o all make.sh + rm -f $(HDR) $(OBJ) $(DEP) .config mesh-tool diff --git a/config.mk b/config.mk @@ -2,6 +2,7 @@ VERSION_MAJOR = 0 VERSION_MINOR = 2 VERSION_PATCH = 0 VERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH) + PREFIX = /usr/local LIB_TYPE = SHARED @@ -10,6 +11,9 @@ LIB_TYPE = SHARED BUILD_TYPE = RELEASE #BUILD_TYPE = DEBUG +BINPREFIX = $(PREFIX)/bin +MANPREFIX = $(PREFIX)/share/man + ################################################################################ # Tools ################################################################################ @@ -27,20 +31,10 @@ PCFLAGS_STATIC = --static PCFLAGS = $(PCFLAGS_$(LIB_TYPE)) RSYS_VERSION = 0.14 -RSYS_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rsys) -RSYS_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rsys) - SSTL_VERSION = 0.5.1 -SSTL_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags sstl) -SSTL_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs sstl) -DPDC_CFLAGS =\ - $(RSYS_CFLAGS)\ - $(SSTL_CFLAGS) -DPDC_LIBS =\ - $(RSYS_LIBS)\ - $(SSTL_LIBS)\ - -lm +INCS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rsys sstl) +LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rsys sstl) -lm ################################################################################ # Compilation options @@ -61,9 +55,11 @@ CFLAGS_HARDENED =\ -fstack-protector-strong CFLAGS_COMMON=\ + -std=c89\ -pedantic\ -fvisibility=hidden\ -fstrict-aliasing\ + -fPIE\ $(CFLAGS_HARDENED)\ $(WFLAGS) @@ -71,19 +67,13 @@ CFLAGS_DEBUG = -g $(CFLAGS_COMMON) CFLAGS_RELEASE = -O2 -DNDEBUG $(CFLAGS_COMMON) CFLAGS = $(CFLAGS_$(BUILD_TYPE)) -CFLAGS_SO = $(CFLAGS) -fPIC -CFLAGS_EXE = $(CFLAGS) -fPIE - ################################################################################ # Linker options ################################################################################ LDFLAGS_HARDENED = -Wl,-z,relro,-z,now LDFLAGS_DEBUG = $(LDFLAGS_HARDENED) LDFLAGS_RELEASE = -s $(LDFLAGS_HARDENED) -LDFLAGS = $(LDFLAGS_$(BUILD_TYPE)) - -LDFLAGS_SO = $(LDFLAGS) -shared -Wl,--no-undefined -LDFLAGS_EXE = $(LDFLAGS) -pie +LDFLAGS = $(LDFLAGS_$(BUILD_TYPE)) -pie OCPFLAGS_DEBUG = --localize-hidden OCPFLAGS_RELEASE = --localize-hidden --strip-unneeded diff --git a/make.sh b/make.sh @@ -1,70 +0,0 @@ -#!/bin/sh - -# Copyright (C) 2015, 2016, 2019, 2021, 2023 |Méso|Star> (contact@meso-star.com) -# -# 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 - -config_test() -{ - for i in "$@"; do - test=$(basename "${i}" ".c") - test_list="${test_list} ${test}" - printf "%s: src/%s.o\n" "${test}" "${test}" - done - printf "test_bin: %s\n" "${test_list}" -} - -run_test() -{ - for i in "$@"; do - test=$(basename "${i}" ".c") - - printf "%s " "${test}" - if ./"${test}" > /dev/null 2>&1; then - printf "\033[1;32mOK\033[m\n" - else - printf "\033[1;31mError\033[m\n" - fi - done 2> /dev/null -} - -clean_test() -{ - for i in "$@"; do - rm -f "$(basename "${i}" ".c")" - done -} - -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 -} - -"$@"