在Windows中使用条件表达式Makefile

问题描述 投票:0回答:1

我正在为 Fortran 程序编写 makefile,我想使用编译器开关,具体取决于我是使用 ifort 还是 gfortran 进行编译。

这是 makefile,但它给了我一个语法错误:

# Select Compiler
COMPILER = ifort
#COMPILER = ifort
#COMPILER = gfortran

# Define the compiler switches
ifeq ($(COMPILER), gfortran)
    SWITCH = -O3 -Qopenmp
else
    SWITCH = /O3 /fast /Qipo /Qmkl=parallel /Qopenmp /Qparallel -qopt-matmul 
endif

#SWITCH = /Qmkl /Qopenmp /warn:all /check:all /traceback /heap-arrays0 
#GARBAGE = /fast /Qparallel /Qipo /Qprec-div- /QxHost  /heap-arrays0

SRCS =src\mod_utilities.f90 src\main.f90
    
EXEC = exe\run_win.exe

ifort:
    $(COMPILER) -fpp $(SWITCH) $(SRCS) -o $(EXEC) 
    
# Cleaning everything

clean:
    del *.mod
    del *.obj
    del *.pdb
    del *.ilk
    del $(EXEC)

#To compile in Mac, type:
# $ make -f makefile_mac

#To compile in Windows, type:
# $ nmake /f makefile_win

错误如下:

makefile_win(8) : fatal error U1034: syntax error : separator missing
windows makefile
1个回答
0
投票

要在 nmake 文件中获得相同的结果,您需要类似以下内容:

!IF "$(COMPILER)" == "gfortran"
SWITCH = -O3 -Qopenmp
!ELSE
SWITCH = /O3 /fast /Qipo /Qmkl=parallel /Qopenmp /Qparallel -qopt-matmul
!ENDIF

请注意,在这种情况下,单词

SWITCH
必须出现在该行的第 1 列中。否则
nmake
认为这是一个命令并尝试执行它。

© www.soinside.com 2019 - 2024. All rights reserved.