commit e616f7359de5fa0692e36beb8c66d1e4e578a282
parent 6baa2835fe031a6bebd278b11413f362d9bd230e
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Sun, 10 Sep 2023 21:11:15 +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 | | | 12 | +++++------- |
| A | Makefile | | | 84 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | config.mk | | | 68 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | make.sh | | | 39 | +++++++++++++++++++++++++++++++++++++++ |
4 files changed, 196 insertions(+), 7 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,11 +1,9 @@
.gitignore
-CMakeCache.txt
-CMakeFiles
-Makefile
-tmp
-[Bb]uild*
+[Bb]uild
*.sw[po]
-*.[ao]
+*.[od]
*~
+.config
tags
-
+src/htpp_version.h
+htpp
diff --git a/Makefile b/Makefile
@@ -0,0 +1,84 @@
+# Copyright (C) 2018-2020, 2023 |Méso|Star> (contact@meso-star.com)
+# Copyright (C) 2018, 2019 Centre National de la Recherche Scientifique
+# Copyright (C) 2018, 2019 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
+
+################################################################################
+# Library building
+################################################################################
+SRC = src/htpp.c
+OBJ = $(SRC:.c=.o)
+DEP = $(SRC:.c=.d)
+
+build_library: .config $(DEP)
+ @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) htpp
+
+$(DEP) $(OBJ): config.mk
+
+htpp: $(OBJ)
+ $(CC) -o $@ $(OBJ) $(LDFLAGS) $(DPDC_LIBS)
+
+.config: config.mk
+ @if ! $(PKG_CONFIG) --atleast-version $(SCMAP_VERSION) scmap; then \
+ echo "scmap $(SCMAP_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
+ @echo "config done" > $@
+
+src/htpp.d: src/htpp_version.h
+
+src/htpp_version.h: src/htpp_version.h.in config.mk
+ sed -e 's#@VERSION_MAJOR@#$(VERSION_MAJOR)#g' \
+ -e 's#@VERSION_MINOR@#$(VERSION_MINOR)#g' \
+ -e 's#@VERSION_PATCH@#$(VERSION_PATCH)#g' \
+ src/htpp_version.h.in > $@
+
+.SUFFIXES: .c .d .o
+.c.d:
+ @$(CC) $(CFLAGS) $(DPDC_CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@
+
+.c.o:
+ $(CC) $(CFLAGS) $(DPDC_CFLAGS) -c $< -o $@
+
+################################################################################
+# Installation
+################################################################################
+install: build_library pkg
+ @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/bin" htpp
+ @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/htpp" COPYING README.md
+
+uninstall:
+ rm -f "$(DESTDIR)$(PREFIX)/bin/htpp"
+ rm -f "$(DESTDIR)$(PREFIX)/share/doc/htmie/COPYING"
+ rm -f "$(DESTDIR)$(PREFIX)/share/doc/htmie/README.md"
+
+################################################################################
+# Miscellaneous targets
+################################################################################
+all: build_library
+
+clean:
+ rm -f $(OBJ) htpp .config
+
+distclean: clean
+ rm -f $(DEP) src/htpp_version.h
+
+lint:
+ shellcheck -o all make.sh
diff --git a/config.mk b/config.mk
@@ -0,0 +1,68 @@
+VERSION_MAJOR = 0
+VERSION_MINOR = 4
+VERSION_PATCH = 4
+VERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH)
+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))
+
+SCMAP_VERSION = 0.0
+SCMAP_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags scmap)
+SCMAP_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs scmap)
+
+RSYS_VERSION = 0.9
+RSYS_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rsys)
+RSYS_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rsys)
+
+DPDC_CFLAGS = $(SCMAP_CFLAGS) $(RSYS_CFLAGS) -fopenmp
+DPDC_LIBS = $(SCMAP_LIBS) $(RSYS_LIBS) -fopenmp -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
+################################################################################
+LDFLAGS_DEBUG =
+LDFLAGS_RELEASE = -s
+LDFLAGS = $(LDFLAGS_$(BUILD_TYPE))
diff --git a/make.sh b/make.sh
@@ -0,0 +1,39 @@
+#!/bin/sh -e
+
+# Copyright (C) 2018-2020, 2023 |Méso|Star> (contact@meso-star.com)
+# Copyright (C) 2018, 2019 Centre National de la Recherche Scientifique
+# Copyright (C) 2018, 2019 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
+}
+
+"$@"