如何在基于平台的Makefile中制作if语句?
How to make if statement in Makefile based on platform?
我在使用加密钱包时遇到问题,这可能无关紧要。问题是 makefile 包含用于 x86 架构的文件,而我有 AARCH64 文件,但似乎找不到解决方法,如何处理...
所以我想根据平台(在本例中为 x86)进行更改:
crypto/randomx/jit_compiler_x86.cpp
crypto/randomx/jit_compiler_x86.hpp
crypto/randomx/jit_compiler_x86_static.asm
crypto/randomx/jit_compiler_x86_static.hpp
crypto/randomx/jit_compiler_x86_static.S
对此(AARCH64 时):
crypto/randomx/jit_compiler_a64.cpp
crypto/randomx/jit_compiler_a64.hpp
crypto/randomx/jit_compiler_a64_static.hpp
crypto/randomx/jit_compiler_a64_static.S
那么有没有什么办法,如何以更优雅的方式做到这一点,然后将这些 cpp/hpp/s 文件合并在一起*,就在 Makefile 中?
*好吧,我认为这行不通,因为 x86 实现还有一个文件。
另一个问题是它以 *.PO 或 *PLO 文件的形式创建依赖文件,它们...它们来自哪里,它们是由编译器即时创建的。
Makefile 的末尾是这样写的:
crypto/randomx/libbitcoinconsensus_la-jit_compiler_x86.lo: \
crypto/randomx/$(am__dirstamp) \
crypto/randomx/$(DEPDIR)/$(am__dirstamp)
这可能会导致一些问题,因为它里面有 x86 并且它是一些临时的 *.lo 文件,我也不知道这些文件在编译过程中的什么地方被引入。
那么有什么办法,怎么解决呢?如果需要单独的 make 文件,那不是问题,只要我知道如何(通过代码)区分它们。我正在编译 linux,所以我想在 configure.ac 中有一种方法可以做到这一点,或者在 autogen.sh 或类似的东西中,它们用于设置环境。
提前感谢您的帮助。
你给出了文件名列表,但没有说明你如何使用它们,所以我假设你正在将它们分配给变量。
我们可以从一个简单的开始 conditional:
ifeq ($(PLATFORM),x86_64)
do something
endif
ifeq ($(PLATFORM),aarch64)
do something else
endif
粗略地说,我们可以这样做:
ifeq ($(PLATFORM),x86_64)
SOURCE := crypto/randomx/jit_compiler_x86.cpp
HEADER := crypto/randomx/jit_compiler_x86.hpp
ASM := crypto/randomx/jit_compiler_x86_static.asm
STATIC_HEADER := crypto/randomx/jit_compiler_x86_static.hpp
STATIC_SOURCE := crypto/randomx/jit_compiler_x86_static.S
endif
ifeq ($(PLATFORM),x86_64)
...likewise for a64...
endif
这可行,但会非常多余。我们可以改进它:
BASE := crypto/randomx/jit_compiler
ifeq ($(PLATFORM),x86_64)
BASE := $(BASE)_x86
endif
ifeq ($(PLATFORM),aarch64)
BASE := $(BASE)_a64
endif
SOURCE := $(BASE).cpp
HEADER := $(BASE).hpp
ASM := $(BASE)_static.asm
STATIC_HEADER := $(BASE)_static.hpp
STATIC_SOURCE := $(BASE)_static.S
我在使用加密钱包时遇到问题,这可能无关紧要。问题是 makefile 包含用于 x86 架构的文件,而我有 AARCH64 文件,但似乎找不到解决方法,如何处理...
所以我想根据平台(在本例中为 x86)进行更改:
crypto/randomx/jit_compiler_x86.cpp
crypto/randomx/jit_compiler_x86.hpp
crypto/randomx/jit_compiler_x86_static.asm
crypto/randomx/jit_compiler_x86_static.hpp
crypto/randomx/jit_compiler_x86_static.S
对此(AARCH64 时):
crypto/randomx/jit_compiler_a64.cpp
crypto/randomx/jit_compiler_a64.hpp
crypto/randomx/jit_compiler_a64_static.hpp
crypto/randomx/jit_compiler_a64_static.S
那么有没有什么办法,如何以更优雅的方式做到这一点,然后将这些 cpp/hpp/s 文件合并在一起*,就在 Makefile 中?
*好吧,我认为这行不通,因为 x86 实现还有一个文件。
另一个问题是它以 *.PO 或 *PLO 文件的形式创建依赖文件,它们...它们来自哪里,它们是由编译器即时创建的。
Makefile 的末尾是这样写的:
crypto/randomx/libbitcoinconsensus_la-jit_compiler_x86.lo: \
crypto/randomx/$(am__dirstamp) \
crypto/randomx/$(DEPDIR)/$(am__dirstamp)
这可能会导致一些问题,因为它里面有 x86 并且它是一些临时的 *.lo 文件,我也不知道这些文件在编译过程中的什么地方被引入。
那么有什么办法,怎么解决呢?如果需要单独的 make 文件,那不是问题,只要我知道如何(通过代码)区分它们。我正在编译 linux,所以我想在 configure.ac 中有一种方法可以做到这一点,或者在 autogen.sh 或类似的东西中,它们用于设置环境。
提前感谢您的帮助。
你给出了文件名列表,但没有说明你如何使用它们,所以我假设你正在将它们分配给变量。
我们可以从一个简单的开始 conditional:
ifeq ($(PLATFORM),x86_64)
do something
endif
ifeq ($(PLATFORM),aarch64)
do something else
endif
粗略地说,我们可以这样做:
ifeq ($(PLATFORM),x86_64)
SOURCE := crypto/randomx/jit_compiler_x86.cpp
HEADER := crypto/randomx/jit_compiler_x86.hpp
ASM := crypto/randomx/jit_compiler_x86_static.asm
STATIC_HEADER := crypto/randomx/jit_compiler_x86_static.hpp
STATIC_SOURCE := crypto/randomx/jit_compiler_x86_static.S
endif
ifeq ($(PLATFORM),x86_64)
...likewise for a64...
endif
这可行,但会非常多余。我们可以改进它:
BASE := crypto/randomx/jit_compiler
ifeq ($(PLATFORM),x86_64)
BASE := $(BASE)_x86
endif
ifeq ($(PLATFORM),aarch64)
BASE := $(BASE)_a64
endif
SOURCE := $(BASE).cpp
HEADER := $(BASE).hpp
ASM := $(BASE)_static.asm
STATIC_HEADER := $(BASE)_static.hpp
STATIC_SOURCE := $(BASE)_static.S