commit fa0bc2e9b0bc55742483ff862f874075b03c2f16
parent e9ad4baa82b4f8aecf6795466051c69292cd9ad2
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 14 Sep 2023 16:39:34 +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 | | | 11 | +++++------ |
| A | Makefile | | | 127 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | config.mk | | | 93 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | htsky.pc.in | | | 11 | +++++++++++ |
| A | make.sh | | | 39 | +++++++++++++++++++++++++++++++++++++++ |
5 files changed, 275 insertions(+), 6 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,11 +1,10 @@
.gitignore
-CMakeCache.txt
-CMakeFiles
-Makefile
-tmp
[Bb]uild*
*.sw[po]
-*.[ao]
-*.orig
+*.[aod]
+*.so
*~
+.config
+.test
tags
+*.pc
diff --git a/Makefile b/Makefile
@@ -0,0 +1,127 @@
+# Copyright (C) 2018, 2019, 2020, 2021 |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
+
+LIBNAME_STATIC = libhtsky.a
+LIBNAME_SHARED = libhtsky.so
+LIBNAME = $(LIBNAME_$(LIB_TYPE))
+
+################################################################################
+# Library building
+################################################################################
+SRC =\
+ src/htsky_atmosphere.c\
+ src/htsky.c\
+ src/htsky_cloud.c\
+ src/htsky_dump_cloud_vtk.c\
+ src/htsky_log.c\
+ src/htsky_svx.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 $(HTCP_VERSION) htcp; then \
+ echo "htcp $(HTCP_VERSION) not found" >&2; exit 1; fi
+ @if ! $(PKG_CONFIG) --atleast-version $(HTGOP_VERSION) htgop; then \
+ echo "htgop $(HTGOP_VERSION) not found" >&2; exit 1; fi
+ @if ! $(PKG_CONFIG) --atleast-version $(HTMIE_VERSION) htmie; then \
+ echo "htmie $(HTMIE_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 $(SVX_VERSION) svx; then \
+ echo "svx $(SVX_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) -DHTSKY_SHARED_BUILD -c $< -o $@
+
+################################################################################
+# Installation
+################################################################################
+pkg:
+ sed -e 's#@PREFIX@#$(PREFIX)#g'\
+ -e 's#@VERSION@#$(VERSION)#g'\
+ -e 's#@HTCP_VERSION@#$(HTCP_VERSION)#g'\
+ -e 's#@HTGOP_VERSION@#$(HTGOP_VERSION)#g'\
+ -e 's#@HTMIE_VERSION@#$(HTMIE_VERSION)#g'\
+ -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
+ -e 's#@SVX_VERSION@#$(SVX_VERSION)#g'\
+ htsky.pc.in > htsky.pc
+
+htmie-local.pc: htmie.pc.in
+ sed -e '1d'\
+ -e 's#^includedir=.*#includedir=./src/#'\
+ -e 's#^libdir=.*#libdir=./#'\
+ -e 's#@VERSION@#$(VERSION)#g'\
+ -e 's#@HTCP_VERSION@#$(HTCP_VERSION)#g'\
+ -e 's#@HTGOP_VERSION@#$(HTGOP_VERSION)#g'\
+ -e 's#@HTMIE_VERSION@#$(HTMIE_VERSION)#g'\
+ -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
+ -e 's#@SVX_VERSION@#$(SVX_VERSION)#g'\
+ htsky.pc.in > $@
+
+install: build_library pkg
+ @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" $(LIBNAME)
+ @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" htsky.pc
+ @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/high_tune" src/htsky.h
+ @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/htsky" COPYING README.md
+
+uninstall:
+ rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)"
+ rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/htsky.pc"
+ rm -f "$(DESTDIR)$(PREFIX)/share/doc/htsky/COPYING"
+ rm -f "$(DESTDIR)$(PREFIX)/share/doc/htsky/README.md"
+ rm -f "$(DESTDIR)$(PREFIX)/include/high_tune/htsky.h"
+
+################################################################################
+# Miscellaneous targets
+################################################################################
+all: build_library
+
+clean:
+ rm -f $(OBJ) $(LIBNAME) .config htsky.pc
+
+distclean: clean
+ rm -f $(DEP)
+
+lint:
+ shellcheck -o all make.sh
diff --git a/config.mk b/config.mk
@@ -0,0 +1,93 @@
+VERSION = 0.2.2
+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))
+
+HTCP_VERSION = 0.0.5
+HTCP_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags htcp)
+HTCP_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs htcp)
+
+HTGOP_VERSION = 0.1.2
+HTGOP_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags htgop)
+HTGOP_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs htgop)
+
+HTMIE_VERSION = 0.0.4
+HTMIE_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags htmie)
+HTMIE_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs htmie)
+
+RSYS_VERSION = 0.13
+RSYS_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rsys)
+RSYS_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rsys)
+
+SVX_VERSION = 0.2.1
+SVX_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags svx)
+SVX_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs svx)
+
+DPDC_CFLAGS =\
+ $(HTCP_CFLAGS)\
+ $(HTGOP_CFLAGS)\
+ $(HTMIE_CFLAGS)\
+ $(RSYS_CFLAGS)\
+ $(SVX_CFLAGS)\
+ -fopenmp
+
+DPDC_LIBS =\
+ $(HTCP_LIBS)\
+ $(HTGOP_LIBS)\
+ $(HTMIE_LIBS)\
+ $(RSYS_LIBS)\
+ $(SVX_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
+################################################################################
+SOFLAGS = -shared -Wl,--no-undefined
+
+LDFLAGS_DEBUG =
+LDFLAGS_RELEASE = -s
+LDFLAGS = $(LDFLAGS_$(BUILD_TYPE))
diff --git a/htsky.pc.in b/htsky.pc.in
@@ -0,0 +1,11 @@
+prefix=@PREFIX@
+includedir=${prefix}/include
+libdir=${prefix}/lib
+
+Requires: rsys >= @RSYS_VERSION@, svx >= @SVX_VERSION@
+Requires.private: htcp >= @HTCP_VERSION@, htgop >= @HTGOP_VERSION@, htmie >= @HTMIE_VERSION@
+Name: htsky
+Description: High-Tune Sky
+Version: @VERSION@
+Libs: -L${libdir} -lhtsky
+CFlags: -I${includedir}
diff --git a/make.sh b/make.sh
@@ -0,0 +1,39 @@
+#!/bin/sh -e
+
+# Copyright (C) 2018, 2019, 2020, 2021 |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
+}
+
+"$@"