Makefile (7499B)
1 # Copyright (C) 2014-2019, 2021, 2023, 2025 Vincent Forest (vaplv@free.fr) 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 = librsimd.a 22 LIBNAME_SHARED = librsimd.so 23 LIBNAME = $(LIBNAME_$(LIB_TYPE)) 24 25 default: library 26 all: library tests 27 28 ################################################################################ 29 # Library building 30 ################################################################################ 31 SRC_SIMD128 = src/aosf44.c src/aosq.c src/math4.c 32 SRC_SIMD256 = src/math8.c $(SRC_SIMD128) 33 SRC = $(SRC_SIMD$(SIMD_WIDTH)) 34 OBJ = $(SRC:.c=.o) 35 DEP = $(SRC:.c=.d) 36 37 CFLAGS_LIB = -std=c99 $(CFLAGS_SO) $(INCS) -DRSIMD_SHARED_BUILD 38 LDFLAGS_LIB = $(LDFLAGS_SO) $(LIBS) 39 40 library: .config $(DEP) 41 @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) \ 42 $$(if [ -n "$(LIBNAME)" ]; then\ 43 echo "$(LIBNAME)";\ 44 else\ 45 echo "$(LIBNAME_SHARED)";\ 46 fi) 47 48 src/rsimd.h: src/rsimd.h.in config.mk 49 if [ "$(SIMD_WIDTH)" = "128" ]; then \ 50 sed '/#include[[:space:]]\{0,\}"avx\/avx\.h"/d' src/rsimd.h.in > $@; \ 51 fi 52 if [ "$(SIMD_WIDTH)" = "256" ]; then \ 53 cp src/rsimd.h.in $@; \ 54 fi 55 56 src/math.h: src/math.h.in config.mk 57 if [ "$(SIMD_WIDTH)" = "128" ]; then \ 58 sed '/#include[[:space:]]\{0,\}"math8\.h"/d' src/math.h.in > $@; \ 59 fi 60 if [ "$(SIMD_WIDTH)" = "256" ]; then \ 61 cp src/math.h.in $@; \ 62 fi 63 64 $(DEP) $(OBJ): config.mk src/math.h src/rsimd.h 65 66 $(LIBNAME_SHARED): $(OBJ) 67 $(CC) $(CFLAGS_LIB) -o $@ $(OBJ) $(LDFLAGS_LIB) 68 69 $(LIBNAME_STATIC): librsimd.o 70 $(AR) -rc $@ $? 71 $(RANLIB) $@ 72 73 librsimd.o: $(OBJ) 74 $(LD) -r $(OBJ) -o $@ 75 $(OBJCOPY) $(OCPFLAGS) $@ 76 77 .config: config.mk 78 $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys 79 $(PKG_CONFIG) --atleast-version $(SLEEF_VERSION) sleef 80 echo "config done" > $@ 81 82 .SUFFIXES: .c .d .o 83 .c.d: 84 @$(CC) $(CFLAGS_LIB) -MM -MT "$(@:.d=.o) $@" $< -MF $@ 85 86 .c.o: 87 $(CC) $(CFLAGS_LIB) -c $< -o $@ 88 89 ################################################################################ 90 # Installation 91 ################################################################################ 92 API_SIMD128=\ 93 src/aosf33.h\ 94 src/aosf44.h\ 95 src/aosq.h\ 96 src/math.h\ 97 src/mathX.h\ 98 src/math4.h\ 99 src/rsimd.h\ 100 src/soaXfY.h\ 101 src/soaXfY_begin.h\ 102 src/soaXfY_end.h\ 103 src/soaXf2.h\ 104 src/soaXf3.h\ 105 src/soa4f2.h\ 106 src/soa4f3.h\ 107 src/soa4f4.h\ 108 src/vXf_begin.h\ 109 src/vXf_end.h\ 110 src/sse/sse.h\ 111 src/sse/ssef.h\ 112 src/sse/ssei.h\ 113 src/sse/sse_swz.h 114 API_SIMD256=\ 115 src/math8.h\ 116 src/soa8f2.h\ 117 src/soa8f3.h\ 118 src/soa8f4.h\ 119 src/avx/avx.h\ 120 src/avx/avxf.h\ 121 src/avx/avxi.h\ 122 $(API_SIMD128) 123 API = $(API_SIMD$(SIMD_WIDTH)) 124 125 pkg: 126 sed -e 's#@PREFIX@#$(PREFIX)#g' \ 127 -e 's#@VERSION@#$(VERSION)#g' \ 128 -e 's#@SLEEF_VERSION@#$(SLEEF_VERSION)#g' \ 129 -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g' \ 130 -e 's#@CFLAGS_SIMD@#$(CFLAGS_SIMD)#g' \ 131 rsimd.pc.in > rsimd.pc 132 133 # Remove the include directive rather than setting it to "./src". to prevent 134 # the source directory from having a higher priority than the system include 135 # directories. In such a situation, the local "math.h" file could be included 136 # instead of the "math.h" header provided by the C standard library. Note that 137 # this is no longer a problem with the common pc file: the "math.h" file is 138 # installed in the "rsimd" subdirectory, which is therefore a prefix of the 139 # header file allowing it to be distinguished from the header of the standard 140 # library 141 rsimd-local.pc: rsimd.pc.in 142 sed -e '1,2d'\ 143 -e 's#^libdir=.*#libdir=./#'\ 144 -e 's#@VERSION@#$(VERSION)#g' \ 145 -e 's#@SLEEF_VERSION@#$(SLEEF_VERSION)#g' \ 146 -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g' \ 147 -e 's#@CFLAGS_SIMD@#$(CFLAGS_SIMD)#g' \ 148 -e 's#-I$${includedir}##g'\ 149 rsimd.pc.in > $@ 150 151 install: library pkg 152 install() { mode="$$1"; prefix="$$2"; shift 2; \ 153 printf "%s\n" "$$@" | while read -r i; do \ 154 f="$${i##src/}"; \ 155 p="$${prefix}/$$(dirname "$${f}")"; \ 156 mkdir -p "$${p}"; \ 157 cp "$${i}" "$${p}"; \ 158 chmod "$${mode}" "$${p}/$${f##*/}"; \ 159 done; \ 160 }; \ 161 install 755 "$(DESTDIR)$(LIBPREFIX)" $(LIBNAME); \ 162 install 644 "$(DESTDIR)$(LIBPREFIX)/pkgconfig" rsimd.pc; \ 163 install 644 "$(DESTDIR)$(INCPREFIX)/rsimd" $(API); \ 164 install 644 "$(DESTDIR)$(PREFIX)/share/doc/rsimd" COPYING README.md 165 166 uninstall: 167 rm -f $(DESTDIR)$(LIBPREFIX)/$(LIBNAME) 168 rm -f $(DESTDIR)$(LIBPREFIX)/pkgconfig/rsimd.pc 169 rm -f $(DESTDIR)$(PREFIX)/share/doc/rsimd/COPYING 170 rm -f $(DESTDIR)$(PREFIX)/share/doc/rsimd/README.md 171 rm -f $$(echo $(API) | sed 's,src\/,$(DESTDIR)$(INCPREFIX)\/rsimd\/,g') 172 173 clean: clean_test 174 rm -f $(OBJ) $(DEP) $(LIBNAME) 175 rm -f .config librsimd.o rsimd.pc rsimd-local.pc 176 rm -f src/math.h src/rsimd.h 177 178 ################################################################################ 179 # Tests 180 ################################################################################ 181 TEST_SIMD128=\ 182 src/test_aosf33.c\ 183 src/test_aosf44.c\ 184 src/test_aosq.c\ 185 src/test_math4.c\ 186 src/test_soa4f2.c\ 187 src/test_soa4f3.c\ 188 src/test_soa4f4.c\ 189 src/test_v4f.c\ 190 src/test_v4i.c 191 TEST_SIMD256=\ 192 src/test_math8.c\ 193 src/test_soa8f2.c\ 194 src/test_soa8f3.c\ 195 src/test_soa8f4.c\ 196 $(TEST_SIMD128) 197 TEST_SRC = $(TEST_SIMD$(SIMD_WIDTH)) 198 TEST_OBJ = $(TEST_SRC:.c=.o) 199 TEST_DEP = $(TEST_SRC:.c=.d) 200 TEST_TGT = $(TEST_SRC:.c=.t) 201 202 PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG) 203 INCS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rsimd-local rsys) 204 LIBS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rsimd-local rsys) 205 206 CFLAGS_TEST = -std=c89 $(CFLAGS_EXE) $(INCS_TEST) 207 LDFLAGS_TEST = $(LDFLAGS_EXE) $(LIBS_TEST) 208 209 tests: library $(TEST_DEP) $(TEST_TGT) 210 @$(MAKE) -fMakefile \ 211 $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) \ 212 $$(for i in $(TEST_TGT); do echo -f"$${i}"; done) \ 213 test_list 214 215 $(TEST_TGT): 216 @{ \ 217 exe="$$(basename "$@" ".t")"; \ 218 printf '%s: %s\n' "$${exe}" $(@:.t=.o); \ 219 printf 'test_list: %s\n' "$${exe}"; \ 220 } > $@ 221 222 $(TEST_DEP): config.mk rsimd-local.pc 223 @$(CC) $(CFLAGS_TEST) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ 224 225 $(TEST_OBJ): config.mk rsimd-local.pc 226 $(CC) $(CFLAGS_TEST) -c $(@:.o=.c) -o $@ 227 228 test_aosf33 \ 229 test_aosf44 \ 230 test_aosq \ 231 test_soa4f2 \ 232 test_soa4f3 \ 233 test_soa4f4 \ 234 test_soa8f2 \ 235 test_soa8f3 \ 236 test_soa8f4 \ 237 test_v4f \ 238 test_v4i \ 239 : config.mk rsimd-local.pc $(LIBNAME) 240 $(CC) -std=c89 $(CFLAGS_TEST) -o $@ src/$@.o $(LDFLAGS_TEST) 241 242 test_math4 \ 243 test_math8 \ 244 : config.mk rsimd-local.pc $(LIBNAME) 245 $(CC) -std=c89 $(CFLAGS_TEST) -o $@ src/$@.o $(LDFLAGS_TEST) -lm 246 247 clean_test: 248 rm -f $(TEST_DEP) $(TEST_OBJ) $(TEST_TGT) 249 for i in $(TEST_SRC); do rm -f "$$(basename "$${i}" ".c")"; done 250 251 test: tests 252 @err=0; \ 253 for i in $(TEST_SRC); do \ 254 test="$$(basename "$${i}" ".c")"; \ 255 printf '%s' "$${test}"; \ 256 if "./$${test}" > /dev/null 2>&1; then \ 257 printf '\n'; \ 258 else \ 259 printf ': error %s\n' "$$?"; \ 260 err=$$((err+1)); \ 261 fi \ 262 done; \ 263 [ "$${err}" -eq 0 ]