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