Skip to content

Commit a55399a

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 27d0a4f commit a55399a

File tree

3 files changed

+35
-67
lines changed

3 files changed

+35
-67
lines changed

examples/monolithic_build_multilevel_native/Makefile

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,37 +52,27 @@ BIN=test_binary
5252

5353
# Automatically detect system architecture and set preprocessor etc accordingly
5454
HOST_PLATFORM := $(shell uname -s)-$(shell uname -m)
55-
# linux x86_64
56-
ifeq ($(HOST_PLATFORM),Linux-x86_64)
57-
CFLAGS += -z noexecstack
58-
endif
5955

60-
ifeq ($(HOST_PLATFORM),Linux-x86_64)
56+
# Native compilation
6157
ifeq ($(CROSS_PREFIX),)
58+
ifeq ($(HOST_PLATFORM),Linux-x86_64)
6259
CFLAGS += -mavx2 -mbmi2 -mpopcnt -maes
6360
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
7361
else ifeq ($(HOST_PLATFORM),Linux-aarch64)
74-
ifeq ($(CROSS_PREFIX),)
7562
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
8363
else ifeq ($(HOST_PLATFORM),Darwin-arm64)
8464
CFLAGS += -DMLK_FORCE_AARCH64
8565
endif
66+
# Cross compilation
67+
else ifneq ($(findstring aarch64_be, $(CROSS_PREFIX)),)
68+
CFLAGS += -DMLK_FORCE_AARCH64_EB
69+
else ifneq ($(findstring aarch64, $(CROSS_PREFIX)),)
70+
CFLAGS += -DMLK_FORCE_AARCH64
71+
else ifneq ($(findstring riscv64, $(CROSS_PREFIX)),)
72+
CFLAGS += -DMLK_FORCE_RISCV64
73+
else ifneq ($(findstring powerpc64le, $(CROSS_PREFIX)),)
74+
CFLAGS += -DMLK_FORCE_PPC64LE
75+
endif
8676

8777
CFLAGS := \
8878
-Wall \

examples/multilevel_build_native/Makefile

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,27 @@ endif
1414

1515
# Automatically detect system architecture and set preprocessor etc accordingly
1616
HOST_PLATFORM := $(shell uname -s)-$(shell uname -m)
17-
# linux x86_64
18-
ifeq ($(HOST_PLATFORM),Linux-x86_64)
19-
CFLAGS += -z noexecstack
20-
endif
2117

22-
ifeq ($(HOST_PLATFORM),Linux-x86_64)
18+
# Native compilation
2319
ifeq ($(CROSS_PREFIX),)
20+
ifeq ($(HOST_PLATFORM),Linux-x86_64)
2421
CFLAGS += -mavx2 -mbmi2 -mpopcnt -maes
2522
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
3523
else ifeq ($(HOST_PLATFORM),Linux-aarch64)
36-
ifeq ($(CROSS_PREFIX),)
3724
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
4525
else ifeq ($(HOST_PLATFORM),Darwin-arm64)
4626
CFLAGS += -DMLK_FORCE_AARCH64
4727
endif
28+
# Cross compilation
29+
else ifneq ($(findstring aarch64_be, $(CROSS_PREFIX)),)
30+
CFLAGS += -DMLK_FORCE_AARCH64_EB
31+
else ifneq ($(findstring aarch64, $(CROSS_PREFIX)),)
32+
CFLAGS += -DMLK_FORCE_AARCH64
33+
else ifneq ($(findstring riscv64, $(CROSS_PREFIX)),)
34+
CFLAGS += -DMLK_FORCE_RISCV64
35+
else ifneq ($(findstring powerpc64le, $(CROSS_PREFIX)),)
36+
CFLAGS += -DMLK_FORCE_PPC64LE
37+
endif
4838

4939
CFLAGS := \
5040
-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)