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