-2
A
回答
2
几乎没有哈斯克尔项目使用一个Makefile,因为这是笨重,难以阅读,而且容易出错。
对于简单的一次性项目,你真的不需要任何专门的编译系统在所有:GHC本身可以计算出模块之间的依赖关系:
[email protected]:/tmp$ cat >> Hello.hs
module Main where
import Greeting
main = putStrLn greeting
[email protected]:/tmp$ cat >> Greeting.hs
module Greeting where
greeting = "Hello, World!"
[email protected]:/tmp$ ghc Hello.hs
[1 of 2] Compiling Greeting (Greeting.hs, Greeting.o)
[2 of 2] Compiling Main (Hello.hs, Hello.o)
Linking Hello ...
[email protected]:/tmp$ ./Hello
Hello, World!
...或者干脆
[email protected]:/tmp$ runhaskell Hello.hs
Hello, World!
对于更复杂的项目,绝对是图书馆,你要使用Cabal。即您需要一个.cabal
文件,例如对于上述“项目” hello.cabal
。可以通过cabal
工具半自动生成这样的文件:
[email protected]:/tmp$ mkdir hello
[email protected]:/tmp$ mv Hello.hs hello
[email protected]:/tmp$ mv Greeting.hs hello
[email protected]:/tmp$ cd hello/
[email protected]:/tmp/hello$ cabal init
Package name? hello
This package name is already used by another package on hackage. Do you want to choose a different name? [default: y] n
Package version? [default: 0.1.0.0]
Please choose a license:
1) GPL-2
2) GPL-3
3) LGPL-2.1
4) LGPL-3
5) AGPL-3
6) BSD2
* 7) BSD3
8) MIT
9) ISC
10) MPL-2.0
11) Apache-2.0
12) PublicDomain
13) AllRightsReserved
14) Other (specify)
Your choice? [default: BSD3] 12
Author name? [default: Justus Sagemüller]
Maintainer email? [default: [email protected]]
Project homepage URL?
Project synopsis? hello
Project category:
* 1) (none)
2) Codec
3) Concurrency
4) Control
5) Data
6) Database
7) Development
8) Distribution
9) Game
10) Graphics
11) Language
12) Math
13) Network
14) Sound
15) System
16) Testing
17) Text
18) Web
19) Other (specify)
Your choice? [default: (none)] 17
What does the package build:
1) Library
2) Executable
Your choice? 2
What is the main module of the executable:
* 1) Main.hs (does not yet exist, but will be created)
2) Main.lhs (does not yet exist, but will be created)
3) Other (specify)
Your choice? [default: Main.hs (does not yet exist, but will be created)] 3
Please specify? Hello.hs
Source directory:
* 1) (none)
2) src
3) Other (specify)
Your choice? [default: (none)]
What base language is the package written in:
* 1) Haskell2010
2) Haskell98
3) Other (specify)
Your choice? [default: Haskell2010]
Add informative comments to each field in the cabal file (y/n)? [default: n]
Guessing dependencies...
Generating Setup.hs...
Generating ChangeLog.md...
Generating hello.cabal...
You may want to edit the .cabal file and add a Description field.
此时该文件将包含:
[email protected]:/tmp/hello$ cat hello.cabal
-- Initial hello.cabal generated by cabal init. For further documentation,
-- see http://haskell.org/cabal/users-guide/
name: hello
version: 0.1.0.0
synopsis: hello
-- description:
license: PublicDomain
author: Justus Sagemüller
maintainer: [email protected]
category: Text
build-type: Simple
extra-source-files: ChangeLog.md
cabal-version: >=1.10
executable hello
main-is: Hello.hs
-- other-modules:
-- other-extensions:
build-depends: base >=4.10 && <4.11
-- hs-source-dirs:
default-language: Haskell2010
这不是很完整,你仍然需要添加Greeting.hs
到项目:(没有文件扩展名)
...
executable hello
main-is: Hello.hs
other-modules: Greeting
-- other-extensions:
...
但仅此而已,你现在可以做
[email protected]:/tmp/hello$ cabal build
Resolving dependencies...
Configuring hello-0.1.0.0...
Preprocessing executable 'hello' for hello-0.1.0.0..
Building executable 'hello' for hello-0.1.0.0..
[1 of 2] Compiling Greeting (Greeting.hs, dist/build/hello/hello-tmp/Greeting.o)
[2 of 2] Compiling Main (Hello.hs, dist/build/hello/hello-tmp/Main.o)
Linking dist/build/hello/hello ...
或者,只需运行脚本,cabal run
或cabal install
以使其始终可用于您的系统。
相关问题
- 1. 在Linux上为C程序制作makefile
- 2. 如何为目标语言制作CFLocale?
- 3. 如何制作多语言C#控制台应用程序?
- 4. 作为设备语言更改更改应用程序语言
- 5. 如何在winforms中制作多语言应用程序
- 6. 如何制作多语言应用程序
- 7. 如何用语言制作Windows窗体应用程序?
- 8. Haskell迷你语言
- 9. Agda作为编程语言
- 10. 如何使用makefile/autoconf制作可安装的Perl程序?
- 11. 如何将应用程序语言切换为当前用户的语言?
- 12. 如何制作语言绑定?
- 13. 如何制作多语言网站?
- 14. 如何制作多语言TabBarItem
- 15. 如何制作Crystal Reports多语言?
- 16. 作为桌面编程语言的PHP
- 17. 制作iPhone应用程序多语言的最佳方式
- 18. 为ASP.NET网站制作替代语言
- 19. 如何将屏幕图像作为程序的输入,在Haskell
- 20. 如何使用Java作为Arduino的编程语言?
- 21. 如何使用Vala编程语言制作PHP模块?
- 22. 如何将我的java程序语言环境设置为ccjk?
- 23. C语言程序不起作用?
- 24. 如何在主菜单中为Drupal8制作语言切换器
- 25. 如何使用python将语音命令程序制作为android?
- 26. 使用C#作为C#应用程序的脚本语言
- 27. 在处理语言中制作透明背景(应用程序)
- 28. 制作一个wxPython应用程序多语言
- 29. R作为通用编程语言
- 30. 为非Unicode程序获取语言
我们知道你想要什么。大。你到目前为止有什么? – panther
我不建议。而是使用'ghc --make',或'cabal'或'stack'。如果您确实需要'make',请阅读有关它的文档:https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/separate_compilation.html#using-make – chi
那么你首先想想你是什么命令在制作程序时调用自己,然后将其转换为Makefile。 –