Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
576 lines (489 loc) · 17.7 KB
/
Copy pathMakefile
File metadata and controls
576 lines (489 loc) · 17.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
all :
ORIGINAL_VARIABLES := $(.VARIABLES)
print-variables :
$(foreach v, $(sort $(filter-out $(ORIGINAL_VARIABLES) ORIGINAL_VARIABLES,$(.VARIABLES))), $(info $(v) = $($(v))))
.PHONY : print-variables
# ====== VERSIONS ======
ADVANCECOMP_VER := 2.6
GIFSICLE_VER := 1.96
JHEAD_VER := 3.08
JPEGARCHIVE_VER := 2.2.0
JPEGOPTIM_VER := 1.5.6
LIBJPEG_VER := 9f
LIBLCMS2_VER := 2.17
LIBMOZJPEG_VER := 4.1.5
LIBPNG_VER := 1.6.58
LIBZ_VER := 1.3.2
OPTIPNG_VER := 7.9.1
OXIPNG_VER := 10.2.0
PNGCRUSH_VER := 1.8.13
PNGOUT_VER = $(if $(IS_DARWIN),$(PNGOUT_DARWIN_VER),$(PNGOUT_LINUX_VER))
PNGOUT_LINUX_VER := 20200115
PNGOUT_LINUX_STATIC_VER := $(PNGOUT_LINUX_VER)
PNGOUT_DARWIN_VER := 20230322
PNGQUANT_VER := 3.0.3
# ====== CHECKSUMS ======
include checksums.mk
# ====== CONSTANTS ======
OS := $(shell uname -s | tr A-Z a-z)
HOST_ARCH := $(shell uname -m)
ARCH := $(HOST_ARCH)
IS_DARWIN := $(findstring darwin,$(OS))
IS_LINUX := $(findstring linux,$(OS))
IS_BSD := $(findstring bsd,$(OS))
IS_FREEBSD := $(findstring freebsd,$(OS))
IS_OPENBSD := $(findstring openbsd,$(OS))
IS_LINUX_MUSL := $(findstring linux-musl,$(shell gcc -dumpmachine))
DLEXT := $(if $(IS_DARWIN),.dylib,.so)
HOST := $(ARCH:arm64=arm)-$(if $(IS_DARWIN),apple,pc)-$(OS)
LIBC_SUFFIX := $(if $(IS_DARWIN),,$(if $(IS_LINUX_MUSL),-musl,-gnu))
RUST_HOST := $(ARCH:arm64=aarch64)-$(if $(IS_DARWIN),apple-darwin,unknown-linux$(LIBC_SUFFIX))
DL_DIR := $(CURDIR)/download
BUILD_ROOT_DIR := $(CURDIR)/build
BUILD_DIR := $(BUILD_ROOT_DIR)/$(OS)-$(ARCH)$(LIBC_SUFFIX)
OUTPUT_ROOT_DIR := $(CURDIR)/vendor
OUTPUT_DIR := $(OUTPUT_ROOT_DIR)/$(OS)-$(ARCH)$(LIBC_SUFFIX)
PATCHES_DIR := $(CURDIR)/patches
export CARGO_HOME := $(DL_DIR)/cargo
ANSI_RED=\033[31m
ANSI_GREEN=\033[32m
ANSI_MAGENTA=\033[35m
ANSI_RESET=\033[0m
# ====== HELPERS ======
downcase = $(shell echo $1 | tr A-Z a-z)
tar := $(shell if command -v bsdtar >/dev/null 2>&1; then echo bsdtar; else echo tar; fi)
sha256sum := $(shell \
empty_sha256=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855; \
for cmd in sha256sum "shasum -a 256" gsha256sum sha256; do \
if echo "$$empty_sha256 /dev/null" | $$cmd -c >/dev/null 2>&1; then \
echo "$$cmd"; \
exit 0; \
fi; \
done; \
echo false)
# ====== ARCHIVES ======
ARCHIVES :=
# $1 - name of archive
# $2 - extension to use (instead of default tar.gz)
define archive
ARCHIVES += $1
$1_DIR := $(BUILD_DIR)/$(call downcase,$1)
$1_ARC := $(DL_DIR)/$(call downcase,$1)-$($1_VER).$(or $2,tar.gz)
$1_EXTRACTED := $$($1_DIR)/__$$(notdir $$($1_ARC))__
$$($1_EXTRACTED) : $$($1_ARC)
mkdir -p $(BUILD_DIR)
rm -rf $$(@D)
echo "$$($1_SHA256) $$<" | $(sha256sum) -c
mkdir $$(@D)
$(tar) -C $$(@D) --strip-components=1 -xzf $$<
touch $$(@D)/__$$(notdir $$<)__
endef
# $1 - name of archive
# $2 - url of archive with [VER] for replace with version
# $3 - extension to use
define archive-dl
$(call archive,$1,$3)
# download archive from url
$$($1_ARC) :
mkdir -p $(DL_DIR)
test -w $(DL_DIR)
tmpfile=`mktemp "$$@.XXXXXXXXXX"` && \
wget -O "$$$$tmpfile" --no-use-server-timestamps "$(subst [VER],$($1_VER),$(strip $2))" && \
chmod 644 "$$$$tmpfile" && \
mv "$$$$tmpfile" "$$@"
endef
$(eval $(call archive-dl,ADVANCECOMP, https://github.com/amadvance/advancecomp/releases/download/v[VER]/advancecomp-[VER].tar.gz))
$(eval $(call archive-dl,GIFSICLE, https://www.lcdf.org/gifsicle/gifsicle-[VER].tar.gz))
$(eval $(call archive-dl,JHEAD, https://github.com/Matthias-Wandel/jhead/archive/[VER].tar.gz))
$(eval $(call archive-dl,JPEGARCHIVE, https://github.com/danielgtaylor/jpeg-archive/archive/v[VER].tar.gz))
$(eval $(call archive-dl,JPEGOPTIM, https://github.com/tjko/jpegoptim/archive/v[VER].tar.gz))
$(eval $(call archive-dl,LIBJPEG, https://www.ijg.org/files/jpegsrc.v[VER].tar.gz))
$(eval $(call archive-dl,LIBLCMS2, https://prdownloads.sourceforge.net/lcms/lcms2-[VER].tar.gz?download))
$(eval $(call archive-dl,LIBMOZJPEG, https://github.com/mozilla/mozjpeg/archive/v[VER].tar.gz))
$(eval $(call archive-dl,LIBPNG, https://prdownloads.sourceforge.net/libpng/libpng-[VER].tar.gz?download))
$(eval $(call archive-dl,LIBZ, https://github.com/madler/zlib/archive/v[VER].tar.gz))
$(eval $(call archive-dl,OPTIPNG, https://prdownloads.sourceforge.net/optipng/optipng-[VER].tar.gz?download))
$(eval $(call archive-dl,OXIPNG, https://github.com/oxipng/oxipng/archive/v[VER].tar.gz))
$(eval $(call archive-dl,PNGCRUSH, https://prdownloads.sourceforge.net/pmt/pngcrush-[VER]-nolib.tar.gz?download))
$(eval $(call archive-dl,PNGOUT_LINUX,https://www.jonof.id.au/files/kenutils/pngout-[VER]-linux.tar.gz))
$(eval $(call archive-dl,PNGOUT_LINUX_STATIC,https://www.jonof.id.au/files/kenutils/pngout-[VER]-linux-static.tar.gz))
$(eval $(call archive-dl,PNGOUT_DARWIN,https://www.jonof.id.au/files/kenutils/pngout-[VER]-mac.zip,zip))
$(eval $(call archive-dl,PNGQUANT, https://crates.io/api/v1/crates/pngquant/[VER]/download))
download : $(foreach archive,$(ARCHIVES),$($(archive)_ARC))
.PHONY : download
download-dependencies : $(OXIPNG_EXTRACTED) $(PNGQUANT_EXTRACTED)
cd $(OXIPNG_DIR) && cargo fetch --locked
cd $(PNGQUANT_DIR) && cargo fetch --locked
.PHONY : download-dependencies
purge-dependencies :
rm -rf $(CARGO_HOME)
.PHONY : purge-dependencies
download-tidy-up :
rm -fv $(filter-out $(foreach archive,$(ARCHIVES),$($(archive)_ARC)),$(wildcard $(DL_DIR)/*.*))
.PHONY : download-tidy-up
checksum : download
@$(sha256sum) $(foreach archive,$(ARCHIVES),$($(archive)_ARC))
.PHONY : checksum
checksum-verify : download
@printf '%s %s\n' $(foreach archive,$(ARCHIVES),$($(archive)_SHA256) $($(archive)_ARC)) | $(sha256sum) -c
.PHONY : checksum-verify
checksum-update : download
@printf '%s := %s\n' $(foreach archive,$(ARCHIVES),$(archive)_SHA256 $(shell $(sha256sum) $($(archive)_ARC) | cut -d ' ' -f 1)) > checksums.mk
.PHONY : checksum-update
# ====== PRODUCTS ======
PRODUCTS :=
# $1 - product name
# $2 - archive name ($1 if empty)
# $3 - path ($1 if empty)
define target-build
$1_PATH := $(or $3,$(call downcase,$1))
$1_BASENAME := $$(notdir $$($1_PATH))
$1_DIR := $($(or $2,$1)_DIR)
$1_ARC := $($(or $2,$1)_ARC)
$1_EXTRACTED := $($(or $2,$1)_EXTRACTED)
$1_TARGET := $$($1_DIR)/$$($1_PATH)
$$($1_TARGET) : DIR := $$($1_DIR)
$$($1_TARGET) : $$($1_EXTRACTED)
endef
# $1 - product name
# $2 - archive name ($1 if empty)
# $3 - basename ($1 if empty)
# $4 - don't strip the target
define target
$(call target-build,$1,$2,$3)
PRODUCTS += $1
$1_DESTINATION := $$(OUTPUT_DIR)/$$($1_BASENAME)
# copy product to output dir
$$($1_DESTINATION) : $$($1_TARGET)
mkdir -p $(OUTPUT_DIR)
temppath=`mktemp "$(BUILD_DIR)"/tmp.XXXXXXXXXX` && \
$(if $4,cp $$< "$$$$temppath",strip $$< -Sx -o "$$$$temppath") && \
chmod 755 "$$$$temppath" && \
mv "$$$$temppath" $$@
# short name target
$(call downcase,$1) : | $$($1_DESTINATION)
endef
$(eval $(call target,ADVPNG,ADVANCECOMP))
$(eval $(call target,GIFSICLE,,src/gifsicle))
$(eval $(call target,JHEAD))
$(eval $(call target,JPEG-RECOMPRESS,JPEGARCHIVE))
$(eval $(call target,JPEGOPTIM))
$(eval $(call target,JPEGTRAN,LIBJPEG,.libs/jpegtran))
$(eval $(call target,LIBJPEG,,libjpeg$(DLEXT)))
$(eval $(call target,LIBLCMS2,,liblcms2$(DLEXT)))
$(eval $(call target-build,LIBMOZJPEG,,libjpeg.a))
$(eval $(call target,LIBPNG,,libpng$(DLEXT)))
$(eval $(call target,LIBZ,,libz$(DLEXT)))
$(eval $(call target,OPTIPNG,,src/optipng/optipng))
$(eval $(call target,OXIPNG,,target/$(RUST_HOST)/release/oxipng))
$(eval $(call target,PNGCRUSH))
ifdef IS_DARWIN
$(eval $(call target,PNGOUT,PNGOUT_DARWIN,,NOSTRIP))
else ifdef IS_LINUX_MUSL
$(eval $(call target,PNGOUT,PNGOUT_LINUX_STATIC,,NOSTRIP))
else
$(eval $(call target,PNGOUT,PNGOUT_LINUX,,NOSTRIP))
endif
$(eval $(call target,PNGQUANT,,target/$(RUST_HOST)/release/pngquant))
# ====== TARGETS ======
all : build
@$(MAKE) test
.PHONY : all
build : $(call downcase,$(PRODUCTS))
.PHONY : build
ifdef IS_DARWIN
ldd := otool -L
else
ldd := ldd
endif
ldd-version :; $(ldd) --version
.PHONY : ldd-version
define check_file_presence
@test -e $(OUTPUT_DIR)/$1 || \
{ printf "%s: $(ANSI_RED)not found$(ANSI_RESET)\n" "$1"; exit 1; }
@test -f $(OUTPUT_DIR)/$1 || \
{ printf "%s: $(ANSI_RED)not a regular file$(ANSI_RESET)\n" "$1"; exit 1; }
@test -s $(OUTPUT_DIR)/$1 || \
{ printf "%s: $(ANSI_RED)has size zero$(ANSI_RESET)\n" "$1"; exit 1; }
endef
CHECK_VERSION := $(if $(findstring $(HOST_ARCH)/$(ARCH),x86_64/arm64),,check)
define check_version
@$(OUTPUT_DIR)/$1 $2 | fgrep -q "$3" || \
{ printf "%s: $(ANSI_RED)Expected %s, got %s$(ANSI_RESET)\n" "$1" "$3" "$$($(OUTPUT_DIR)/$1 $2)"; exit 1; }
endef
define check_arch
@file -b $(OUTPUT_DIR)/$1 | fgrep -q '$(ARCH_STRING)' || \
{ printf "%s: $(ANSI_RED)Expected %s, got %s$(ANSI_RESET)\n" "$1" "$(ARCH_STRING)" "$$(file -b $(OUTPUT_DIR)/$1)"; exit 1; }
endef
define check_output
@printf "%s: $(ANSI_GREEN)%s$(ANSI_RESET) / $(ANSI_MAGENTA)%s$(ANSI_RESET)\n" "$1" "$2" "$(ARCH_STRING)"
endef
define check_shlib
@if file $(OUTPUT_DIR)/$1 | fgrep -q 'statically linked'; then \
printf '\tstatically Linked\n'; \
else \
$(ldd) $(OUTPUT_DIR)/$1 | egrep "\s+.*/.*" && \
! $(ldd) $(OUTPUT_DIR)/$1 | egrep -o $$'[^: \t]+/[^: \t]+' | egrep -v "^(@loader_path|/lib|/lib64|/usr|$(OUTPUT_DIR))/"; \
fi
endef
define check_lib
$(call check_file_presence,$1)
$(call check_arch,$1)
$(call check_output,$1,-)
$(call check_shlib,$1)
endef
define check_bin
$(call check_file_presence,$1)
$(if $(CHECK_VERSION),$(call check_version,$1,$2,$3))
$(call check_arch,$1)
$(call check_output,$1,$(if $(CHECK_VERSION),$3,[can't run $(ARCH) on $(HOST_ARCH)]))
$(call check_shlib,$1)
endef
ifdef IS_DARWIN
test : ARCH_STRING := $(ARCH)
else ifeq (amd64,$(ARCH:x86_64=amd64))
test : ARCH_STRING := x86-64
else
test : ARCH_STRING := $(ARCH)
endif
test :
$(call check_bin,advpng,--version 2>&1,$(ADVANCECOMP_VER))
$(call check_bin,gifsicle,--version,$(GIFSICLE_VER))
$(call check_bin,jhead,-V,$(JHEAD_VER))
$(call check_bin,jpeg-recompress,--version,$(JPEGARCHIVE_VER))
$(call check_bin,jpegoptim,--version,$(JPEGOPTIM_VER))
$(call check_bin,jpegtran,-v - 2>&1,$(LIBJPEG_VER))
$(call check_lib,libjpeg$(DLEXT))
$(call check_lib,liblcms2$(DLEXT))
$(call check_lib,libpng$(DLEXT))
$(call check_lib,libz$(DLEXT))
$(call check_bin,optipng,--version,$(OPTIPNG_VER))
$(call check_bin,oxipng,--version,$(OXIPNG_VER))
$(call check_bin,pngcrush,-version 2>&1,$(PNGCRUSH_VER))
$(call check_bin,pngout,2>&1 | head -n 1,$(shell perl -mTime::Piece -e 'print Time::Piece->strptime("$(PNGOUT_VER)", "%Y%m%d")->strftime("%b %e %Y")'))
$(call check_bin,pngquant,--help,$(PNGQUANT_VER))
.PHONY : test
update-versions :
script/livecheck --update
make checksum-update
make download-dependencies
.PHONY : update-versions
# ====== DOCKER ======
DOCKER_IMAGE := ghcr.io/toy/image_optim
DOCKER_TAG := $(shell date +%Y%m%d)
DOCKER_FILE := Dockerfile
docker-build : download
@docker build \
--pull \
$(foreach archive,$(ARCHIVES),--build-arg $(archive)_VER=$($(archive)_VER) --build-arg $(archive)_SHA256=$($(archive)_SHA256)) \
-t $(DOCKER_IMAGE):latest$(DOCKER_TAG_SUFFIX) \
-f $(DOCKER_FILE) \
.
@docker tag \
$(DOCKER_IMAGE):latest$(DOCKER_TAG_SUFFIX) \
$(DOCKER_IMAGE):$(DOCKER_TAG)$(DOCKER_TAG_SUFFIX)
.PHONY : docker-build
docker-test : docker-build
@docker run \
--rm \
$(DOCKER_IMAGE):latest$(DOCKER_TAG_SUFFIX) \
--info
.PHONY : docker-test
docker-push : docker-test
@docker push $(DOCKER_IMAGE):latest$(DOCKER_TAG_SUFFIX)
@docker push $(DOCKER_IMAGE):$(DOCKER_TAG)$(DOCKER_TAG_SUFFIX)
.PHONY : docker-push
# ====== CLEAN ======
clean :
rm -rf $(BUILD_DIR)
rm -rf $(OUTPUT_DIR)
.PHONY : clean
clean-all :
rm -rf $(BUILD_ROOT_DIR)
rm -rf $(OUTPUT_ROOT_DIR)
.PHONY : clean-all
clobber : clean-all
rm -rf $(DL_DIR)
.PHONY : clobber
# ====== BUILD HELPERS ======
# $1 - name of product
# $2 - list of dependency products
define depend-build
# depend this product on every specified product
$($1_EXTRACTED) : $$(filter-out $($1_EXTRACTED),$(foreach dep,$2,$$($(dep)_EXTRACTED)))
$($1_TARGET) : $(foreach dep,$2,$$($(dep)_TARGET))
# add dependent product dir to CPATH, LIBRARY_PATH and PKG_CONFIG_PATH
$($1_TARGET) : export CPATH := $(subst $(eval) ,:,$(foreach dep,$2,$$($(dep)_DIR)))
$($1_TARGET) : export LIBRARY_PATH := $$(CPATH)
$($1_TARGET) : export PKG_CONFIG_PATH := $$(CPATH)
endef
# $1 - name of product
# $2 - list of dependency products
define depend
$(call depend-build,$1,$2)
# depend output of this product on output of every specified product
$$($1_DESTINATION) : $(foreach dep,$2,$$($(dep)_DESTINATION))
endef
pkgconfig_pwd = perl -pi -e 's/(?<=dir=).*/$$ENV{PWD}/'
libtool_target_soname = perl -pi -e 's/(?<=soname_spec=)".*"/"$(@F)"/ ; s/(?<=library_names_spec=)".*"/"\\\$$libname\\\$$shared_ext"/' -- libtool
ifdef IS_DARWIN
chrpath_origin =
else ifdef IS_OPENBSD
chrpath_origin = perl -pi -e 's/XORIGIN/\$$ORIGIN/' -- $1
else
chrpath_origin = chrpath -r '$$ORIGIN' $1
endif
ifdef IS_LINUX
XORIGIN := -Wl,-rpath,XORIGIN
else ifdef IS_BSD
XORIGIN := -Wl,-rpath,XORIGIN -Wl,-z,origin
else
XORIGIN :=
endif
# ====== ENV ======
ifdef IS_DARWIN
export CC := clang
export CXX := clang++
else
export CC := gcc
export CXX := g++
endif
GCC_FLAGS := -O3
export CFLAGS = $(GCC_FLAGS)
export CXXFLAGS = $(GCC_FLAGS)
export CPPFLAGS = $(GCC_FLAGS)
export LDFLAGS = $(GCC_FLAGS)
ifdef IS_DARWIN
export MACOSX_DEPLOYMENT_TARGET := 10.12
GCC_FLAGS += -arch $(ARCH)
CXXFLAGS += -stdlib=libc++
export CMAKE_OSX_ARCHITECTURES := $(ARCH)
endif
ifdef IS_BSD
autotool_version = $(shell printf '%s\n' /usr/local/bin/$1-* | egrep -o '[0-9][^-]+$$' | tail -n 1)
export AUTOCONF_VERSION := $(call autotool_version,autoconf)
export AUTOMAKE_VERSION := $(call autotool_version,automake)
endif
# ====== BUILD TARGETS ======
## advpng
$(eval $(call depend,ADVPNG,LIBZ))
$(ADVPNG_TARGET) :
cd $(DIR) && ./configure --host "$(HOST)" LDFLAGS="$(XORIGIN)"
cd $(DIR) && $(MAKE) advpng
$(call chrpath_origin,$@)
## gifsicle
$(GIFSICLE_TARGET) :
cd $(DIR) && ./configure --host "$(HOST)"
cd $(DIR) && $(MAKE) gifsicle
## jhead
$(JHEAD_TARGET) :
cd $(DIR) && $(MAKE) jhead CC="$(CC) $(CFLAGS)"
## jpeg-recompress
$(eval $(call depend-build,JPEG-RECOMPRESS,LIBMOZJPEG))
$(JPEG-RECOMPRESS_TARGET) :
cd $(DIR) && $(MAKE) jpeg-recompress CC="$(CC) $(CFLAGS) -fcommon" LIBJPEG=$(LIBMOZJPEG_TARGET) \
MAKE=$(MAKE) # fix for bsd in jpeg-archive-2.1.1
## jpegoptim
$(eval $(call depend,JPEGOPTIM,LIBJPEG))
$(JPEGOPTIM_TARGET) :
cd $(DIR) && ./configure --host "$(HOST)" LDFLAGS="$(XORIGIN)"
cd $(DIR) && $(MAKE) jpegoptim
$(call chrpath_origin,$@)
## jpegtran
$(eval $(call depend,JPEGTRAN,LIBJPEG))
$(JPEGTRAN_TARGET) :
cd $(DIR) && $(MAKE) jpegtran LDFLAGS="$(XORIGIN)"
$(call chrpath_origin,$(JPEGTRAN_TARGET))
## libjpeg
$(LIBJPEG_TARGET) :
cd $(DIR) && ./configure --host "$(HOST)" CC="$(CC) $(CFLAGS)"
cd $(DIR) && $(libtool_target_soname)
ifdef IS_DARWIN
cd $(DIR) && $(MAKE) libjpeg.la LDFLAGS="-Wl,-install_name,@loader_path/$(@F)"
else
cd $(DIR) && $(MAKE) libjpeg.la
endif
cd $(DIR) && ln -sf .libs/libjpeg$(DLEXT) .
## liblcms2
$(LIBLCMS2_TARGET) :
cd $(DIR) && ./configure --host "$(HOST)"
cd $(DIR) && $(libtool_target_soname)
ifdef IS_DARWIN
cd $(DIR)/src && make liblcms2.la LDFLAGS="-Wl,-install_name,@loader_path/$(@F)"
else
cd $(DIR)/src && make liblcms2.la LDFLAGS="$(XORIGIN)"
endif
cd $(DIR) && ln -sf include/lcms2.h .
cd $(DIR) && ln -sf src/.libs/liblcms2$(DLEXT) .
## libmozjpeg
$(LIBMOZJPEG_TARGET) :
cd $(DIR) && cmake -DPNG_SUPPORTED=0 -DCMAKE_POLICY_VERSION_MINIMUM=3.5 .
cd $(DIR) && $(MAKE) jpeg-static
## libpng
$(eval $(call depend,LIBPNG,LIBZ))
$(LIBPNG_TARGET) :
cd $(DIR) && ./configure --host "$(HOST)" CC="$(CC) $(CFLAGS)"
cd $(DIR) && $(pkgconfig_pwd) -- *.pc
cd $(DIR) && perl -pi -e 's/(?<=lpng)\d+//g' -- *.pc # %MAJOR%%MINOR% suffix
cd $(DIR) && $(libtool_target_soname)
ifdef IS_DARWIN
cd $(DIR) && $(MAKE) libpng16.la LDFLAGS="-Wl,-install_name,@loader_path/$(@F)"
else
cd $(DIR) && $(MAKE) libpng16.la LDFLAGS="$(XORIGIN)"
endif
cd $(DIR) && ln -sf .libs/libpng16$(DLEXT) libpng$(DLEXT)
$(call chrpath_origin,$@)
## libz
ifdef IS_DARWIN
$(LIBZ_TARGET) : export LDSHARED = $(CC) -dynamiclib -install_name @loader_path/$(@F) -compatibility_version 1 -current_version $(LIBZ_VER)
else
$(LIBZ_TARGET) : export LDSHARED = $(CC) -shared -Wl,-soname,$(@F),--version-script,zlib.map
endif
$(LIBZ_TARGET) :
cd $(DIR) && ./configure
cd $(DIR) && $(pkgconfig_pwd) -- *.pc
cd $(DIR) && $(MAKE) placebo
## optipng
$(eval $(call depend,OPTIPNG,LIBPNG LIBZ))
$(OPTIPNG_TARGET) :
cd $(DIR) && ./configure -with-system-libs
cd $(DIR) && $(MAKE) all LDFLAGS="$(XORIGIN) $(LDFLAGS)"
$(call chrpath_origin,$@)
## oxipng
ifdef IS_LINUX_MUSL
$(PNGQUANT_TARGET) : export RUSTFLAGS = -C target-feature=-crt-static
endif
$(OXIPNG_TARGET) :
cd $(DIR) && cargo build --release --frozen --offline --target=$(RUST_HOST)
## pngcrush
$(eval $(call depend,PNGCRUSH,LIBPNG LIBZ))
$(PNGCRUSH_TARGET) :
cd $(DIR) && rm -f png.h pngconf.h
cd $(DIR) && patch < $(PATCHES_DIR)/pngcrush.patch
cd $(DIR) && $(MAKE) pngcrush \
CC="$(CC)" \
LD="$(CC)" \
LIBS="-lpng -lz -lm" \
CFLAGS="$(CFLAGS)" \
CPPFLAGS="$(CPPFLAGS)" \
LDFLAGS="$(XORIGIN) $(LDFLAGS)"
$(call chrpath_origin,$@)
## pngout
$(PNGOUT_TARGET) :
ifdef IS_LINUX
cd $(DIR) && ln -sf $(ARCH:x86_64=amd64)/pngout$(if $(IS_LINUX_MUSL),-static) pngout
endif
cd $(DIR) && touch pngout
## pngquant
$(eval $(call depend,PNGQUANT,LIBLCMS2 LIBPNG LIBZ))
$(PNGQUANT_TARGET) : export RUSTFLAGS = -C link-arg=$(XORIGIN) $(if $(IS_LINUX_MUSL),-C target-feature=-crt-static)
$(PNGQUANT_TARGET) :
printf "%s\n" \
$(foreach LIB,PNG Z LCMS2, \
"[target.$(RUST_HOST).$(call downcase,$(LIB))]" \
"rustc-link-lib = ['$(call downcase,$(LIB))']" \
"rustc-link-search = ['native=$(LIB$(LIB)_DIR)']" \
"include = '$(LIB$(LIB)_DIR)'" \
) > $(DIR)/override.toml
cd $(DIR) && cargo build --release --frozen --offline --target=$(RUST_HOST) --config override.toml
$(call chrpath_origin,$@)