如何检测 GHC 是否设置为默认生成 32 位或 64 位代码? [英] How can I detect if GHC is set to generate 32bit or 64bit code by default?

查看:21
本文介绍了如何检测 GHC 是否设置为默认生成 32 位或 64 位代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 makefile 中有以下内容:

I have the following bits in my makefile:

GLFW_FLAG := -m32 -O2 -Iglfw/include -Iglfw/lib -Iglfw/lib/cocoa $(CFLAGS)
...
$(BUILD_DIR)/%.o : %.c
    $(CC) -c $(GLFW_FLAG) $< -o $@
$(BUILD_DIR)/%.o : %.m
    $(CC) -c $(GLFW_FLAG) $< -o $@

-m32 指示 GCC 生成 32 位代码.这是因为在某些配置中 GHC 设置为构建 32 位代码,但 GCC 的默认值有时是 64 位.我想对此进行概括,以便它自动检测 GHC 是在构建 32 位还是 64 位代码,然后将正确的标志传递给 GCC.

The -m32 instructs GCC to generate 32bit code. It's there because on some configurations GHC is set to build 32bit code but GCC's default is sometimes 64bit. I would like to generalize this so that it autodetects whether GHC is building 32bit or 64bit code and then passes the correct flag to GCC.

问题:我如何询问 GHC 它将构建什么类型的代码(32 位与 64 位)?

Question: How can I ask GHC what type of code (32bit vs. 64bit) it will build?

PS:我的 cabal 文件在构建期间调用此 makefile 以解决 cabal 中的限制.我真希望我能在我的阴谋集团文件中将这些作为 c-sources 列出.

PS: My cabal file calls this makefile during the build to workaround limitations in cabal. I do wish I could just list these as c-sources in my cabal file.

推荐答案

感谢 Ed'ka 我现在知道正确答案了.

Thanks to Ed'ka I know the correct answer now.

Makefile 现在有这样的规则:

The Makefile now has a rule like this:

GCCFLAGS  := $(shell ghc --info | ghc -e "fmap read getContents >>= putStrLn . unwords . read . Data.Maybe.fromJust . lookup "Gcc Linker flags"")

它有点长,但它所做的只是从 ghc 的输出中提取Gcc 链接器标志".注意:这是ghc --info的输出,而不是ghc +RTS --info的输出.

It's a bit long, but all it does is extract the "Gcc Linker flags" from ghc's output. Note: This is the output of ghc --info and not ghc +RTS --info.

这比其他建议的方法要好,因为它给了我所有需要指定的标志,而不仅仅是 -m 标志.当不需要标志时,它也是空的.

This is better than the other suggested ways as it gives me all the flags that need to be specified and not just the -m flag. It's also empty when no flags are needed.

谢谢大家!

这篇关于如何检测 GHC 是否设置为默认生成 32 位或 64 位代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆