Makefile (5211B)
1 # Copyright (C) 2016, 2018, 2021, 2023 |Méso|Star> (contact@meso-star.com) 2 # 3 # This program is free software: you can redistribute it and/or modify 4 # it under the terms of the GNU General Public License as published by 5 # the Free Software Foundation, either version 3 of the License, or 6 # (at your option) any later version. 7 # 8 # This program is distributed in the hope that it will be useful, 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 # GNU General Public License for more details. 12 # 13 # You should have received a copy of the GNU General Public License 14 # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 .POSIX: 17 .SUFFIXES: # Clean up default inference rules 18 19 include config.mk 20 21 LIBNAME_STATIC = libs3dstl.a 22 LIBNAME_SHARED = libs3dstl.so 23 LIBNAME = $(LIBNAME_$(LIB_TYPE)) 24 25 ################################################################################ 26 # Library building 27 ################################################################################ 28 SRC = src/s3dstl.c 29 OBJ = $(SRC:.c=.o) 30 DEP = $(SRC:.c=.d) 31 32 build_library: .config $(DEP) 33 @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) \ 34 $$(if [ -n "$(LIBNAME)" ]; then\ 35 echo "$(LIBNAME)";\ 36 else\ 37 echo "$(LIBNAME_SHARED)";\ 38 fi) 39 40 $(DEP) $(OBJ): config.mk 41 42 $(LIBNAME_SHARED): $(OBJ) 43 $(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -o $@ $(OBJ) $(LDFLAGS_SO) $(DPDC_LIBS) 44 45 $(LIBNAME_STATIC): libs3dstl.o 46 $(AR) -rc $@ $? 47 $(RANLIB) $@ 48 49 libs3dstl.o: $(OBJ) 50 $(LD) -r $(OBJ) -o $@ 51 $(OBJCOPY) $(OCPFLAGS) $@ 52 53 .config: config.mk 54 @if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then\ 55 echo "rsys $(RSYS_VERSION) not found" >&2; exit 1; fi 56 @if ! $(PKG_CONFIG) --atleast-version $(S3D_VERSION) s3d; then\ 57 echo "s3d $(S3D_VERSION) not found" >&2; exit 1; fi 58 @if ! $(PKG_CONFIG) --atleast-version $(SSTL_VERSION) sstl; then\ 59 echo "sstl $(SSTL_VERSION) not found" >&2; exit 1; fi 60 @echo "config done" > $@ 61 62 .SUFFIXES: .c .d .o 63 .c.d: 64 @$(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@ 65 66 .c.o: 67 $(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -DS3DSTL_SHARED_BUILD -c $< -o $@ 68 69 ################################################################################ 70 # Installation 71 ################################################################################ 72 pkg: 73 sed -e 's#@PREFIX@#$(PREFIX)#g'\ 74 -e 's#@VERSION@#$(VERSION)#g'\ 75 -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ 76 -e 's#@S3D_VERSION@#$(S3D_VERSION)#g'\ 77 -e 's#@SSTL_VERSION@#$(SSTL_VERSION)#g'\ 78 s3dstl.pc.in > s3dstl.pc 79 80 s3dstl-local.pc: s3dstl.pc.in 81 sed -e '1d'\ 82 -e 's#^includedir=.*#includedir=./src/#'\ 83 -e 's#^libdir=.*#libdir=./#'\ 84 -e 's#@VERSION@#$(VERSION)#g'\ 85 -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ 86 -e 's#@S3D_VERSION@#$(S3D_VERSION)#g'\ 87 -e 's#@SSTL_VERSION@#$(SSTL_VERSION)#g'\ 88 s3dstl.pc.in > $@ 89 90 install: build_library pkg 91 @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" $(LIBNAME) 92 @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig/" s3dstl.pc 93 @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" src/s3dstl.h 94 @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/star-3dstl" COPYING README.md 95 96 uninstall: 97 rm -f "$(DESTDIR)$(PREFIX)/lib/libs3dstl.so" 98 rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/s3dstl.pc" 99 rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-3dstl/COPYING" 100 rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-3dstl/README.md" 101 rm -f "$(DESTDIR)$(PREFIX)/include/star/s3dstl.h" 102 103 ################################################################################ 104 # Miscellaneous targets 105 ################################################################################ 106 all: build_library build_tests 107 108 clean: clean_test 109 rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME) 110 rm -f .config .test libs3dstl.o s3dstl.pc s3dstl-local.pc 111 112 distclean: clean 113 rm -f $(DEP) $(TEST_DEP) 114 115 lint: 116 shellcheck -o all make.sh 117 118 ################################################################################ 119 # Test 120 ################################################################################ 121 TEST_OBJ = src/test_s3dstl.o 122 TEST_DEP = src/test_s3dstl.d 123 124 PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG) 125 S3DSTL_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags s3dstl-local.pc) 126 S3DSTL_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs s3dstl-local.pc) 127 128 build_tests: build_library src/test_s3dstl.d 129 @$(MAKE) -fMakefile -fsrc/test_s3dstl.d test_s3dstl 130 131 test: build_tests 132 @printf "%s " "test_s3dstl" 133 @if ./test_s3dstl > /dev/null 2>&1; then \ 134 printf "\033[1;32mOK\033[m\n"; \ 135 else \ 136 printf "\033[1;31mError\033[m\n"; \ 137 fi 138 139 clean_test: 140 rm -f test_s3dstl test_empty.stl 141 142 src/test_s3dstl.d: config.mk s3dstl-local.pc 143 @$(CC) $(CFLAGS_EXE) $(RSYS_CFLAGS) $(S3D_CFLAGS) $(S3DSTL_CFLAGS) $(SSTL_CFLAGS) \ 144 -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ 145 146 src/test_s3dstl.o: config.mk s3dstl-local.pc 147 $(CC) $(CFLAGS_EXE) $(RSYS_CFLAGS) $(S3D_CFLAGS) $(S3DSTL_CFLAGS) $(SSTL_CFLAGS) -c $(@:.o=.c) -o $@ 148 149 test_s3dstl: src/test_s3dstl.o config.mk s3dstl-local.pc $(LIBNAME) 150 $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(S3DSTL_LIBS) $(RSYS_LIBS) $(S3D_LIBS) $(SSTL_LIBS)