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
|
# This file is part of ICU4X. For terms of use, please see the file
# called LICENSE at the top level of the ICU4X source tree
# (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
# PLEASE KEEP THIS FILE IN SYNC WITH ../fixeddecimal_tiny/Makefile
.DEFAULT_GOAL := test
.PHONY: build test
FORCE:
ALL_HEADERS := $(wildcard ../../include/*.h)
ICU4X_NIGHTLY_TOOLCHAIN ?= "nightly-2022-12-26"
$(ALL_HEADERS):
GCC := gcc
CLANG := clang-15
LLD := lld-15
crate/target/debug/libcrate.a: FORCE
cd crate && cargo build --features std
crate/target/x86_64-unknown-linux-gnu/debug/libcrate.a: FORCE
rustup toolchain install ${ICU4X_NIGHTLY_TOOLCHAIN}
rustup component add rust-src --toolchain ${ICU4X_NIGHTLY_TOOLCHAIN}
cd crate && \
RUSTFLAGS="-Clinker-plugin-lto -Clinker=$(CLANG) -Ccodegen-units=1 -Clink-arg=-flto -Cpanic=abort" cargo +${ICU4X_NIGHTLY_TOOLCHAIN} build -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort --target x86_64-unknown-linux-gnu
crate/target/x86_64-unknown-linux-gnu/release/libcrate.a: FORCE
rustup toolchain install ${ICU4X_NIGHTLY_TOOLCHAIN}
rustup component add rust-src --toolchain ${ICU4X_NIGHTLY_TOOLCHAIN}
cd crate && \
RUSTFLAGS="-Clto -Cembed-bitcode -Clinker-plugin-lto -Clinker=$(CLANG) -Ccodegen-units=1 -Clink-arg=-flto -Cpanic=abort -Copt-level=s" cargo +${ICU4X_NIGHTLY_TOOLCHAIN} build -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort --target x86_64-unknown-linux-gnu --release
# Naive target: no optimizations, full std
optim0.elf: crate/target/debug/libcrate.a $(ALL_HEADERS) test.c
$(GCC) test.c crate/target/debug/libcrate.a -ldl -lpthread -lm -g -o optim0.elf
# optim.elf: gcc with maximum link-time code stripping (gc-sections and strip-all)
optim1.elf: crate/target/debug/libcrate.a $(ALL_HEADERS) test.c
$(GCC) -fdata-sections -ffunction-sections test.c crate/target/debug/libcrate.a -ldl -lpthread -lm -g -o optim1.elf -Wl,--gc-sections -Wl,--strip-all
# optim2.elf: clang single-step with gc-sections
optim2.elf: crate/target/x86_64-unknown-linux-gnu/debug/libcrate.a $(ALL_HEADERS) test.c
$(CLANG) -flto -fdata-sections -ffunction-sections test.c crate/target/x86_64-unknown-linux-gnu/debug/libcrate.a -g -o optim2.elf -Wl,--gc-sections
optim3.o: $(ALL_HEADERS) test.c
$(CLANG) -c -flto=thin -fdata-sections -ffunction-sections --target=x86_64-unknown-linux-gnu test.c -g -o optim3.o
# optim3.elf: clang two-step with lld, debug mode
optim3.elf: optim3.o crate/target/x86_64-unknown-linux-gnu/debug/libcrate.a
$(CLANG) -flto=thin -fuse-ld=$(LLD) -L . -o optim3.elf optim3.o crate/target/x86_64-unknown-linux-gnu/debug/libcrate.a -Wl,--gc-sections
optim4.o: $(ALL_HEADERS) test.c
$(CLANG) -c -flto=thin -fdata-sections -ffunction-sections --target=x86_64-unknown-linux-gnu test.c -g -o optim4.o
# optim4.elf: clang two-step with lld, release mode with debug symbols
optim4.elf: optim4.o crate/target/x86_64-unknown-linux-gnu/release/libcrate.a
$(CLANG) -flto=thin -fuse-ld=$(LLD) -L . -o optim4.elf optim4.o crate/target/x86_64-unknown-linux-gnu/release/libcrate.a -Wl,--gc-sections
optim5.o: $(ALL_HEADERS) test.c
$(CLANG) -c -flto=thin -fdata-sections -ffunction-sections --target=x86_64-unknown-linux-gnu test.c -o optim5.o
# optim5.elf: clang two-step with lld, release mode stripped of debug symbols
optim5.elf: optim5.o crate/target/x86_64-unknown-linux-gnu/release/libcrate.a
$(CLANG) -flto=thin -fuse-ld=$(LLD) -L . -o optim5.elf optim5.o crate/target/x86_64-unknown-linux-gnu/release/libcrate.a -Wl,--gc-sections -Wl,--strip-all
build: optim0.elf optim1.elf optim2.elf optim3.elf optim4.elf optim5.elf
ls -l optim*.elf
test: build
./optim0.elf
./optim1.elf
./optim2.elf
./optim2.elf
./optim4.elf
./optim5.elf
clean:
git clean -xf *
|