Makefile (4804B)
1 # Copyright (C) 2014-2017, 2020-2023 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 = libaw.a 22 LIBNAME_SHARED = libaw.so 23 LIBNAME = $(LIBNAME_$(LIB_TYPE)) 24 25 ################################################################################ 26 # Library building 27 ################################################################################ 28 SRC = src/aw.c src/aw_obj.c src/aw_mtl.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): libaw.o 46 $(AR) -rc $@ $? 47 $(RANLIB) $@ 48 49 libaw.o: $(OBJ) 50 $(LD) -r $(OBJ) -o $@ 51 $(OBJCOPY) $(OCPFLAGS) $@ 52 53 .config: Makefile config.mk 54 @if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \ 55 echo "rsys $(RSYS_VERSION) not found"; exit 1; fi 56 @echo "config done" > .config 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) -DAW_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 aw.pc.in > aw.pc 73 74 aw-local.pc: aw.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 aw.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" aw.pc 85 @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include" src/aw.h 86 @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/aw"\ 87 COPYING README.md 88 89 uninstall: 90 rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)" 91 rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/aw.pc" 92 rm -f "$(DESTDIR)$(PREFIX)/include/aw.h" 93 rm -f "$(DESTDIR)$(PREFIX)/share/doc/aw/COPYING" 94 rm -f "$(DESTDIR)$(PREFIX)/share/doc/aw/README.md" 95 96 ################################################################################ 97 # Miscellaneous targets 98 ################################################################################ 99 all: build_library build_tests 100 101 clean: clean_test 102 rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME) 103 rm -f .config .test aw.pc aw-local.pc libaw.o 104 105 distclean: clean 106 rm -f $(DEP) $(TEST_DEP) 107 108 lint: 109 shellcheck -o all make.sh 110 111 ################################################################################ 112 # Tests 113 ################################################################################ 114 TEST_SRC =\ 115 src/test_aw.c\ 116 src/test_aw_mtl.c\ 117 src/test_aw_obj.c 118 TEST_OBJ = $(TEST_SRC:.c=.o) 119 TEST_DEP = $(TEST_SRC:.c=.d) 120 121 PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG) 122 AW_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags aw-local.pc) 123 AW_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs aw-local.pc) 124 125 build_tests: build_library $(TEST_DEP) .test 126 @$(MAKE) -fMakefile -f.test $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) test_bin 127 128 test: build_tests 129 @$(SHELL) make.sh run_test src/test_aw_mtl.c src/test_aw_obj.c 130 131 .test: Makefile make.sh 132 @$(SHELL) make.sh config_test $(TEST_SRC) > $@ 133 134 clean_test: 135 rm -f test_cbox.obj test_obj_cube.obj test_obj_plane.obj test_obj_squares.obj 136 rm -f mtl0.mtl test_mtl_common.mtl test_mtl_multi.mtl 137 $(SHELL) make.sh clean_test $(TEST_SRC) 138 139 $(TEST_DEP) $(TEST_OBJ): config.mk aw-local.pc 140 141 $(TEST_DEP): 142 @$(CC) $(CFLAGS_EXE) $(AW_CFLAGS) $(RSYS_CFLAGS) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ 143 144 $(TEST_OBJ): 145 $(CC) $(CFLAGS_EXE) $(AW_CFLAGS) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@ 146 147 test_aw \ 148 test_aw_mtl \ 149 test_aw_obj \ 150 : config.mk aw-local.pc $(LIBNAME) 151 $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(AW_LIBS) $(RSYS_LIBS)