Makefile (5372B)
1 # Copyright (C) 2015, 2016, 2020, 2021, 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 = libs3daw.a 22 LIBNAME_SHARED = libs3daw.so 23 LIBNAME = $(LIBNAME_$(LIB_TYPE)) 24 25 ################################################################################ 26 # Star-3DAW building 27 ################################################################################ 28 SRC = src/s3daw.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 $(OBJ) $(DEP): config.mk 41 42 $(LIBNAME_SHARED): $(OBJ) 43 $(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -o $@ $(OBJ) $(LDFLAGS_SO) $(DPDC_LIBS) 44 45 $(LIBNAME_STATIC): libs3daw.o 46 $(AR) -rc $@ $? 47 $(RANLIB) $@ 48 49 libs3daw.o: $(OBJ) 50 $(LD) -r $(OBJ) -o $@ 51 $(OBJCOPY) $(OCPFLAGS) $@ 52 53 .config: config.mk 54 @if ! $(PKG_CONFIG) --atleast-version $(AW_VERSION) aw; then\ 55 echo "aw $(AW_VERSION) not found" >&2; exit 1; fi 56 @if ! $(PKG_CONFIG) --atleast-version $(POLYGON_VERSION) polygon; then\ 57 echo "polygon $(POLYGON_VERSION) not found" >&2; exit 1; fi 58 @if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then\ 59 echo "rsys $(RSYS_VERSION) not found" >&2; exit 1; fi 60 @if ! $(PKG_CONFIG) --atleast-version $(S3D_VERSION) s3d; then\ 61 echo "s3d $(S3D_VERSION) not found" >&2; exit 1; fi 62 @echo "config done" > $@ 63 64 .SUFFIXES: .c .d .o 65 .c.d: 66 @$(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@ 67 68 .c.o: 69 $(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -DS3DAW_SHARED_BUILD -c $< -o $@ 70 71 ################################################################################ 72 # Installation 73 ################################################################################ 74 pkg: 75 sed -e 's#@PREFIX@#$(PREFIX)#g'\ 76 -e 's#@VERSION@#$(VERSION)#g'\ 77 -e 's#@AW_VERSION@#$(AW_VERSION)#g'\ 78 -e 's#@POLYGON_VERSION@#$(POLYGON_VERSION)#g'\ 79 -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ 80 -e 's#@S3D_VERSION@#$(S3D_VERSION)#g'\ 81 s3daw.pc.in > s3daw.pc 82 83 s3daw-local.pc: s3daw.pc.in 84 sed -e '1d'\ 85 -e 's#^includedir=.*#includedir=./src/#'\ 86 -e 's#^libdir=.*#libdir=./#'\ 87 -e 's#@VERSION@#$(VERSION)#g'\ 88 -e 's#@AW_VERSION@#$(AW_VERSION)#g'\ 89 -e 's#@POLYGON_VERSION@#$(POLYGON_VERSION)#g'\ 90 -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ 91 -e 's#@S3D_VERSION@#$(S3D_VERSION)#g'\ 92 s3daw.pc.in > $@ 93 94 install: build_library pkg 95 @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" $(LIBNAME) 96 @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" s3daw.pc 97 @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" src/s3daw.h 98 @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/star-3daw" COPYING README.md 99 100 uninstall: 101 rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)" 102 rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/s3daw.pc" 103 rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-3daw/COPYING" 104 rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-3daw/README.md" 105 rm -f "$(DESTDIR)$(PREFIX)/include/star/s3daw.h" 106 107 ################################################################################ 108 # Miscellaneous targets 109 ################################################################################ 110 all: build_library build_tests 111 112 clean: clean_test 113 rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME) 114 rm -f .config .test libs3daw.o s3daw.pc s3daw-local.pc 115 116 distclean: clean 117 rm -f $(DEP) $(TEST_DEP) 118 119 lint: 120 shellcheck -o all make.sh 121 122 ################################################################################ 123 # Test 124 ################################################################################ 125 TEST_OBJ = src/test_s3daw.o 126 TEST_DEP = src/test_s3daw.d 127 128 PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG) 129 S3DAW_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags s3daw-local.pc) 130 S3DAW_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs s3daw-local.pc) 131 132 build_tests: build_library src/test_s3daw.d 133 @$(MAKE) -fMakefile -fsrc/test_s3daw.d test_s3daw 134 135 test: build_tests 136 @printf "%s " "test_s3daw" 137 @if ./test_s3daw > /dev/null 2>&1; then \ 138 printf "\033[1;32mOK\033[m\n"; \ 139 else \ 140 printf "\033[1;31mError\033[m\n"; \ 141 fi 142 143 clean_test: 144 rm -f test_s3daw cbox.mtl cbox2.mtl cbox.obj 145 146 src/test_s3daw.d: config.mk s3daw-local.pc 147 @$(CC) $(CFLAGS_EXE) $(S3D_CFLAGS) $(S3DAW_CFLAGS) $(RSYS_CFLAGS) \ 148 -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ 149 150 src/test_s3daw.o: config.mk s3daw-local.pc 151 $(CC) $(CFLAGS_EXE) $(S3D_CFLAGS) $(S3DAW_CFLAGS) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@ 152 153 test_s3daw: src/test_s3daw.o config.mk s3daw-local.pc $(LIBNAME) 154 $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(S3DAW_LIBS) $(S3D_LIBS) $(RSYS_LIBS)