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