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

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

问题描述

我在 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。



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



PS:我的cabal文件在生成过程中调用此makefile以解决阴谋。我希望我可以在我的cabal文件中列出它们作为c源代码。

感谢Ed'ka,我知道现在正确答案。

Makefile现在有这样一个规则:

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

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



这比其他建议的方式更好,因为它可以让我 all 被指定,而不仅仅是-m标志。没有标志时也是空的。



谢谢大家!


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 $@

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.

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

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.

解决方案

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

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\"")

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.

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.

Thank you everyone!

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

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