Makefile.rcv (4786B)
1 # Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) 2 # Copyright (C) 2016-2018 CNRS 3 # 4 # This program is free software: you can redistribute it and/or modify 5 # it under the terms of the GNU General Public License as published by 6 # the Free Software Foundation, either version 3 of the License, or 7 # (at your option) any later version. 8 # 9 # This program is distributed in the hope that it will be useful, 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # GNU General Public License for more details. 13 # 14 # You should have received a copy of the GNU General Public License 15 # along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17 .POSIX: 18 .SUFFIXES: # Clean up default inference rules 19 20 include config.mk 21 22 LIBNAME = src/libsrcv.a 23 24 default: library 25 all: library tests 26 27 ################################################################################ 28 # Build the library 29 ################################################################################ 30 SRC =\ 31 src/receivers/srcvl.c 32 OBJ = $(SRC:.c=.o) 33 DEP = $(SRC:.c=.d) 34 35 # Headers to configure 36 HDR= 37 38 CFLAGS_LIB = $(CFLAGS_SO) $(INCS) -DSRCVL_SHARED_BUILD 39 LDFLAGS_LIB = $(LDFLAGS_SO) $(LIBS) 40 41 $(DEP) $(OBJ): src/.config_rcv 42 43 library: $(DEP) 44 @$(MAKE) -fMakefile.rcv $$(for i in $(DEP); do echo -f $${i}; done) \ 45 $(LIBNAME) 46 47 $(LIBNAME): src/libsrcv.o 48 $(AR) -rc $@ $? 49 $(RANLIB) $@ 50 51 src/libsrcv.o: $(OBJ) $(DEP) 52 $(LD) -r $(OBJ) -o $@ 53 $(OBJCOPY) $(OCPFLAGS) $@ 54 55 $(DEP): $(HDR) 56 @$(CC) $(CFLAGS_LIB) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ 57 58 $(OBJ): $(HDR) 59 $(CC) $(CFLAGS_LIB) -c $(@:.o=.c) -o $@ 60 61 ################################################################################ 62 # Installation 63 ################################################################################ 64 src/.config_rcv: config.mk 65 $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys 66 $(PKG_CONFIG) --atleast-version $(YAML_VERSION) yaml-0.1 67 @echo "config done" > $@ 68 69 install: 70 71 uninstall: 72 73 clean: clean_test 74 rm -f $(DEP) $(OBJ) $(LIBNAME) 75 rm -f src/.config_rcv src/libsrcv.o 76 77 lint: 78 79 ################################################################################ 80 # Tests 81 ################################################################################ 82 TEST_SRC =\ 83 src/receivers/test_srcvl.c\ 84 src/receivers/test_srcvl2.c 85 TEST_OBJ =\ 86 $(TEST_SRC:.c=.o) 87 TEST_DEP =\ 88 $(TEST_SRC:.c=.d) 89 TEST_TGT =\ 90 $(TEST_SRC:.c=.t) 91 92 src/srcv-local.pc: srcv.pc.in src/.config_srcv_test 93 sed -e '1d'\ 94 -e 's#^includedir=.*#includedir=./src#'\ 95 -e 's#^libdir=.*#libdir=./src#'\ 96 -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ 97 -e 's#@YAML_VERSION@#$(YAML_VERSION)#g'\ 98 srcv.pc.in > $@ 99 100 # Regular cflags 101 PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./src:$${PKG_CONFIG_PATH}" $(PKG_CONFIG) 102 INCS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rsys srcv-local) 103 LIBS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rsys srcv-local)\ 104 -lm 105 106 tests: library src/srcv-local.pc $(TEST_DEP) $(TEST_TGT) 107 @$(MAKE) -fMakefile.rcv \ 108 $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) \ 109 $$(for i in $(TEST_TGT); do echo -f"$${i}"; done) \ 110 test_list 111 112 $(TEST_TGT): 113 @{ \ 114 exe="$$(basename "$@" ".t")"; \ 115 printf '%s: %s\n' "$${exe}" $(@:.t=.o); \ 116 printf 'test_list: %s\n' "$${exe}"; \ 117 } > $@ 118 119 src/.config_srcv_test: config.mk 120 @echo "config done" > $@ 121 122 clean_test: 123 rm -f $(TEST_DEP) $(TEST_OBJ) $(TEST_TGT) 124 for i in $(TEST_SRC); do rm -f "$$(basename "$${i}" ".c")"; done 125 rm -f src/.config_srcv_test src/srcv-local.pc 126 127 test: tests 128 @err=0; \ 129 check() { name="$$1"; prog="$$2"; shift 2; \ 130 printf '%s' "$${name}"; \ 131 if PATH=./:"$${PATH}" "$${prog}" $$@ > /dev/null 2>&1; then \ 132 printf '\n'; \ 133 else \ 134 printf ': error %s\n' "$$?"; \ 135 err=$$((err+1)); \ 136 fi; \ 137 }; \ 138 \ 139 for i in $(TEST_SRC); do \ 140 test="$$(basename "$${i}" ".c")"; \ 141 if [ "$${test}" != "test_srcvl" ]; then \ 142 check "$${test}" "$${test}"; \ 143 else \ 144 check test_srcvl_ok \ 145 test_srcvl src/receivers/yaml/test_ok.yaml; \ 146 check test_srcvl_ko \ 147 test_srcvl -e src/receivers/yaml/test_ko.yaml; \ 148 fi \ 149 done; \ 150 \ 151 [ "$${err}" -eq 0 ] 152 153 ################################################################################ 154 # Regular tests 155 ################################################################################ 156 CFLAGS_TEST = $(CFLAGS_EXE) $(INCS_TEST) 157 LDFLAGS_TEST = $(LDFLAGS_EXE) $(LIBS_TEST) 158 159 $(TEST_DEP) : src/.config_srcv_test src/srcv-local.pc 160 @$(CC) $(CFLAGS_TEST) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ 161 162 $(TEST_OBJ) : src/.config_srcv_test src/srcv-local.pc 163 $(CC) $(CFLAGS_TEST) -c $(@:.o=.c) -o $@ 164 165 test_srcvl\ 166 test_srcvl2\ 167 : src/.config_srcv_test src/srcv-local.pc $(LIBNAME) 168 $(CC) $(CFLAGS_TEST) -o $@ src/receivers/$@.o $(LDFLAGS_TEST)