Makefile (4966B)
1 # Copyright (C) 2022, 2023 |Méso|Star> (contact@meso-star.com) 2 # Copyright (C) 2020, 2021 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_STATIC = libsck.a 23 LIBNAME_SHARED = libsck.so 24 LIBNAME = $(LIBNAME_$(LIB_TYPE)) 25 26 ################################################################################ 27 # Library building 28 ################################################################################ 29 SRC = src/sck.c src/sck_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) -lm 45 46 $(LIBNAME_STATIC): libsck.o 47 $(AR) -rc $@ $? 48 $(RANLIB) $@ 49 50 libsck.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) -DSCK_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 sck.pc.in > sck.pc 74 75 sck-local.pc: sck.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 sck.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" sck.pc 86 @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" src/sck.h 87 @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/star-ck" COPYING README.md 88 @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/man/man5" sck.5 89 90 uninstall: 91 rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)" 92 rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/sck.pc" 93 rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-ck/COPYING" 94 rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-ck/README.md" 95 rm -f "$(DESTDIR)$(PREFIX)/include/star/sck.h" 96 rm -f "$(DESTDIR)$(PREFIX)/share/man/man5/sck.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 libsck.o sck.pc sck-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 sck.5 || [ $$? -le 1 ] 113 114 ################################################################################ 115 # Tests 116 ################################################################################ 117 TEST_SRC =\ 118 src/test_sck.c\ 119 src/test_sck_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 SCK_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags sck-local.pc) 125 SCK_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs sck-local.pc) 126 127 build_tests: build_library $(TEST_DEP) .test 128 @$(MAKE) -fMakefile -f.test $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) test_bin 129 130 test: build_tests 131 @$(SHELL) make.sh run_test $(TEST_SRC) 132 133 .test: Makefile 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.sck 139 140 $(TEST_DEP): config.mk sck-local.pc 141 @$(CC) $(CFLAGS_EXE) $(SCK_CFLAGS) $(RSYS_CFLAGS) \ 142 -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ 143 144 $(TEST_OBJ): config.mk sck-local.pc 145 $(CC) $(CFLAGS_EXE) $(SCK_CFLAGS) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@ 146 147 test_sck: config.mk sck-local.pc $(LIBNAME) 148 $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(SCK_LIBS) $(RSYS_LIBS) 149 150 test_sck_load: config.mk sck-local.pc $(LIBNAME) 151 $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(SCK_LIBS) $(RSYS_LIBS) -lm