commit 5c815690f16ec20100dae0822eac4178ed3d2ec2
parent 16eb7b0361e0e90e7b6003225594f45d29ed4653
Author: vaplv <vaplv@free.fr>
Date: Thu, 3 Mar 2022 21:50:54 +0100
Add a POSIX Makefile as an alternative to CMake
Diffstat:
| A | Makefile | | | 132 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | aw.pc.in | | | 10 | ++++++++++ |
| A | config.mk | | | 20 | ++++++++++++++++++++ |
3 files changed, 162 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
@@ -0,0 +1,132 @@
+# Copyright (C) 2014-2017, 2020 Vincent Forest (vaplv@free.fr)
+#
+# This CMake script 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 CMake script 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 CMake script. If not, see <http://www.gnu.org/licenses/>.
+
+.POSIX:
+.SUFFIXES: # Clean up default inference rules
+
+include config.mk
+
+################################################################################
+# RSys building
+################################################################################
+SRC = src/aw.c src/aw_obj.c src/aw_mtl.c
+
+OBJ = $(SRC:.c=.o)
+DEP = $(SRC:.c=.d)
+
+build_library: $(DEP) .config
+ @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) libaw.so
+
+$(OBJ): config.mk
+
+libaw.so: $(OBJ)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJ)
+
+.config: Makefile
+ @echo "Setup .config"
+ @if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \
+ echo "rsys $(RSYS_VERSION) not found"; exit 1; fi
+ @echo "config done" > .config
+
+.SUFFIXES: .c .d .o
+.c.d:
+ @echo "Computing dependencies for $<"
+ @$(CC) $(CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@
+
+.c.o:
+ $(CC) $(CFLAGS) -DAW_SHARED_BUILD -c $< -o $@
+
+################################################################################
+# Installation
+################################################################################
+pkg:
+ sed -e 's#@PREFIX@#$(PREFIX)#g' \
+ -e 's#@VERSION@#$(VERSION)#g' \
+ -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g' \
+ aw.pc.in > aw.pc
+
+install: build_library pkg
+ mkdir -p $(DESTDIR)$(PREFIX)/lib
+ mkdir -p $(DESTDIR)$(PREFIX)/lib/pkgconfig
+ mkdir -p $(DESTDIR)$(PREFIX)/include/
+ mkdir -p $(DESTDIR)$(PREFIX)/share/doc/aw
+ cp libaw.so $(DESTDIR)$(PREFIX)/lib
+ cp COPYING README.md $(DESTDIR)$(PREFIX)/share/doc/aw
+ cp aw.pc $(DESTDIR)$(PREFIX)/lib/pkgconfig
+ cp src/aw.h $(DESTDIR)$(PREFIX)/include
+
+uninstall:
+ rm -f $(DESTDIR)$(PREFIX)/lib/libaw.so
+ rm -f $(DESTDIR)$(PREFIX)/lib/pkgconfig/aw.pc
+ rm -f $(DESTDIR)$(PREFIX)/share/doc/aw/COPYING
+ rm -f $(DESTDIR)$(PREFIX)/share/doc/aw/README
+ rm -f $(DESTDIR)$(PREFIX)/include/aw.h
+
+################################################################################
+# Tests
+################################################################################
+TEST_SRC =\
+ src/test_aw.c\
+ src/test_aw_mtl.c\
+ src/test_aw_obj.c
+
+TEST_OBJ = $(TEST_SRC:.c=.o)
+TEST_DEP = $(TEST_SRC:.c=.d)
+
+build_tests: build_library $(TEST_DEP) .test
+ @$(MAKE) -fMakefile -f.test $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) test_bin
+
+test: build_tests
+ @$(MAKE) -fMakefile -f.test $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) test_run
+
+.test: Makefile
+ @echo "Setup tests"
+ @{ for i in $(TEST_SRC); do \
+ test=$$(echo "$${i}" | sed 's/src\/\(.\{1,\}\).c$$/\1/'); \
+ printf "test_bin: %s\n" "$${test}"; \
+ printf "%s: %s\n" "$${test}" "src/$${test}.o"; \
+ done; } > .test
+
+test_run: test_bin
+ @n=0; \
+ for i in $(TEST_SRC); do \
+ test=$$(echo $${i} | sed 's/src\/\(.\{1,\}\).c$$/\1/'); \
+ [ "$${test}" = "test_aw" ] && continue; \
+ printf "%s" $${test}; \
+ ./"$${test}" > /dev/null 2>&1 \
+ && printf " \e[1;32mOK\e[m\n" \
+ || { printf " \e[1;31mErreur\e[m\n"; n=$$((n+1)); }; \
+ done; \
+ if [ "$${n}" -ne 0 ]; then printf "%d errors\n" "$${n}"; exit 1; fi
+
+$(TEST_OBJ): config.mk
+ $(CC) $(CFLAGS) -c $(@:.o=.c) -o $@
+
+test_aw test_aw_mtl test_aw_obj: libaw.so
+ $(CC) $(CFLAGS) -o $@ -L$$(pwd) src/$@.o $$($(PKG_CONFIG) --libs rsys) -law -lrsys
+
+################################################################################
+# Miscellaneous targets
+################################################################################
+all: build_library build_tests
+
+clean:
+ @rm -f test_cbox.obj test_obj_cube.obj test_obj_plane.obj test_obj_squares.obj
+ @rm -f mtl0.mtl test_mtl_common.mtl test_mtl_multi.mtl
+ @rm -f $(OBJ) $(TEST_OBJ) libaw.so .test aw.pc .config
+ @rm -f $$(for i in $(TEST_SRC); do echo $${i} | sed 's/src\/\(.\{1,\}\).c$$/\1/'; done)
+
+distclean: clean
+ @rm -f $(DEP) $(TEST_DEP)
diff --git a/aw.pc.in b/aw.pc.in
@@ -0,0 +1,10 @@
+prefix=@PREFIX@
+includedir=${prefix}/include
+libdir=${prefix}/lib
+
+Requires.private: rsys >= @RSYS_VERSION@
+Name: AW
+Description: AW library
+Version: @VERSION@
+Libs: -L${libdir} -law
+CFlags: -I${includedir}
diff --git a/config.mk b/config.mk
@@ -0,0 +1,20 @@
+VERSION = 2.0.0
+
+PREFIX = /usr/local
+
+CPPFLAGS = -DNDEBUG
+WFLAGS = -Wall -Wextra -Wmissing-declarations -Wmissing-prototypes -Wconversion -Wshadow
+
+PKG_CONFIG=pkg-config
+
+INCS=$$($(PKG_CONFIG) --cflags rsys)
+LIBS=$$($(PKG_CONFIG) --libs rsys)
+
+CFLAGS = -O2 -std=c89 -pedantic -fPIC -fvisibility=hidden -fstrict-aliasing\
+ -Wl,--no-undefined $(WFLAGS) $(CPPFLAGS) $(INCS)
+LDFLAGS = -shared $(LIBS)
+
+CC = cc
+
+# Dependency version
+RSYS_VERSION=0.9