我在makefile以下位:如何檢測GHC是否設置爲默認生成32位或64位代碼?
GLFW_FLAG := -m32 -O2 -Iglfw/include -Iglfw/lib -Iglfw/lib/cocoa $(CFLAGS)
...
$(BUILD_DIR)/%.o : %.c
$(CC) -c $(GLFW_FLAG) $< -o [email protected]
$(BUILD_DIR)/%.o : %.m
$(CC) -c $(GLFW_FLAG) $< -o [email protected]
的-m32
指示GCC生成32位代碼。這是因爲在某些配置中,GHC被設置爲構建32位代碼,但GCC的默認設置有時是64位。我想概括一下,以便自動檢測GHC是在構建32位還是64位代碼,然後將正確的標誌傳遞給GCC。
問題:我該如何問GHC它將構建什麼類型的代碼(32位與64位)?
PS:在編譯期間,我的cabal文件調用此makefile以解決cabal中的解決方法侷限性。我希望我可以在我的cabal文件中將它們列爲c源代碼。
我可以使用它從GHC中獲取字的大小,但我不知道它是否使用正確的值:WORDSIZE:= $(shell ghc + RTS --info | ghc -e「do c < - getContents; let {r = read c :: [(String,String)]; wsize = Data.Maybe.fromJust(lookup \「Word size \」r)}; putStrLn wsize「) – 2011-06-02 17:02:01
編譯一個測試程序是否合理並用Elf庫(在hackage上)讀取結果? – 2011-06-02 17:44:48
你可以使用'ghc -e'print(maxBound :: Int)''的結果,它應該取決於你是否有32位或64位的GHC ... – hvr 2011-06-02 19:38:47