Makefile (5459B)
1 # Copyright (C) 2016-2018, 2021-2024 |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 = libscpr.a 22 LIBNAME_SHARED = libscpr.so 23 LIBNAME = $(LIBNAME_$(LIB_TYPE)) 24 25 ################################################################################ 26 # Library building 27 ################################################################################ 28 SRC =\ 29 src/scpr_device.c\ 30 src/scpr_intersector.c\ 31 src/scpr_mesh.c\ 32 src/scpr_polygon.c 33 OBJ = $(SRC:.c=.o) 34 DEP = $(SRC:.c=.d) 35 36 build_library: .config $(DEP) 37 @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) \ 38 $$(if [ -n "$(LIBNAME)" ]; then\ 39 echo "$(LIBNAME)";\ 40 else\ 41 echo "$(LIBNAME_SHARED)";\ 42 fi) 43 44 $(DEP) $(OBJ): config.mk 45 46 $(LIBNAME_SHARED): $(OBJ) 47 $(CXX) $(CXXFLAGS) $(DPDC_CFLAGS) -o $@ $(OBJ) $(LDFLAGS_SO) $(DPDC_LIBS) 48 49 $(LIBNAME_STATIC): libscpr.o 50 $(AR) -rc $@ $? 51 $(RANLIB) $@ 52 53 libscpr.o: $(OBJ) 54 $(LD) -r $(OBJ) -o $@ 55 $(OBJCOPY) $(OCPFLAGS) $@ 56 57 .config: config.mk 58 @if ! $(PKG_CONFIG) --atleast-version $(CLIPPER2_VERSION) Clipper2; then \ 59 echo "Clipper2 $(CLIPPER2_VERSION) not found" >&2; exit 1; fi 60 @if ! $(PKG_CONFIG) --atleast-version $(POLYGON_VERSION) polygon; then \ 61 echo "polygon $(POLYGON_VERSION) not found" >&2; exit 1; fi 62 @if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \ 63 echo "rsys $(RSYS_VERSION) not found" >&2; exit 1; fi 64 @echo "config done" > $@ 65 66 .SUFFIXES: .c .d .o 67 .c.d: 68 @$(CXX) $(CXXFLAGS) $(DPDC_CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@ 69 70 .c.o: 71 $(CXX) $(CXXFLAGS) $(DPDC_CFLAGS) -DSCPR_SHARED_BUILD -c $< -o $@ 72 73 ################################################################################ 74 # Installation 75 ################################################################################ 76 pkg: 77 sed -e 's#@PREFIX@#$(PREFIX)#g'\ 78 -e 's#@VERSION@#$(VERSION)#g'\ 79 -e 's#@CLIPPER2_VERSION@#$(CLIPPER2_VERSION)#g'\ 80 -e 's#@POLYGON_VERSION@#$(POLYGON_VERSION)#g'\ 81 -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ 82 scpr.pc.in > scpr.pc 83 84 scpr-local.pc: scpr.pc.in 85 sed -e '1d'\ 86 -e 's#^includedir=.*#includedir=./src/#'\ 87 -e 's#^libdir=.*#libdir=./#'\ 88 -e 's#@VERSION@#$(VERSION)#g'\ 89 -e 's#@CLIPPER2_VERSION@#$(CLIPPER2_VERSION)#g'\ 90 -e 's#@POLYGON_VERSION@#$(POLYGON_VERSION)#g'\ 91 -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ 92 scpr.pc.in > $@ 93 94 install: build_library pkg 95 @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" $(LIBNAME) 96 @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" scpr.pc 97 @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" src/scpr.h 98 @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/star-cpr" COPYING README.md 99 100 uninstall: 101 rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)" 102 rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/scpr.pc" 103 rm -f "$(DESTDIR)$(PREFIX)/include/star/scpr.h" 104 rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-cpr/COPYING" 105 rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-cpr/README.md" 106 107 ################################################################################ 108 # Miscellaneous targets 109 ################################################################################ 110 all: build_library build_tests 111 112 clean: clean_test 113 rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME) 114 rm -f .config .test libscpr.o scpr.pc scpr-local.pc 115 116 distclean: clean 117 rm -f $(DEP) $(TEST_DEP) 118 119 lint: 120 shellcheck -o all make.sh 121 122 ################################################################################ 123 # Tests 124 ################################################################################ 125 TEST_SRC =\ 126 src/test_scpr_clip.c\ 127 src/test_scpr_device.c\ 128 src/test_scpr_intersector.c\ 129 src/test_scpr_is_in.c\ 130 src/test_scpr_mesh.c\ 131 src/test_scpr_offset.c\ 132 src/test_scpr_polygon.c 133 TEST_OBJ = $(TEST_SRC:.c=.o) 134 TEST_DEP = $(TEST_SRC:.c=.d) 135 136 PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG) 137 SCPR_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags scpr-local.pc) 138 SCPR_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs scpr-local.pc) 139 140 build_tests: build_library $(TEST_DEP) .test 141 @$(MAKE) -fMakefile -f.test \ 142 $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) \ 143 test_bin 144 145 test: build_tests 146 @$(SHELL) make.sh run_test $(TEST_SRC) 147 148 .test: Makefile 149 @$(SHELL) make.sh config_test $(TEST_SRC) > $@ 150 151 clean_test: 152 $(SHELL) make.sh clean_test $(TEST_SRC) 153 154 $(TEST_DEP): config.mk scpr-local.pc 155 @$(CC) $(CFLAGS) $(RSYS_CFLAGS) $(SCPR_CFLAGS) \ 156 -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ 157 158 $(TEST_OBJ): config.mk scpr-local.pc 159 $(CC) $(CFLAGS) $(RSYS_CFLAGS) $(SCPR_CFLAGS) -c $(@:.o=.c) -o $@ 160 161 test_scpr_clip\ 162 test_scpr_device\ 163 test_scpr_intersector\ 164 test_scpr_is_in\ 165 test_scpr_mesh\ 166 test_scpr_offset\ 167 test_scpr_polygon \ 168 : config.mk scpr-local.pc $(LIBNAME) 169 $(CC) $(CFLAGS) -o $@ src/$@.o $(LDFLAGS_EXE) $(SCPR_LIBS) $(RSYS_LIBS) -lm