Makefile (5966B)
1 # Copyright (C) 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 = libscam.a 22 LIBNAME_SHARED = libscam.so 23 LIBNAME = $(LIBNAME_$(LIB_TYPE)) 24 25 ################################################################################ 26 # Library building 27 ################################################################################ 28 SRC =\ 29 src/scam.c\ 30 src/scam_log.c\ 31 src/scam_orthographic.c\ 32 src/scam_perspective.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 $(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -o $@ $(OBJ) $(LDFLAGS_SO) $(RSYS_LIBS) -lm 48 49 $(LIBNAME_STATIC): libscam.o 50 $(AR) -rc $@ $? 51 $(RANLIB) $@ 52 53 libscam.o: $(OBJ) 54 $(LD) -r $(OBJ) -o $@ 55 $(OBJCOPY) $(OCPFLAGS) $@ 56 57 .config: config.mk 58 @if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then\ 59 echo "rsys $(RSYS_VERSION) not found" >&2; exit 1; fi 60 @echo "config done" > $@ 61 62 .SUFFIXES: .c .d .o 63 .c.d: 64 @$(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@ 65 66 .c.o: 67 $(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -DSCAM_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 scam.pc.in > scam.pc 77 78 scam-local.pc: scam.pc.in 79 sed -e '1d'\ 80 -e 's#^includedir=.*#includedir=./src/#'\ 81 -e 's#^libdir=.*#libdir=./#'\ 82 -e 's#@VERSION@#$(VERSION)#g'\ 83 -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ 84 scam.pc.in > $@ 85 86 install: build_library pkg 87 @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" $(LIBNAME) 88 @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" scam.pc 89 @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" src/scam.h 90 @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/star-cam" COPYING README.md 91 92 uninstall: 93 rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)" 94 rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/scam.pc" 95 rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-cam/COPYING" 96 rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-cam/README.md" 97 rm -f "$(DESTDIR)$(PREFIX)/include/star/scam.h" 98 99 ################################################################################ 100 # Miscellaneous targets 101 ################################################################################ 102 all: build_library build_tests 103 104 clean: clean_test 105 rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME) 106 rm -f .config .test libscam.o scam.pc scam-local.pc 107 108 distclean: clean 109 rm -f $(DEP) $(TEST_DEP) src/test_scam_cbox.d 110 111 lint: 112 shellcheck -o all make.sh 113 114 ################################################################################ 115 # Tests 116 ################################################################################ 117 TEST_SRC =\ 118 src/test_scam_orthographic.c\ 119 src/test_scam_perspective_pinhole.c\ 120 src/test_scam_perspective_thin_lens.c 121 TEST_OBJ = $(TEST_SRC:.c=.o) 122 TEST_DEP = $(TEST_SRC:.c=.d) 123 124 S3D_FOUND = $(PKG_CONFIG) --atleast-version $(S3D_VERSION) s3d 125 126 PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG) 127 SCAM_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags scam-local.pc) 128 SCAM_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs scam-local.pc) 129 130 build_tests: build_library $(TEST_DEP) .test 131 @if $(S3D_FOUND); then $(MAKE) src/test_scam_cbox.d; fi; \ 132 $(MAKE) -fMakefile -f.test \ 133 $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) \ 134 $$($(S3D_FOUND) && echo "-fsrc/test_scam_cbox.d") \ 135 test_bin 136 137 test: build_tests 138 @$(SHELL) make.sh run_test $(TEST_SRC) 139 @if $(S3D_FOUND); then \ 140 $(SHELL) make.sh check test_scam_cbox_orthographic \ 141 test_scam_cbox orthographic pinhole; \ 142 $(SHELL) make.sh check test_scam_cbox_perspective_pinhole \ 143 test_scam_cbox perspective pinhole; \ 144 $(SHELL) make.sh check test_scam_cbox_perspective_thin_lens \ 145 test_scam_cbox perspective thin-lens; \ 146 fi 147 148 .test: Makefile 149 @{ $(SHELL) make.sh config_test $(TEST_SRC); \ 150 if $(S3D_FOUND); then \ 151 $(SHELL) make.sh config_test src/test_scam_cbox.c; fi \ 152 } > $@ 153 154 clean_test: 155 $(SHELL) make.sh clean_test $(TEST_SRC) src/test_scam_cbox.c 156 157 $(TEST_DEP): config.mk scam-local.pc 158 @$(CC) $(CFLAGS_EXE) $(SCAM_CFLAGS) $(RSYS_CFLAGS) \ 159 -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ 160 161 src/test_scam_cbox.d: config.mk scam-local.pc 162 @$(CC) $(CFLAGS_EXE) $(SCAM_CFLAGS) $(RSYS_CFLAGS) $(S3D_CFLAGS) \ 163 -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ 164 165 $(TEST_OBJ): config.mk scam-local.pc 166 $(CC) $(CFLAGS_EXE) $(SCAM_CFLAGS) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@ 167 168 src/test_scam_cbox.o: config.mk scam-local.pc 169 $(CC) $(CFLAGS_EXE) $(SCAM_CFLAGS) $(RSYS_CFLAGS) $(S3D_CFLAGS) -c $(@:.o=.c) -o $@ 170 171 test_scam_orthographic \ 172 test_scam_perspective_pinhole \ 173 test_scam_perspective_thin_lens \ 174 : config.mk scam-local.pc $(LIBNAME) 175 $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(SCAM_LIBS) $(RSYS_LIBS) -lm 176 177 test_scam_cbox: config.mk scam-local.pc $(LIBNAME) 178 $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(SCAM_LIBS) $(RSYS_LIBS) $(S3D_LIBS) -lm