Makefile (7411B)
1 # Copyright (C) 2018-2021, 2023, 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 = libsenc2d.a 22 LIBNAME_SHARED = libsenc2d.so 23 LIBNAME = $(LIBNAME_$(LIB_TYPE)) 24 25 ################################################################################ 26 # Library building 27 ################################################################################ 28 SRC =\ 29 src/senc2d_descriptor.c\ 30 src/senc2d_device.c\ 31 src/senc2d_enclosure.c\ 32 src/senc2d_scene.c\ 33 src/senc2d_scene_analyze.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) $(DPDC_CFLAGS) -o $@ $(OBJ) $(LDFLAGS_SO) $(DPDC_LIBS) 49 50 $(LIBNAME_STATIC): libsenc2d.o 51 $(AR) -rc $@ $? 52 $(RANLIB) $@ 53 54 libsenc2d.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 @if ! $(PKG_CONFIG) --atleast-version $(S2D_VERSION) s2d; then \ 62 echo "s2d $(S2D_VERSION) not found" >&2; exit 1; fi 63 @echo "config done" > $@ 64 65 .SUFFIXES: .c .d .o 66 .c.d: 67 @$(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@ 68 69 .c.o: 70 $(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -DSENC2D_SHARED_BUILD -c $< -o $@ 71 72 ################################################################################ 73 # Installation 74 ################################################################################ 75 pkg: 76 sed -e 's#@PREFIX@#$(PREFIX)#g'\ 77 -e 's#@VERSION@#$(VERSION)#g'\ 78 -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ 79 -e 's#@S2D_VERSION@#$(S2D_VERSION)#g'\ 80 senc2d.pc.in > senc2d.pc 81 82 senc2d-local.pc: senc2d.pc.in 83 sed -e '1d'\ 84 -e 's#^includedir=.*#includedir=./src/#'\ 85 -e 's#^libdir=.*#libdir=./#'\ 86 -e 's#@VERSION@#$(VERSION)#g'\ 87 -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ 88 -e 's#@S2D_VERSION@#$(S2D_VERSION)#g'\ 89 senc2d.pc.in > $@ 90 91 install: build_library pkg 92 @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" $(LIBNAME) 93 @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" senc2d.pc 94 @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" \ 95 src/senc2d.h src/senc2d_sXd_helper.h src/sencX2d.h src/sencX2d_undefs.h 96 @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/star-enclosures-2d" \ 97 COPYING README.md 98 99 uninstall: 100 rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)" 101 rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/senc2d.pc" 102 rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-enclosures-2d/COPYING" 103 rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-enclosures-2d/README.md" 104 rm -f "$(DESTDIR)$(PREFIX)/include/star/senc2d.h" 105 rm -f "$(DESTDIR)$(PREFIX)/include/star/senc2d_sXd_helper.h" 106 rm -f "$(DESTDIR)$(PREFIX)/include/star/sencX2d.h" 107 rm -f "$(DESTDIR)$(PREFIX)/include/star/sencX2d_undefs.h" 108 109 ################################################################################ 110 # Miscellaneous targets 111 ################################################################################ 112 all: build_library build_tests 113 114 clean: clean_test 115 rm -f $(OBJ) $(TEST_OBJ) $(TEST_OBJ_SSP) $(LIBNAME) 116 rm -f .config .test libsenc2d.o senc2d.pc senc2d-local.pc 117 118 distclean: clean 119 rm -f $(DEP) $(TEST_DEP) $(TEST_DEP_SSP) 120 121 lint: 122 shellcheck -o all make.sh 123 124 ################################################################################ 125 # Tests 126 ################################################################################ 127 TEST_SRC =\ 128 src/test_senc2d_square_behind_square.c\ 129 src/test_senc2d_square_in_square.c\ 130 src/test_senc2d_square_on_square.c\ 131 src/test_senc2d_device.c\ 132 src/test_senc2d_enclosure.c\ 133 src/test_senc2d_inconsistant_square.c\ 134 src/test_senc2d_invalid_scenes.c\ 135 src/test_senc2d_many_enclosures.c\ 136 src/test_senc2d_many_segments.c\ 137 src/test_senc2d_multi_media.c\ 138 src/test_senc2d_scene.c\ 139 src/test_senc2d_some_enclosures.c\ 140 src/test_senc2d_some_segments.c\ 141 src/test_senc2d_unspecified_medium.c 142 TEST_OBJ = $(TEST_SRC:.c=.o) 143 TEST_DEP = $(TEST_SRC:.c=.d) 144 145 # Tests that require Star-SP 146 TEST_SRC_SSP = src/test_senc2d_sample_enclosure.c 147 TEST_OBJ_SSP = $(TEST_SRC_SSP:.c=.o) 148 TEST_DEP_SSP = $(TEST_SRC_SSP:.c=.d) 149 SSP_FOUND = $(PKG_CONFIG) --atleast-version $(SSP_VERSION) star-sp 150 151 PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG) 152 SENC2D_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags senc2d-local.pc) 153 SENC2D_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs senc2d-local.pc) 154 155 build_tests: build_library $(TEST_DEP) .test 156 @if $(SSP_FOUND); then $(MAKE) $(TEST_DEP_SSP); fi; \ 157 $(MAKE) -fMakefile -f.test \ 158 $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) \ 159 $$(if $(SSP_FOUND); then \ 160 for i in $(TEST_DEP_SSP); do echo -f"$${i}"; done; \ 161 fi) \ 162 test_bin 163 164 test: build_tests 165 @$(SHELL) make.sh run_test $(TEST_SRC) 166 @if $(SSP_FOUND); then $(SHELL) make.sh run_test $(TEST_SRC_SSP); fi 167 168 .test: Makefile 169 @{ $(SHELL) make.sh config_test $(TEST_SRC) ; \ 170 if $(SSP_FOUND); then $(SHELL) make.sh config_test $(TEST_SRC_SSP); fi } \ 171 > $@ 172 173 clean_test: 174 @$(SHELL) make.sh clean_test $(TEST_SRC) $(TEST_SRC_SSP) 175 176 $(TEST_DEP): config.mk senc2d-local.pc 177 @$(CC) $(CFLAGS_EXE) $(SENC2D_CFLAGS) $(RSYS_CFLAGS) \ 178 -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ 179 180 $(TEST_DEP_SSP): config.mk senc2d-local.pc 181 @$(CC) $(CFLAGS_EXE) $(SENC2D_CFLAGS) $(RSYS_CFLAGS) $(SSP_CFLAGS) \ 182 -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ 183 184 $(TEST_OBJ): config.mk senc2d-local.pc 185 $(CC) $(CFLAGS_EXE) $(SENC2D_CFLAGS) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@ 186 187 $(TEST_OBJ_SSP): config.mk senc2d-local.pc 188 $(CC) $(CFLAGS_EXE) $(SENC2D_CFLAGS) $(RSYS_CFLAGS) $(SSP_CFLAGS) -c $(@:.o=.c) -o $@ 189 190 test_senc2d_square_behind_square \ 191 test_senc2d_square_in_square \ 192 test_senc2d_square_on_square \ 193 test_senc2d_device \ 194 test_senc2d_inconsistant_square \ 195 test_senc2d_invalid_scenes \ 196 test_senc2d_multi_media \ 197 test_senc2d_scene \ 198 test_senc2d_some_enclosures \ 199 test_senc2d_some_segments \ 200 test_senc2d_unspecified_medium \ 201 : config.mk senc2d-local.pc $(LIBNAME) 202 $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(SENC2D_LIBS) $(RSYS_LIBS) 203 204 test_senc2d_many_enclosures test_senc2d_many_segments: config.mk senc2d-local.pc $(LIBNAME) 205 $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(SENC2D_LIBS) $(RSYS_LIBS) -lm 206 207 test_senc2d_enclosure: config.mk senc2d-local.pc $(LIBNAME) 208 $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(SENC2D_LIBS) $(RSYS_LIBS) $(S2D_LIBS) 209 210 test_senc2d_sample_enclosure: config.mk senc2d-local.pc $(LIBNAME) 211 $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(SENC2D_LIBS) $(RSYS_LIBS) $(S2D_LIBS) $(SSP_LIBS)