commit 7a50dd572764505ca1617c4b0f0eea5f35f2e8fc
parent 9b5001e4084391e99e67cc27b0157d22546b5056
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Tue, 11 Apr 2023 11:26:04 +0200
Write a POSIX Makefile as an alternative to CMake
Diffstat:
| M | .gitignore | | | 13 | ++++++------- |
| A | Makefile | | | 121 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | config.mk | | | 34 | ++++++++++++++++++++++++++++++++++ |
| A | smsh.pc.in | | | 10 | ++++++++++ |
4 files changed, 171 insertions(+), 7 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,12 +1,11 @@
.gitignore
-CMakeCache.txt
-CMakeFiles
-Makefile
-tmp
[Bb]uild*
*.sw[po]
-*.[ao]
-*.orig
+*.[aod]
+*.so
*~
+test*
+!test*.[ch]
+.pkg
tags
-
+smsh.pc
diff --git a/Makefile b/Makefile
@@ -0,0 +1,121 @@
+# Copyright (C) 2020-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
+
+################################################################################
+# Star-3D building
+################################################################################
+SRC =\
+ src/smsh.c\
+ src/smsh_log.c
+
+OBJ = $(SRC:.c=.o)
+DEP = $(SRC:.c=.d)
+
+build_library: .pkg $(DEP)
+ @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) libsmsh.so
+
+$(OBJ): config.mk
+
+libsmsh.so: $(OBJ)
+ @echo "LD $@"
+ @$(CC) $(CFLAGS) $(LDFLAGS) $(LIBS) -o $@ $(OBJ)
+
+.pkg: config.mk
+ @if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then\
+ >&2 printf "\e[1;31merror\e[0m: RSys $(RSYS_VERSION): dependency is missing\n";\
+ exit 1;\
+ fi
+ @echo "config done" > $@
+
+.SUFFIXES: .c .d .o
+.c.d:
+ @$(CC) $(CFLAGS) $(INCS) -MM -MT "$(@:.d=.o) $@" $< -MF $@
+
+.c.o:
+ @echo "CC $@"
+ @$(CC) $(CFLAGS) $(INCS) -DSMSH_SHARED_BUILD -c $< -o $@
+
+################################################################################
+# Installation
+################################################################################
+pkg:
+ @echo "Setup smsh.pc"
+ @sed -e 's#@PREFIX@#$(PREFIX)#g' \
+ -e 's#@VERSION@#$(VERSION)#g' \
+ -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g' \
+ smsh.pc.in > smsh.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-mesh
+ cp libsmsh.so $(DESTDIR)$(PREFIX)/lib
+ cp smsh.pc $(DESTDIR)$(PREFIX)/lib/pkgconfig
+ cp src/smsh.h $(DESTDIR)$(PREFIX)/include/star
+ cp COPYING README.md $(DESTDIR)$(PREFIX)/share/doc/star-mesh
+
+uninstall:
+ rm -f $(DESTDIR)$(PREFIX)/lib/libsmsh.so
+ rm -f $(DESTDIR)$(PREFIX)/lib/pkgconfig/smsh.pc
+ rm -f $(DESTDIR)$(PREFIX)/share/doc/star-mesh/COPYING
+ rm -f $(DESTDIR)$(PREFIX)/share/doc/star-mesh/README.md
+ rm -f $(DESTDIR)$(PREFIX)/include/star/smsh.h
+
+################################################################################
+# Miscellaneous targets
+################################################################################
+all: build_library build_test
+
+clean: clean_test
+ @rm -f $(OBJ) $(TEST_OBJ) libsmsh.so .test .pkg smsh.pc
+
+distclean: clean
+ @rm -f $(DEP) $(TEST_DEP)
+
+################################################################################
+# Tests
+################################################################################
+TEST_OBJ = src/test_smsh.o
+TEST_DEP = src/test_smsh.d
+
+test: build_test
+ @printf "test_smsh "; \
+ if ./test_smsh > /dev/null 2>&1; then \
+ printf "\e[1;32mOK\e[m\n"; \
+ else \
+ printf "\e[1;31mErreur\e[m\n"; \
+ fi
+
+build_test: build_library $(TEST_DEP)
+ @$(MAKE) -fMakefile -fsrc/test_smsh.d test_smsh
+
+clean_test:
+ @rm -f test_smsh
+
+$(TEST_OBJ) $(TEST_DEP): config.mk
+
+src/test_smsh.o:
+ @echo "CC $@"
+ @$(CC) $(CFLAGS) $(RSYS_INC) -c $(@:.o=.c) -o $@
+
+test_smsh: src/test_smsh.o libsmsh.so config.mk
+ @echo "LD $@"
+ @$(CC) $(CFLAGS) -o $@ src/$@.o -L$$(pwd) -lsmsh $(RSYS_LIB)
diff --git a/config.mk b/config.mk
@@ -0,0 +1,34 @@
+VERSION = 0.0.0 # Library version
+
+PREFIX = /usr/local
+PKG_CONFIG = pkg-config
+
+################################################################################
+# Dependencies
+################################################################################
+RSYS_VERSION=0.13
+RSYS_INC = $$($(PKG_CONFIG) --cflags rsys)
+RSYS_LIB = $$($(PKG_CONFIG) --libs rsys)
+
+INCS=$(RSYS_INC)
+LIBS=$(RSYS_LIB)
+
+################################################################################
+# Compilation options
+################################################################################
+CC = cc # Compiler
+
+CPPFLAGS = -DNDEBUG
+WFLAGS =\
+ -Wall\
+ -Wcast-align\
+ -Wconversion\
+ -Wextra\
+ -Wmissing-declarations\
+ -Wmissing-prototypes\
+ -Wshadow
+
+CFLAGS = -O3 -std=c89 -pedantic -fPIC -fvisibility=hidden -fstrict-aliasing\
+ -Wl,--no-undefined $(WFLAGS) $(CPPFLAGS) # Compiler options
+
+LDFLAGS = -shared # Linker options
diff --git a/smsh.pc.in b/smsh.pc.in
@@ -0,0 +1,10 @@
+prefix=@PREFIX@
+includedir=${prefix}/include
+libdir=${prefix}/lib
+
+Requires: rsys >= @RSYS_VERSION@
+Name: Star-Mesh
+Description: Star-Mesh Library
+Version: @VERSION@
+Libs: -L${libdir} -lsmsh
+CFlags: -I${includedir}