commit 782bbe2c6cece428b3ae1a8b2996d2d737ddbfa4
parent 095918c3e482b890fb9a06715f5ad32fd05af7a2
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Tue, 21 Mar 2023 15:42:58 +0100
Write a POSIX Makefile as an alternative to CMake
Diffstat:
| M | .gitignore | | | 14 | ++++++++------ |
| A | Makefile | | | 127 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | config.mk | | | 46 | ++++++++++++++++++++++++++++++++++++++++++++++ |
| A | make.sh | | | 92 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | s3daw.pc.in | | | 11 | +++++++++++ |
5 files changed, 284 insertions(+), 6 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,11 +1,13 @@
.gitignore
-CMakeCache.txt
-CMakeFiles
-Makefile
-tmp
[Bb]uild*
*.sw[po]
-*.[ao]
+*.[aod]
+*.so
*~
+test*
+!test*.[ch]
+.pkg
tags
-
+s3daw.pc
+*.mtl
+*.obj
diff --git a/Makefile b/Makefile
@@ -0,0 +1,127 @@
+# Copyright (C) 2015, 2016, 2020, 2021 |Meso|Star> (contact@meso-star.com)
+#
+# This software is governed by the CeCILL license under French law and
+# abiding by the rules of distribution of free software. You can use,
+# modify and/or redistribute the software under the terms of the CeCILL
+# license as circulated by CEA, CNRS and INRIA at the following URL
+# "http://www.cecill.info".
+#
+# As a counterpart to the access to the source code and rights to copy,
+# modify and redistribute granted by the license, users are provided only
+# with a limited warranty and the software's author, the holder of the
+# economic rights, and the successive licensors have only limited
+# liability.
+#
+# In this respect, the user's attention is drawn to the risks associated
+# with loading, using, modifying and/or developing or reproducing the
+# software by the user in light of its specific status of free software,
+# that may mean that it is complicated to manipulate, and that also
+# therefore means that it is reserved for developers and experienced
+# professionals having in-depth computer knowledge. Users are therefore
+# encouraged to load and test the software's suitability as regards their
+# requirements in conditions enabling the security of their systems and/or
+# data to be ensured and, more generally, to use and operate it in the
+# same conditions as regards security.
+#
+# The fact that you are presently reading this means that you have had
+# knowledge of the CeCILL license and that you accept its terms.
+
+.POSIX:
+.SUFFIXES: # Clean up default inference rules
+
+include config.mk
+
+################################################################################
+# Star-3DAW building
+################################################################################
+SRC = src/s3daw.c
+
+OBJ = $(SRC:.c=.o)
+DEP = $(SRC:.c=.d)
+
+build_library: .pkg $(DEP)
+ @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) libs3daw.so
+
+$(OBJ) $(DEP): config.mk
+
+libs3daw.so: $(OBJ)
+ @echo "LD $@"
+ @$(CC) $(CFLAGS) $(LDFLAGS) $(LIBS) -o $@ $(OBJ)
+
+.pkg: make.sh config.mk
+ @$(SHELL) make.sh config_pkg && echo "pkg done" > $@ || exit 1
+
+.SUFFIXES: .c .d .o
+.c.d:
+ @$(CC) $(CFLAGS) $(INCS) -MM -MT "$(@:.d=.o) $@" $< -MF $@
+
+.c.o:
+ @echo "CC $@"
+ @$(CC) $(CFLAGS) $(INCS) -DS3DAW_SHARED_BUILD -c $< -o $@
+
+################################################################################
+# Installation
+################################################################################
+pkg:
+ @echo "Setup s3daw.pc"
+ @sed -e 's#@PREFIX@#$(PREFIX)#g' \
+ -e 's#@VERSION@#$(VERSION)#g' \
+ -e 's#@AW_VERSION@#$(AW_VERSION)#g' \
+ -e 's#@POLYGON_VERSION@#$(POLYGON_VERSION)#g' \
+ -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g' \
+ -e 's#@STAR-3D_VERSION@#$(STAR-3D_VERSION)#g' \
+ s3daw.pc.in > s3daw.pc
+
+install: build_library pkg
+ mkdir -p $(DESTDIR)$(PREFIX)/lib
+ mkdir -p $(DESTDIR)$(PREFIX)/lib/pkgconfig
+ mkdir -p $(DESTDIR)$(PREFIX)/include/star
+ mkdir -p $(DESTDIR)$(PREFIX)/share/doc/star-3daw
+ cp libs3daw.so $(DESTDIR)$(PREFIX)/lib
+ cp s3daw.pc $(DESTDIR)$(PREFIX)/lib/pkgconfig
+ cp src/s3daw.h $(DESTDIR)$(PREFIX)/include/star
+ cp COPYING.en COPYING.fr README.md $(DESTDIR)$(PREFIX)/share/doc/star-3daw
+
+uninstall:
+ rm -f $(DESTDIR)$(PREFIX)/lib/libs3daw.so
+ rm -f $(DESTDIR)$(PREFIX)/lib/pkgconfig/s3daw.pc
+ rm -f $(DESTDIR)$(PREFIX)/share/doc/star-3daw/COPYING.en
+ rm -f $(DESTDIR)$(PREFIX)/share/doc/star-3daw/COPYING.fr
+ rm -f $(DESTDIR)$(PREFIX)/share/doc/star-3daw/README.md
+ rm -f $(DESTDIR)$(PREFIX)/include/star/s3daw.h
+
+################################################################################
+# Miscellaneous targets
+################################################################################
+all: build_library build_tests
+
+clean: clean_test
+ @rm -f $(OBJ) $(TEST_OBJ) libs3d.so .test s3d.pc .pkg
+
+distclean: clean
+ @rm -f $(DEP) $(TEST_DEP)
+
+################################################################################
+# Test
+################################################################################
+TEST_OBJ = src/test_s3daw.o
+TEST_DEP = src/test_s3daw.d
+
+test: build_tests
+ @$(SHELL) make.sh run_test test_s3daw
+
+build_tests: src/test_s3daw.d
+ @$(MAKE) -fMakefile -fsrc/test_s3daw.d test_s3daw
+
+clean_test:
+ @rm -f test_s3daw cbox.mtl cbox2.mtl cbox.obj
+
+$(TEST_OBJ) $(TEST_DEP): config.mk
+
+src/test_s3daw.o: src/test_s3daw.c
+ @echo "CC $@"
+ @$(CC) $(CFLAGS) $(RSYS_INC) $(STAR-3D_INC) -c $< -o $@
+
+test_s3daw: src/test_s3daw.o libs3daw.so config.mk
+ @echo "LD $@"
+ @$(CC) $(CFLAGS) -o $@ src/$@.o -L$$(pwd) -ls3daw $(RSYS_LIB) $(STAR-3D_LIB)
diff --git a/config.mk b/config.mk
@@ -0,0 +1,46 @@
+VERSION = 0.4.1 # Library version
+
+PREFIX = /usr/local
+PKG_CONFIG = pkg-config
+
+################################################################################
+# Dependencies
+################################################################################
+AW_VERSION=2.0
+AW_INC = $$($(PKG_CONFIG) --cflags aw)
+AW_LIB = $$($(PKG_CONFIG) --libs aw)
+
+POLYGON_VERSION=0.1
+POLYGON_INC = $$($(PKG_CONFIG) --cflags polygon)
+POLYGON_LIB = $$($(PKG_CONFIG) --libs polygon)
+
+RSYS_VERSION=0.6
+RSYS_INC = $$($(PKG_CONFIG) --cflags rsys)
+RSYS_LIB = $$($(PKG_CONFIG) --libs rsys)
+
+STAR-3D_VERSION=0.3
+STAR-3D_INC = $$($(PKG_CONFIG) --cflags s3d)
+STAR-3D_LIB = $$($(PKG_CONFIG) --libs s3d)
+
+INCS=$(AW_INC) $(POLYGON_INC) $(RSYS_INC) $(STAR-3D_INC)
+LIBS=$(AW_LIB) $(POLYGON_LIB) $(RSYS_LIB) $(STAR-3D_LIB)
+
+################################################################################
+# Compilation options
+################################################################################
+CC = cc # Compiler
+
+CPPFLAGS = -DNDEBUG
+WFLAGS =\
+ -Wall\
+ -Wcast-align\
+ -Wconversion\
+ -Wextra\
+ -Wmissing-declarations\
+ -Wmissing-prototypes\
+ -Wshadow
+
+CFLAGS = -O3 -std=c99 -pedantic -fPIC -fvisibility=hidden -fstrict-aliasing\
+ -Wl,--no-undefined $(WFLAGS) $(CPPFLAGS) # Compiler options
+
+LDFLAGS = -shared # Linker options
diff --git a/make.sh b/make.sh
@@ -0,0 +1,92 @@
+#!/bin/sh -e
+
+# Copyright (C) 2015, 2016, 2020, 2021 |Meso|Star> (contact@meso-star.com)
+#
+# This software is governed by the CeCILL license under French law and
+# abiding by the rules of distribution of free software. You can use,
+# modify and/or redistribute the software under the terms of the CeCILL
+# license as circulated by CEA, CNRS and INRIA at the following URL
+# "http://www.cecill.info".
+#
+# As a counterpart to the access to the source code and rights to copy,
+# modify and redistribute granted by the license, users are provided only
+# with a limited warranty and the software's author, the holder of the
+# economic rights, and the successive licensors have only limited
+# liability.
+#
+# In this respect, the user's attention is drawn to the risks associated
+# with loading, using, modifying and/or developing or reproducing the
+# software by the user in light of its specific status of free software,
+# that may mean that it is complicated to manipulate, and that also
+# therefore means that it is reserved for developers and experienced
+# professionals having in-depth computer knowledge. Users are therefore
+# encouraged to load and test the software's suitability as regards their
+# requirements in conditions enabling the security of their systems and/or
+# data to be ensured and, more generally, to use and operate it in the
+# same conditions as regards security.
+#
+# The fact that you are presently reading this means that you have had
+# knowledge of the CeCILL license and that you accept its terms.
+
+################################################################################
+# Helper functions
+################################################################################
+# Print the value of a variable in config.mk
+showvar()
+{
+ # To avoid messages from Make being displayed instead of the value of the
+ # queried variable, we redirect its output to /dev/null and open a new file
+ # descriptor to stdout to print the variable
+<< EOF make -f 3>&1 1>/dev/null 2>&1 - || kill -HUP $$
+.POSIX:
+include config.mk
+showvar:
+ @1>&3 echo \$(${1})
+EOF
+ exec 3<&- # Close file descriptor 3
+}
+
+################################################################################
+# Main functions
+################################################################################
+run_test()
+{
+ for i in "$@"; do
+ printf "%s " "${i}"
+ if ./"${i}" > /dev/null 2>&1; then
+ printf "\e[1;32mOK\e[m\n"
+ else
+ printf "\e[1;31mErreur\e[m\n"
+ n=$((n+1))
+ fi
+ done
+}
+
+config_pkg()
+{
+ pkg_config=$(showvar PKG_CONFIG)
+
+ aw_version=$(showvar AW_VERSION)
+ polygon_version=$(showvar POLYGON_VERSION)
+ rsys_version=$(showvar RSYS_VERSION)
+ s3d_version=$(showvar STAR-3D_VERSION)
+ dependencies="\
+ AW aw ${aw_version}
+ Polygon polygon ${polygon_version}
+ RSys rsys ${rsys_version}
+ Star-3D s3d ${s3d_version}"
+
+ printf "%s\n" "${dependencies}" | while read -r i; do
+ name=$(printf "%s" "${i}" | cut -d' ' -f1)
+ pc=$(printf "%s" "${i}" | cut -d' ' -f2)
+ version=$(printf "%s" "${i}" | cut -d' ' -f3)
+
+ if ! "${pkg_config}" --atleast-version "${version}" "${pc}"; then
+ >&2 printf "\e[1;31merror\e[0m:%s %s: dependency is missing\n" \
+ "${name}" "${version}"
+ exit 1
+ fi
+ done || exit $?
+}
+
+"$@"
diff --git a/s3daw.pc.in b/s3daw.pc.in
@@ -0,0 +1,11 @@
+prefix=@PREFIX@
+includedir=${prefix}/include
+libdir=${prefix}/lib
+
+Requires: rsys >= @RSYS_VERSION@
+Requires.private: aw >= @AW_VERSION@, polygon >= @POLYGON_VERSION@, s3d >= @STAR-3D_VERSION@
+Name: Star-3D
+Description: Star-3DAW library
+Version: @VERSION@
+Libs: -L${libdir} -ls3daw
+CFlags: -I${includedir}