Skip to content

Commit 3d14863

Browse files
committed
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 6b606dc commit 3d14863

File tree

3 files changed

+37
-59
lines changed

3 files changed

+37
-59
lines changed

examples/monolithic_build_multilevel_native/Makefile

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,37 +52,32 @@ 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
76-
else ifneq ($(findstring x86_64, $(CROSS_PREFIX)),)
77-
CFLAGS += -mavx2 -mbmi2 -mpopcnt -maes
78-
CFLAGS += -DMLK_FORCE_X86_64
79-
else
80-
endif
81-
82-
# darwin aarch64
8368
else ifeq ($(HOST_PLATFORM),Darwin-arm64)
8469
CFLAGS += -DMLK_FORCE_AARCH64
8570
endif
71+
# Cross compilation
72+
else ifneq ($(findstring aarch64_be, $(CROSS_PREFIX)),)
73+
CFLAGS += -DMLK_FORCE_AARCH64_EB
74+
else ifneq ($(findstring aarch64, $(CROSS_PREFIX)),)
75+
CFLAGS += -DMLK_FORCE_AARCH64
76+
else ifneq ($(findstring riscv64, $(CROSS_PREFIX)),)
77+
CFLAGS += -DMLK_FORCE_RISCV64
78+
else ifneq ($(findstring powerpc64le, $(CROSS_PREFIX)),)
79+
CFLAGS += -DMLK_FORCE_PPC64LE
80+
endif
8681

8782
CFLAGS := \
8883
-Wall \

examples/multilevel_build_native/Makefile

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,32 @@ 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
38-
else ifneq ($(findstring x86_64, $(CROSS_PREFIX)),)
39-
CFLAGS += -mavx2 -mbmi2 -mpopcnt -maes
40-
CFLAGS += -DMLK_FORCE_X86_64
41-
else
42-
endif
43-
44-
# darwin aarch64
4530
else ifeq ($(HOST_PLATFORM),Darwin-arm64)
4631
CFLAGS += -DMLK_FORCE_AARCH64
4732
endif
33+
# Cross compilation
34+
else ifneq ($(findstring aarch64_be, $(CROSS_PREFIX)),)
35+
CFLAGS += -DMLK_FORCE_AARCH64_EB
36+
else ifneq ($(findstring aarch64, $(CROSS_PREFIX)),)
37+
CFLAGS += -DMLK_FORCE_AARCH64
38+
else ifneq ($(findstring riscv64, $(CROSS_PREFIX)),)
39+
CFLAGS += -DMLK_FORCE_RISCV64
40+
else ifneq ($(findstring powerpc64le, $(CROSS_PREFIX)),)
41+
CFLAGS += -DMLK_FORCE_PPC64LE
42+
endif
4843

4944
CFLAGS := \
5045
-Wall \

test/mk/auto.mk

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,24 @@
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
30-
else ifneq ($(findstring x86_64, $(CROSS_PREFIX)),)
31-
CFLAGS += -DMLK_FORCE_X86_64
14+
endif
15+
# Cross compilation
16+
else ifneq ($(findstring aarch64_be, $(CROSS_PREFIX)),)
17+
CFLAGS += -DMLK_FORCE_AARCH64_EB
3218
else ifneq ($(findstring aarch64, $(CROSS_PREFIX)),)
3319
CFLAGS += -DMLK_FORCE_AARCH64
34-
else
35-
endif
20+
else ifneq ($(findstring riscv64, $(CROSS_PREFIX)),)
21+
CFLAGS += -DMLK_FORCE_RISCV64
22+
else ifneq ($(findstring powerpc64le, $(CROSS_PREFIX)),)
23+
CFLAGS += -DMLK_FORCE_PPC64LE
3624
endif

0 commit comments

Comments
 (0)