commit 671828489810bf57770d75ac06503daf7ab7270c
parent eae8859ae65e7c492121618eed94c7d7d4d34ea3
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Thu, 30 May 2024 16:49:24 +0200
Replace CMake by POSIX make
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.
In addition to the features previously provided by its CMake
alternative, this Makefile supports the use of static libraries and
provides an uninstall target. It also enable compiler and linker options
that activate various hardening features aimed at increasing the
security and robustness of generated binaries. 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:
| A | Makefile | | | 146 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | config.mk | | | 132 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | make.sh | | | 39 | +++++++++++++++++++++++++++++++++++++++ |
3 files changed, 317 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
@@ -0,0 +1,146 @@
+# Copyright (C) 2018-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/>.
+
+.POSIX:
+.SUFFIXES: # Clean up default inference rules
+
+include config.mk
+
+# Default target
+all: build_executable man
+
+################################################################################
+# Program building
+################################################################################
+SRC =\
+ src/cg_args.c\
+ src/cg_building.c\
+ src/cg_catalog.c\
+ src/cg_catalog_parsing.c\
+ src/cg_city.c\
+ src/cg_city_parsing.c\
+ src/cg_construction_mode_0.c\
+ src/cg_construction_mode_1.c\
+ src/cg_construction_mode.c\
+ src/cg_ground.c\
+ src/cg_main.c\
+ src/cg_types.c\
+ src/cg_vertex_denoiser.c
+
+# Headers to configure
+HDR=\
+ src/cg_default.h\
+ src/cg_version.h
+
+OBJ = $(SRC:.c=.o)
+DEP = $(SRC:.c=.d)
+
+build_executable: .config $(HDR) $(DEP)
+ @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) city_generator2
+
+$(DEP) $(OBJ): config.mk
+
+city_generator2: $(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 $(SCAD_VERSION) scad; then \
+ echo "scad $(SCAD_VERSION) not found" >&2; exit 1; fi
+ @if ! $(PKG_CONFIG) --atleast-version $(SCPR_VERSION) scpr; then \
+ echo "scpr $(SCPR_VERSION) not found" >&2; exit 1; fi
+ @if ! $(PKG_CONFIG) --atleast-version $(LIBCYAML_VERSION) libcyaml; then \
+ echo "libcyaml $(LIBCYAML_VERSION) not found" >&2; exit 1; fi
+ @echo "config done" > $@
+
+src/cg_default.h: config.mk src/cg_default.h.in
+ sed -e 's/@CG2_ARGS_DEFAULT_VERBOSITY_LEVEL@/$(CG2_ARGS_DEFAULT_VERBOSITY_LEVEL)/' \
+ -e 's/@CG2_ARGS_BINARY_STL_DEFAULT@/$(CG2_ARGS_BINARY_STL_DEFAULT)/' \
+ -e 's/@CG2_ARGS_STL_DEFAULT_STR@/$(CG2_ARGS_STL_DEFAULT_STR)/' \
+ -e 's/@CG2_ARGS_STL_NON_DEFAULT_STR@/$(CG2_ARGS_STL_NON_DEFAULT_STR)/' \
+ -e 's/@CG2_ARGS_CHANGE_BINARY_DEFAULT_OPTION@/$(CG2_ARGS_CHANGE_BINARY_DEFAULT_OPTION)/' \
+ -e 's/@CG2_CLOSE_NEIGHBOR_DISTANCE@/$(CG2_CLOSE_NEIGHBOR_DISTANCE)/' \
+ -e 's/@CG2_MIN_DISTANCE_TO_MAP_LIMITS@/$(CG2_MIN_DISTANCE_TO_MAP_LIMITS)/' \
+ -e 's/@CG2_MIN_WINDOWS_WIDTH@/$(CG2_MIN_WINDOWS_WIDTH)/' \
+ $@.in > $@
+
+src/cg_version.h: config.mk src/cg_version.h.in
+ sed -e 's/@CG2_VERSION_MAJOR@/$(VERSION_MAJOR)/' \
+ -e 's/@CG2_VERSION_MINOR@/$(VERSION_MINOR)/' \
+ -e 's/@CG2_VERSION_PATCH@/$(VERSION_PATCH)/' \
+ $@.in > $@
+
+.SUFFIXES: .c .d .o
+.c.d:
+ @$(CC) $(CFLAGS) $(DPDC_CFLAGS) -MM -MT \
+ "$(@:.d=.o) $@" $< -MF $@
+
+.c.o:
+ $(CC) $(CFLAGS) $(DPDC_CFLAGS) -c $< -o $@
+
+################################################################################
+# Man pages
+################################################################################
+man: doc/city_generator2.1 doc/city_generator2-input.5 doc/city_generator2-output.5
+
+doc/city_generator2.1: doc/city_generator2.1.txt
+ $(A2X) $(A2X_FLAGS) $<
+
+doc/city_generator2-input.5: doc/city_generator2-input.5.txt
+ $(A2X) $(A2X_FLAGS) $<
+
+doc/city_generator2-output.5: doc/city_generator2-output.5.txt
+ $(A2X) $(A2X_FLAGS) $<
+
+doc/city_generator2.1.txt: doc/city_generator2.1.txt.in
+ sed -e 's/@CG2_ARGS_DEFAULT_VERBOSITY_LEVEL@/$(CG2_ARGS_DEFAULT_VERBOSITY_LEVEL)/' \
+ -e 's/@CG2_ARGS_CHANGE_BINARY_DEFAULT_OPTION@/$(CG2_ARGS_CHANGE_BINARY_DEFAULT_OPTION)/' \
+ -e 's/@CG2_ARGS_STL_NON_DEFAULT_STR@/$(CG2_ARGS_STL_NON_DEFAULT_STR)/' \
+ -e 's/@CG2_ARGS_STL_DEFAULT_STR@/$(CG2_ARGS_STL_DEFAULT_STR)/' \
+ $@.in > $@
+
+################################################################################
+# Installation
+################################################################################
+install: all
+ @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/bin" city_generator2
+ @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/city_generator2" COPYING README.md
+ @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/man/man1" doc/city_generator2.1
+ @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/man/man5" doc/city_generator2-input.5
+ @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/man/man5" doc/city_generator2-output.5
+
+uninstall:
+ rm -f "$(DESTDIR)$(PREFIX)/bin/city_generator2"
+ rm -f "$(DESTDIR)$(PREFIX)/share/doc/city_generator2/COPYING"
+ rm -f "$(DESTDIR)$(PREFIX)/share/doc/city_generator2/README.md"
+ rm -f "$(DESTDIR)$(PREFIX)/share/man/man1/city_generator2.1"
+ rm -f "$(DESTDIR)$(PREFIX)/share/man/man5/city_generator2-input.5"
+ rm -f "$(DESTDIR)$(PREFIX)/share/man/man5/city_generator2-output.5"
+
+################################################################################
+# Miscellaneous targets
+################################################################################
+clean:
+ rm -f $(HDR) $(OBJ) .config city_generator2 doc/city_generator2.1
+
+distclean: clean
+ rm -f $(DEP)
+
+lint: man
+ shellcheck -o all make.sh
+ mandoc -Tlint -Wall doc/city_generator2.1 || [ $$? -le 1 ]
+ mandoc -Tlint -Wall doc/city_generator2-input.5 || [ $$? -le 1 ]
+ mandoc -Tlint -Wall doc/city_generator2-output.5 || [ $$? -le 1 ]
diff --git a/config.mk b/config.mk
@@ -0,0 +1,132 @@
+VERSION_MAJOR = 0
+VERSION_MINOR = 2
+VERSION_PATCH = 0
+VERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH)
+PREFIX = /usr/local
+
+LIB_TYPE = SHARED
+#LIB_TYPE = STATIC
+
+BUILD_TYPE = RELEASE
+#BUILD_TYPE = DEBUG
+
+################################################################################
+# Configuration values
+################################################################################
+# Default verbosity when running city_generator2 (can be changed from the command line)
+CG2_ARGS_DEFAULT_VERBOSITY_LEVEL = 1
+# Default format of the output STL files (can be changed from the command line)
+CG2_STL_OUTPUT_DEFAULT_IS_BINARY = 0
+# Distance up to which neighbor buildings prevent windows' creation (in m)
+CG2_CLOSE_NEIGHBOR_DISTANCE = 2
+# Minimum allowed distance beetween a building and map's limits (in m)
+CG2_MIN_DISTANCE_TO_MAP_LIMITS = 2
+# Minimum width for windows or they are not created (in m)
+CG2_MIN_WINDOWS_WIDTH = 0.1
+
+################################################################################
+# Tools
+################################################################################
+AR = ar
+CC = cc
+LD = ld
+OBJCOPY = objcopy
+PKG_CONFIG = pkg-config
+RANLIB = ranlib
+A2X = a2x
+
+################################################################################
+# Dependencies
+################################################################################
+PCFLAGS_SHARED =
+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)
+
+SCAD_VERSION = 0.5
+SCAD_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags scad)
+SCAD_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs scad)
+
+SCPR_VERSION = 0.4.1
+SCPR_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags scpr)
+SCPR_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs scpr)
+
+LIBCYAML_VERSION = 1.3.1
+LIBCYAML_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags libcyaml)
+LIBCYAML_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs libcyaml)
+
+DPDC_CFLAGS =\
+ $(RSYS_CFLAGS)\
+ $(SCAD_CFLAGS)\
+ $(SCPR_CFLAGS)\
+ $(LIBCYAML_CFLAGS)
+DPDC_LIBS =\
+ $(RSYS_LIBS)\
+ $(SCAD_LIBS)\
+ $(SCPR_LIBS)\
+ $(LIBCYAML_LIBS)\
+ -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 = -O3 -DNDEBUG $(CFLAGS_COMMON)
+CFLAGS_DEBUG = -g $(CFLAGS_COMMON)
+CFLAGS = $(CFLAGS_$(BUILD_TYPE)) -fPIE
+
+################################################################################
+# Asciidoc options
+################################################################################
+A2X_FLAGS = -dmanpage -fmanpage
+
+################################################################################
+# 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))
+
+################################################################################
+# Other Values deduced from configuration values
+################################################################################
+CG2_ARGS_STL_DEFAULT_STR_0 = ascii
+CG2_ARGS_STL_DEFAULT_STR_1 = binary
+CG2_ARGS_STL_NON_DEFAULT_STR_0 = binary
+CG2_ARGS_STL_NON_DEFAULT_STR_1 = ascii
+CG2_ARGS_CHANGE_BINARY_DEFAULT_OPTION_0 = b
+CG2_ARGS_CHANGE_BINARY_DEFAULT_OPTION_1 = a
+CG2_ARGS_BINARY_STL_DEFAULT = $(CG2_STL_OUTPUT_DEFAULT_IS_BINARY)
+CG2_ARGS_STL_DEFAULT_STR = $(CG2_ARGS_STL_DEFAULT_STR_$(CG2_STL_OUTPUT_DEFAULT_IS_BINARY))
+CG2_ARGS_STL_NON_DEFAULT_STR = $(CG2_ARGS_STL_NON_DEFAULT_STR_$(CG2_STL_OUTPUT_DEFAULT_IS_BINARY))
+CG2_ARGS_CHANGE_BINARY_DEFAULT_OPTION = $(CG2_ARGS_CHANGE_BINARY_DEFAULT_OPTION_$(CG2_STL_OUTPUT_DEFAULT_IS_BINARY))
diff --git a/make.sh b/make.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+# Copyright (C) 2018-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
+
+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
+}
+
+"$@"