像sdl-config这样的配置工具如何用于cabalized项目? [英] How can configuration tools like sdl-config be used with a cabalized project?

查看:108
本文介绍了像sdl-config这样的配置工具如何用于cabalized项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可用的SDL / Haskell应用程序,我想用Cabal而不是当前的Makefile构建(因为这是Haskell方式)。 Makefile本身非常简单,我希望默认的cabal构建过程可以让我重新构建在我的Makefile中指定的构建命令。问题是它使用了sdl-config,这是一个实用程序,它提供了所有必要的cc-编译器选项:

  wrapper.o:SDLWrapper_stub.h 
ghc -no-hs-main`sdl-config --cflags` -Wall wrapper.c -c

在调用GHC时,Cabal似乎不会将其扩展为shell调用。我如何指定在编译 wrapper.o

解决时将sdl-config的选项送入GHC方案使用Cabal中的 configure 样式,可以编写一个小配置脚本,将sdl-config命令的输出替换为一个变量。这些值将在$ foo.buildinfo.in文件中被替换,产生一个$ foo.buildinfo文件,Cabal将包含在构建过​​程中。



通用解决方案:配置脚本

 #!/ bin / sh 

SDLFLAGS =`sdl-config --cflags`
echo发现$ SDLFLAGS
sed's,@ SDLFLAGS @,'$ SDLFLAGS','z.buildinfo.in> z.buildinfo

$ foo.builinfo.in文件

  cc-options:@ SDLFLAGS @ 



<.cabal文件

 构建类型:配置

运行cabal configure时,将创建z.buildinfo中的cc-options字段来保存:

  cc-options:-I / usr / include / SDL -D_GNU_SOURCE = 1 -D_REENTRANT 

哪些cabal将包含在构建中。



完成。



pkg-config工具的具体解决方案



对于支持< a配置的pkg-config -style ,例如

code> sdl cairo 等等,Cabal已经有了明确的支持:

< blockquote>

pkgconfig-depends:软件包列表



构建此软件包所需的pkg-config软件包列表。它们可以用版本注释,例如gtk + -2.0> = 2.10,cairo> = 1.0。如果没有指定版本约束,则认为任何版本均可接受。 Cabal使用pkg-config来查找系统中的软件包是否可用,并查找使用软件包所需的额外编译和链接器选项。



如果您需要绑定到一个支持pkg-config的C库(使用pkg-config --list-all来查明它是否被支持),那么最好在这个字段中使用这个字段而不是硬编码选项。


因此,对于 sdl ,您只需要:

  pkgconfig-depends:sdl 


I have a working SDL/Haskell application that I would like to build using Cabal instead of the current Makefile (because that is the "Haskell way"). The Makefile is itself very simple, and I was hoping that the default cabal build process could allow me to reconstruct a build command specified in my Makefile. The problem is that it makes use of "sdl-config", a utility that gives you all the necessary cc- compiler options:

wrapper.o: SDLWrapper_stub.h
    ghc -no-hs-main `sdl-config --cflags` -Wall wrapper.c -c

Cabal does not seem to expand that into a shell call when calling GHC. How can I specify that sdl-config's options should be fed into GHC when compiling wrapper.o?

解决方案

Using the configure style in Cabal, you can write a little configure script that substitutes a variable for the output of the sdl-config command. The values will then be replaced in a $foo.buildinfo.in file, yielding a $foo.buildinfo file, that Cabal will include in the build process.

General solution: the configure script

 #!/bin/sh

 SDLFLAGS=`sdl-config --cflags`
 echo Found "$SDLFLAGS"
 sed 's,@SDLFLAGS@,'"$SDLFLAGS"',' z.buildinfo.in > z.buildinfo       

The $foo.builinfo.in file

cc-options: @SDLFLAGS@

The .cabal file

Build-type:          Configure

When you run "cabal configure" the "cc-options" field in z.buildinfo will be created to hold:

cc-options: -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT 

which cabal will include in the build.

Done.

Specific solution for pkg-config tools

For tools that support the pkg-config-style of configuration, such as sdl or cairo and others, Cabal has specific support already:

pkgconfig-depends: package list

A list of pkg-config packages, needed to build this package. They can be annotated with versions, e.g. gtk+-2.0 >= 2.10, cairo >= 1.0. If no version constraint is specified, any version is assumed to be acceptable. Cabal uses pkg-config to find if the packages are available on the system and to find the extra compilation and linker options needed to use the packages.

If you need to bind to a C library that supports pkg-config (use pkg-config --list-all to find out if it is supported) then it is much preferable to use this field rather than hard code options into the other fields.

So for sdl you just need:

pkgconfig-depends: sdl

这篇关于像sdl-config这样的配置工具如何用于cabalized项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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