2017-11-25 6 views
-2

私はHaskell言語で新しく、私は今作業中のhaskellプログラム用のmakefileを作成したいと思っています。しかし、私はそれを行う方法がわかりません。Haskell言語用のプログラムのMakefileを作るには?

ありがとうございました:)それは不格好だから

+3

私たちはあなたが望むものを知っています。すばらしいです。あなたはこれまで何を持っていますか? – panther

+2

私はそれをお勧めしません。むしろ 'ghc --make'や' cabal'や 'stack'を使います。 'make'が必要な場合は、そのドキュメントを読んでください:https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/separate_compilation.html#using-make – chi

+1

まず、プログラムを作成するときに自分自身を呼び出してから、それをMakefileに変換します。 –

答えて

2

は殆どHaskellのプロジェクトが読み込まれ、エラーが発生しやすいのは難しい、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を実行します。

関連する問題