Skip to content

Commit 5c3414f

Browse files
hanno-beckermkannwischer
authored andcommitted
Makefiles: Simplify auto-derivation of compiler flags
This commit simplifies the logic around automatically setting architecture-specific compiler flags from ``` if (arch == A) { if (!cross) ... if (cross == X) ... elif (cross == Y) ... } elif (arch == B) { if (!cross) ... if (cross == X) ... elif (cross == Y) ... } ``` to ``` if !cross { if (arch == A) ... elif (arch == B) ... ... } else { if (cross == X) ... elif (cross == Y) ... } ``` It also adds further architecture flags for RV64 and PPC64LE. Signed-off-by: Hanno Becker <[email protected]>
1 parent bac5ada commit 5c3414f

File tree

3 files changed

+40
-53
lines changed

3 files changed

+40
-53
lines changed

examples/monolithic_build_multilevel_native/Makefile

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,36 +52,34 @@ BIN=test_binary
5252

5353
# Automatically detect system architecture and set preprocessor etc accordingly
5454
HOST_PLATFORM := $(shell uname -s)-$(shell uname -m)
55+
5556
# linux x86_64
5657
ifeq ($(HOST_PLATFORM),Linux-x86_64)
5758
CFLAGS += -z noexecstack
5859
endif
5960

60-
ifeq ($(HOST_PLATFORM),Linux-x86_64)
61+
# Native compilation
6162
ifeq ($(CROSS_PREFIX),)
63+
ifeq ($(HOST_PLATFORM),Linux-x86_64)
6264
CFLAGS += -mavx2 -mbmi2 -mpopcnt -maes
6365
CFLAGS += -DMLK_FORCE_X86_64
64-
else ifneq ($(findstring aarch64_be, $(CROSS_PREFIX)),)
65-
CFLAGS += -DMLK_FORCE_AARCH64_EB
66-
else ifneq ($(findstring aarch64, $(CROSS_PREFIX)),)
67-
CFLAGS += -DMLK_FORCE_AARCH64
68-
else
69-
70-
endif
71-
72-
# linux aarch64
7366
else ifeq ($(HOST_PLATFORM),Linux-aarch64)
74-
ifeq ($(CROSS_PREFIX),)
7567
CFLAGS += -DMLK_FORCE_AARCH64
68+
else ifeq ($(HOST_PLATFORM),Darwin-arm64)
69+
CFLAGS += -DMLK_FORCE_AARCH64
70+
endif
71+
# Cross compilation
7672
else ifneq ($(findstring x86_64, $(CROSS_PREFIX)),)
7773
CFLAGS += -mavx2 -mbmi2 -mpopcnt -maes
7874
CFLAGS += -DMLK_FORCE_X86_64
79-
else
80-
endif
81-
82-
# darwin aarch64
83-
else ifeq ($(HOST_PLATFORM),Darwin-arm64)
75+
else ifneq ($(findstring aarch64_be, $(CROSS_PREFIX)),)
76+
CFLAGS += -DMLK_FORCE_AARCH64_EB
77+
else ifneq ($(findstring aarch64, $(CROSS_PREFIX)),)
8478
CFLAGS += -DMLK_FORCE_AARCH64
79+
else ifneq ($(findstring riscv64, $(CROSS_PREFIX)),)
80+
CFLAGS += -DMLK_FORCE_RISCV64
81+
else ifneq ($(findstring powerpc64le, $(CROSS_PREFIX)),)
82+
CFLAGS += -DMLK_FORCE_PPC64LE
8583
endif
8684

8785
CFLAGS := \

examples/multilevel_build_native/Makefile

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,34 @@ endif
1414

1515
# Automatically detect system architecture and set preprocessor etc accordingly
1616
HOST_PLATFORM := $(shell uname -s)-$(shell uname -m)
17+
1718
# linux x86_64
1819
ifeq ($(HOST_PLATFORM),Linux-x86_64)
1920
CFLAGS += -z noexecstack
2021
endif
2122

22-
ifeq ($(HOST_PLATFORM),Linux-x86_64)
23+
# Native compilation
2324
ifeq ($(CROSS_PREFIX),)
25+
ifeq ($(HOST_PLATFORM),Linux-x86_64)
2426
CFLAGS += -mavx2 -mbmi2 -mpopcnt -maes
2527
CFLAGS += -DMLK_FORCE_X86_64
26-
else ifneq ($(findstring aarch64_be, $(CROSS_PREFIX)),)
27-
CFLAGS += -DMLK_FORCE_AARCH64_EB
28-
else ifneq ($(findstring aarch64, $(CROSS_PREFIX)),)
29-
CFLAGS += -DMLK_FORCE_AARCH64
30-
else
31-
32-
endif
33-
34-
# linux aarch64
3528
else ifeq ($(HOST_PLATFORM),Linux-aarch64)
36-
ifeq ($(CROSS_PREFIX),)
3729
CFLAGS += -DMLK_FORCE_AARCH64
30+
else ifeq ($(HOST_PLATFORM),Darwin-arm64)
31+
CFLAGS += -DMLK_FORCE_AARCH64
32+
endif
33+
# Cross compilation
3834
else ifneq ($(findstring x86_64, $(CROSS_PREFIX)),)
3935
CFLAGS += -mavx2 -mbmi2 -mpopcnt -maes
4036
CFLAGS += -DMLK_FORCE_X86_64
41-
else
42-
endif
43-
44-
# darwin aarch64
45-
else ifeq ($(HOST_PLATFORM),Darwin-arm64)
37+
else ifneq ($(findstring aarch64_be, $(CROSS_PREFIX)),)
38+
CFLAGS += -DMLK_FORCE_AARCH64_EB
39+
else ifneq ($(findstring aarch64, $(CROSS_PREFIX)),)
4640
CFLAGS += -DMLK_FORCE_AARCH64
41+
else ifneq ($(findstring riscv64, $(CROSS_PREFIX)),)
42+
CFLAGS += -DMLK_FORCE_RISCV64
43+
else ifneq ($(findstring powerpc64le, $(CROSS_PREFIX)),)
44+
CFLAGS += -DMLK_FORCE_PPC64LE
4745
endif
4846

4947
CFLAGS := \

test/mk/auto.mk

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,27 @@
11
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
22
#
33
# Automatically detect system architecture and set preprocessor etc accordingly
4-
ifeq ($(HOST_PLATFORM),Linux-x86_64)
4+
5+
# Native compilation
56
ifeq ($(CROSS_PREFIX),)
7+
ifeq ($(HOST_PLATFORM),Linux-x86_64)
68
CFLAGS += -mavx2 -mbmi2 -mpopcnt -maes
79
CFLAGS += -DMLK_FORCE_X86_64
8-
else ifneq ($(findstring aarch64_be, $(CROSS_PREFIX)),)
9-
CFLAGS += -DMLK_FORCE_AARCH64_EB
10-
else ifneq ($(findstring aarch64, $(CROSS_PREFIX)),)
11-
CFLAGS += -DMLK_FORCE_AARCH64
12-
else
13-
14-
endif
15-
16-
# linux aarch64
1710
else ifeq ($(HOST_PLATFORM),Linux-aarch64)
18-
ifeq ($(CROSS_PREFIX),)
1911
CFLAGS += -DMLK_FORCE_AARCH64
20-
else ifneq ($(findstring x86_64, $(CROSS_PREFIX)),)
21-
CFLAGS += -mavx2 -mbmi2 -mpopcnt -maes
22-
CFLAGS += -DMLK_FORCE_X86_64
23-
else
24-
endif
25-
26-
# darwin aarch64
2712
else ifeq ($(HOST_PLATFORM),Darwin-arm64)
28-
ifeq ($(CROSS_PREFIX),)
2913
CFLAGS += -DMLK_FORCE_AARCH64
14+
endif
15+
# Cross compilation
3016
else ifneq ($(findstring x86_64, $(CROSS_PREFIX)),)
17+
CFLAGS += -mavx2 -mbmi2 -mpopcnt -maes
3118
CFLAGS += -DMLK_FORCE_X86_64
19+
else ifneq ($(findstring aarch64_be, $(CROSS_PREFIX)),)
20+
CFLAGS += -DMLK_FORCE_AARCH64_EB
3221
else ifneq ($(findstring aarch64, $(CROSS_PREFIX)),)
3322
CFLAGS += -DMLK_FORCE_AARCH64
34-
else
35-
endif
23+
else ifneq ($(findstring riscv64, $(CROSS_PREFIX)),)
24+
CFLAGS += -DMLK_FORCE_RISCV64
25+
else ifneq ($(findstring powerpc64le, $(CROSS_PREFIX)),)
26+
CFLAGS += -DMLK_FORCE_PPC64LE
3627
endif

0 commit comments

Comments
 (0)