Makefile (5615B)
1 # Copyright (C) 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 = libscmap.a 22 LIBNAME_SHARED = libscmap.so 23 LIBNAME = $(LIBNAME_$(LIB_TYPE)) 24 25 ################################################################################ 26 # Library building 27 ################################################################################ 28 SRC = src/scmap.c src/scmap_palettes.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): libscmap.o 46 $(AR) -rc $@ $? 47 $(RANLIB) $@ 48 49 libscmap.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) -DSCMAP_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 scmap.pc.in > scmap.pc 73 74 scmap-local.pc: scmap.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 scmap.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" scmap.pc 85 @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" src/scmap.h 86 @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/star-cmap" COPYING README.md 87 88 uninstall: 89 rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)" 90 rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/scmap.pc" 91 rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-cmap/COPYING" 92 rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-cmap/README.md" 93 rm -f "$(DESTDIR)$(PREFIX)/include/star/scmap.h" 94 95 ################################################################################ 96 # Miscellaneous targets 97 ################################################################################ 98 all: build_library build_tests 99 100 clean: clean_test 101 rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME) 102 rm -f .config .test libscmap.o scmap.pc scmap-local.pc 103 104 distclean: clean 105 rm -f $(DEP) $(TEST_DEP) 106 107 lint: 108 shellcheck -o all make.sh 109 110 ################################################################################ 111 # Tests 112 ################################################################################ 113 TEST_SRC =\ 114 src/test_scmap.c\ 115 src/test_scmap_fetch_color.c\ 116 src/test_scmap_palettes.c 117 TEST_OBJ = $(TEST_SRC:.c=.o) 118 TEST_DEP = $(TEST_SRC:.c=.d) 119 PALETTES=\ 120 accent\ 121 blues\ 122 brbg\ 123 bugn\ 124 bupu\ 125 chromajs\ 126 dark2\ 127 gnbu\ 128 gnpu\ 129 greens\ 130 greys\ 131 inferno\ 132 jet\ 133 magma\ 134 moreland\ 135 oranges\ 136 orrd\ 137 paired\ 138 parula\ 139 pastel1\ 140 pastel2\ 141 piyg\ 142 plasma\ 143 prgn\ 144 pubu\ 145 pubugn\ 146 puor\ 147 purd\ 148 purples\ 149 rdbu\ 150 rdgy\ 151 rdpu\ 152 rdylbu\ 153 rdylgn\ 154 reds\ 155 sand\ 156 set1\ 157 set2\ 158 set3\ 159 spectral\ 160 viridis\ 161 whgnbu\ 162 whylrd\ 163 ylgn\ 164 ylgnbu\ 165 ylorbr\ 166 ylorrd\ 167 ylrd 168 169 PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG) 170 SCMAP_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags scmap-local.pc) 171 SCMAP_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs scmap-local.pc) 172 173 build_tests: build_library $(TEST_DEP) .test 174 @$(MAKE) -fMakefile -f.test $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) test_bin 175 176 test: build_tests 177 @$(SHELL) make.sh check test_scmap test_scmap 178 @$(SHELL) make.sh check test_scmap_fetch_color test_scmap_fetch_color 179 @printf "%s\n" $(PALETTES) | while read -r i; do\ 180 $(SHELL) make.sh check test_scmap_palettes_"$${i}" test_scmap_palettes "$${i}"; \ 181 done 182 183 .test: Makefile 184 @$(SHELL) make.sh config_test $(TEST_SRC) > $@ 185 186 clean_test: 187 $(SHELL) make.sh clean_test $(TEST_SRC) 188 echo "$(PALETTES)" | sed 's/[[:space:]]/\n/g' | \ 189 while read -r i; do rm -f "$${i}.ppm"; done 190 191 $(TEST_DEP): config.mk scmap-local.pc 192 @$(CC) $(CFLAGS_EXE) $(SCMAP_CFLAGS) $(RSYS_CFLAGS) \ 193 -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ 194 195 $(TEST_OBJ): config.mk scmap-local.pc 196 $(CC) $(CFLAGS_EXE) $(SCMAP_CFLAGS) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@ 197 198 test_scmap test_scmap_palettes: config.mk scmap-local.pc $(LIBNAME) 199 $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(SCMAP_LIBS) $(RSYS_LIBS) 200 201 test_scmap_fetch_color: config.mk scmap-local.pc $(LIBNAME) 202 $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(SCMAP_LIBS) $(RSYS_LIBS) -lm