LangDev

DEAP 2009 하스켈 강좌 전반부 - 하스켈 플랫폼 설치

안기영

하스켈 개발환경을 구성하는 가장 간단한 방법은 Haskell platform이라는 하스켈 관련 툴/라이브러리 패키지를 설치한다. 주요 리눅스의 배포판에서 Haskell platform 패키지를 제공하므로 배포판 패키지가 있다면 배포판 패키지를 설치하는 것이 좋다. 윈도우즈의 경우, 설치를 제대로 마쳤다면 커맨드 라인에서 다음과 같이 ghc 컴파일러, ghci 대화식 환경, ghc-pkg 패키지 관리 유틸리티 및 cabal 하스켈 빌드 시스템이 동작함을 확인할 수 있을 것이다.

원래대로라면 하스켈 플랫폼(Haskell platform) 홈페이지에서 내려받아야 하지만, 국내에서 접속할 경우 회선 속도가 특히 느리기 때문에 이번 행사를 위해 따로 마련해 놓은 DEAP 2009 리소스 페이지에서 내려받으면 훨씬 빨리 받을 수 있다.

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\ahn>ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.10.4

C:\Documents and Settings\ahn>ghci
GHCi, version 6.10.4: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
Prelude> sum [1..10]
55
Prelude> product [1..10]
3628800
Prelude> :q
Leaving GHCi.

C:\Documents and Settings\ahn>ghc-pkg list
C:/Program Files/Haskell Platform/2009.2.0.2\package.conf:
    Cabal-1.6.0.3, GLUT-2.1.1.2, HTTP-4000.0.6, HUnit-1.2.0.3,
    OpenGL-2.2.1.1, QuickCheck-1.2.0.0, Win32-2.2.0.0, array-0.2.0.0,
    base-3.0.3.1, base-4.1.0.0, bytestring-0.9.1.4, cgi-3001.1.7.1,
    containers-0.2.0.1, directory-1.0.0.3, (dph-base-0.3),
    (dph-par-0.3), (dph-prim-interface-0.3), (dph-prim-par-0.3),
    (dph-prim-seq-0.3), (dph-seq-0.3), extensible-exceptions-0.1.1.0,
    fgl-5.4.2.2, filepath-1.1.0.2, (ghc-6.10.4), ghc-prim-0.1.0.0,
    haddock-2.4.2, haskell-src-1.0.1.3, haskell98-1.0.1.0, hpc-0.5.0.3,
    html-1.0.1.2, integer-0.1.0.1, mtl-1.1.0.2, network-2.2.1.4,
    old-locale-1.0.0.1, old-time-1.0.0.2, packedstring-0.1.0.1,
    parallel-1.1.0.1, parsec-2.1.0.1, pretty-1.0.1.0, process-1.0.1.1,
    random-1.0.0.1, regex-base-0.72.0.2, regex-compat-0.71.0.1,
    regex-posix-0.72.0.3, rts-1.0, stm-2.1.1.2, syb-0.1.0.1,
    template-haskell-2.3.0.1, time-1.1.2.4, xhtml-3000.2.0.1,
    zlib-0.5.0.0

C:\Documents and Settings\ahn>cabal --version
cabal-install version 0.6.2
using version 1.6.0.3 of the Cabal library

설치를 성공적으로 마쳤는지 더 확실히 확인하기 위하여 하스켈 프로그래머들이 주로 사용하는 하스켈로 짠 분산 버전 관리 시스템인 darcs와 또 앞으로 있을 홍민희 님의 강좌에서 사용할 pandoc이라는 마크업 변환 유틸리티를 cabal을 이용해서 소스로부터 컴파일하여 설치해 보겠다.

darcs나 pandoc을 설치하기 위해서는 하스켈 플랫폼(Haskell platorm)에 있지 않는 추가 라이브러리도 필요하다. 하지만 cabal은 BSD의 port처럼 패키지 의존성을 자동으로 검사하여 필요한 의존 패키지를 자동으로 먼저 설치해 주므로 명렁어 하나로 바로 darcs와 pandoc을 빌드하여 설치할 수 있다.

먼저 cabal 패키지 정보를 다음과 같이 hackage로부터 내려받아 최신으로 업데이트해야 한다.

C:\Documents and Settings\ahn>cabal update
Config file C:\Documents and Settings\ahn\Application Data\cabal\config not
found.
Writing default configuration to C:\Documents and Settings\ahn\Application
Data\cabal\config
Downloading the latest package list from hackage.haskell.org
Note: there is a new version of cabal-install available.
To upgrade, run: cabal install cabal-install

새 버전의 cabal-install, 즉 지금 사용하고 잇는 이 cabal 이라는 명령줄 프로그램을 업그레이드할 수 있다고 친절하게 알려준다. 우선 pandoc을 설치하기 전에 cabal-install 패키지부터 업그레이드하겠다.

C:\Documents and Settings\ahn>cabal install cabal-install
Resolving dependencies...
Downloading cabal-install-0.6.4...
Configuring cabal-install-0.6.4...
Preprocessing executables for cabal-install-0.6.4...
Building cabal-install-0.6.4...
[ 1 of 34] Compiling Distribution.Client.Check ( Distribution\Client\Check.hs, d
ist\build\cabal\cabal-tmp\Distribution\Client\Check.o )
...
...
...
[34 of 34] Compiling Main             ( Main.hs, dist\build\cabal\cabal-tmp\Main
.o )
Linking dist\build\cabal\cabal.exe ...
Installing executable(s) in C:\Program Files\Haskell\bin

C:\Documents and Settings\ahn>cabal --version
cabal-install version 0.6.2
using version 1.6.0.3 of the Cabal library

그런데 cabal-install 패키지 즉 cabal 명렁어를 업그레이드는 했지만 버전이 바뀌지 않았다! 이게 어찌 된 일일까? 이것은 하스켈 플랫폼에서 설치한 파일들과 cabal이 설치한 파일의 경로가 서로 다르며 하스켈 플랫폼 실행파일 디렉토리의 Path가 cabal의 실행파일 설치 디렉토리보다 것보다 앞서므로 계속해서 예전의 cabal 명령어가 실행되는 것 뿐이다.

C:\Documents and Settings\ahn>set
...
Path=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\ES
Tsoft\ALZip;C:\Program Files\Haskell Platform\2009.2.0.2\bin;C:\Program Files\Ha
skell Platform\2009.2.0.2\extralibs\bin;C:\Program Files\Haskell\bin;C:\Program
...
C:\Documents and Settings\ahn>dir "C:\Program Files\Haskell Platform\2009.2.0.2\
bin"
 C 드라이브의 볼륨에는 이름이 없습니다.
 볼륨 일련 번호: BC8D-766C

 C:\Program Files\Haskell Platform\2009.2.0.2\bin 디렉터리

2009-12-08  오후 01:18    <DIR>          .
2009-12-08  오후 01:18    <DIR>          ..
2009-07-15  오전 05:53           525,951 ar.exe
2009-07-15  오전 05:50            18,491 ghc-6.10.4.exe
2009-07-15  오전 05:48         1,051,648 ghc-pkg.exe
2009-07-15  오전 05:53        13,884,928 ghc.exe
2009-07-15  오전 05:50            21,931 ghci-6.10.4.exe
2009-07-15  오전 05:50            21,931 ghci.exe
2009-07-15  오전 05:50                51 ghcii-6.10.4.sh
2009-07-15  오전 05:50                51 ghcii.sh
2009-07-15  오전 05:49        13,731,840 haddock.exe
2009-07-15  오전 05:48           516,096 hasktags.exe
2009-07-15  오전 05:48            56,067 hp2ps.exe
2009-07-15  오전 05:48           985,600 hpc.exe
2009-07-15  오전 05:49           771,072 hsc2hs.exe
2009-07-15  오전 05:48           535,040 runghc.exe
2009-07-15  오전 05:50           535,040 runhaskell.exe
2009-07-15  오전 05:53           644,096 windres.exe
              16개 파일          33,299,833 바이트
               2개 디렉터리   5,919,203,328 바이트 남음

C:\Documents and Settings\ahn>dir "C:\Program Files\Haskell Platform\2009.2.0.2\
\extralibs\bin"
 C 드라이브의 볼륨에는 이름이 없습니다.
 볼륨 일련 번호: BC8D-766C

 C:\Program Files\Haskell Platform\2009.2.0.2\extralibs\bin 디렉터리

2009-12-08  오후 01:19    <DIR>          .
2009-12-08  오후 01:19    <DIR>          ..
2009-07-22  오후 03:31         1,555,609 alex.exe
2009-07-22  오후 03:28         9,771,310 cabal.exe
2009-07-22  오후 03:32         2,229,674 happy.exe
               3개 파일          13,556,593 바이트
               2개 디렉터리   5,919,203,328 바이트 남음

C:\Documents and Settings\ahn>dir "C:\Program Files\Haskell\bin"
 C 드라이브의 볼륨에는 이름이 없습니다.
 볼륨 일련 번호: BC8D-766C

 C:\Program Files\Haskell\bin 디렉터리

2009-12-08  오후 01:35    <DIR>          .
2009-12-08  오후 01:35    <DIR>          ..
2009-12-08  오후 01:35         9,852,265 cabal.exe
               1개 파일           9,852,265 바이트
               2개 디렉터리   5,919,203,328 바이트 남음

C:\Documents and Settings\ahn>"C:\Program Files\Haskell\bin\cabal" --version
cabal-install version 0.6.4
using version 1.6.0.3 of the Cabal library

즉, 하스켈의 lex와 yacc에 해당하는 alex와 happy, 그리고 cabal은 새로 업그레이드를 해도 계속 하스켈 플랫폼에서 처음 설치한 것으로 실행되도록 Path가 잡혀 있다. 이것이 마음에 들지 않으면 cabal의 실행파일 설치 디렉토리(C:\Program Files\Haskell\bin)를 Path에서 하스켈 플랫폼의 디렉토리(C:\Program Files\Haskell Platform\2009.2.0.2\extralibs\bin)보다 앞에 오도록 둘의 순서를 바꾸면 된다. 하지만 이 강좌에서는 크게 상관이 없으므로 그냥 이 상태로 cabal 0.6.2를 계속 쓰도록 하겠다.

참고로 리눅스에서도 이와 비슷한 상황이 발생하는데, 리눅스에서는 자신의 홈디렉토리 아래 cabal로 빌드한 실행파일들이 설치되는 ~/.cabal/bin을 path에 수동으로 추가해 주어야만 한다.

설치는 앞서와 마찬가지로 cabal install darcs 그리고 cabal install pandoc 으로 따로따로 설치할 수도 있지만 cabal install darcs pandoc 이렇게 여러개의 패키지를 한꺼번에 설치하도록 명령할 수도 있다. 컴파일이 한세월 걸리므로 기다리는 동안 Hakcage 홈페이지를 살펴보기로 한다. Hackage에는 많은 라이브러리와 프로그램 패키지들이 올라와 있는데 그 중에서 우리가 설치하고 있는 darcs와 pandoc의 패키지 정보 페이지를 보면서 시간을 때운다.

C:\Documents and Settings\ahn>cabal install darcs pandoc
Resolving dependencies...
Downloading binary-0.5.0.2...
Configuring binary-0.5.0.2...
Preprocessing library binary-0.5.0.2...
Building binary-0.5.0.2...
[1 of 4] Compiling Data.Binary.Builder ( src\Data\Binary\Builder.hs, dist\build\
Data\Binary\Builder.o )
...
...
...
...
...
...
[30 of 30] Compiling Main             ( src\pandoc.hs, dist\build\pandoc\pandoc-
tmp\Main.o )
Linking dist\build\pandoc\pandoc.exe ...
Created man\man1\pandoc.1
Created man\man1\hsmarkdown.1
Created man\man1\html2markdown.1
Created man\man1\markdown2pdf.1
Installing library in C:\Program Files\Haskell\pandoc-1.2.1\ghc-6.10.4
Installing executable(s) in C:\Program Files\Haskell\bin
Registering pandoc-1.2.1...
Reading package info from "dist\\installed-pkg-config" ... done.
Writing new package config file... done.
cabal: Error: some packages failed to install:
darcs-2.3.1 failed during the configure step. The exception was:
exit: ExitFailure 1

C:\Documents and Settings\ahn>cabal --version
cabal-install version 0.6.2
using version 1.6.0.3 of the Cabal library

C:\Documents and Settings\ahn>pandoc --version
pandoc 1.2.1
Copyright (C) 2006-8 John MacFarlane
Web:  http://johnmacfarlane.net/pandoc
This is free software; see the source for copying conditions.  There is no
warranty, not even for merchantability or fitness for a particular purpose.

C:\Documents and Settings\ahn>darcs --version
'darcs'은(는) 내부 또는 외부 명령, 실행할 수 있는 프로그램, 또는
배치 파일이 아닙니다.

이와 같이 pandoc은 설치 성공했지만 darcs는 설치를 실패했다. 하스켈 개발자들은 리눅스/유닉스(Mac OS X 포함) 환경에서 개발하는 비율이 높기 때문에 리눅스/유닉스 환경에서만 빌드가 되거나, 혹은 유닉스 환경에서는 기본 설정으로 빌드가 되지만 윈도우즈 별도의 옵션을 주어서 빌드해야 하는 경우가 있다. 특히 유닉스에서 주로 쓰는 C라이브러리를 링크할 때가 그러하다. 간혹 반대로 윈도우즈에서만 빌드가 되는 윈도우즈 전용 라이브러리도 있다.

에러 메시지를 다시 한번 보기 위해 cabal isntall darcs를 다시 한번 실행해 보았다.

C:\Documents and Settings\ahn>cabal install darcs
Resolving dependencies...
[1 of 2] Compiling Distribution.ShellHarness ( C:\DOCUME~1\ahn\LOCALS~1\Temp\dar
cs-2.3.13104\darcs-2.3.1\Distribution\ShellHarness.hs, C:\DOCUME~1\ahn\LOCALS~1\
Temp\darcs-2.3.13104\darcs-2.3.1\dist\setup\Distribution\ShellHarness.o )
[2 of 2] Compiling Main             ( C:\DOCUME~1\ahn\LOCALS~1\Temp\darcs-2.3.13
104\darcs-2.3.1\Setup.lhs, C:\DOCUME~1\ahn\LOCALS~1\Temp\darcs-2.3.13104\darcs-2
.3.1\dist\setup\Main.o )
Linking C:\DOCUME~1\ahn\LOCALS~1\Temp\darcs-2.3.13104\darcs-2.3.1\dist\setup\set
up.exe ...
Configuring darcs-2.3.1...
setup.exe: Missing dependencies on foreign libraries:
* Missing header file: curl/curl.h
* Missing C libraries: curl, curl
This problem can usually be solved by installing the system packages that
provide these libraries (you may need the "-dev" versions). If the libraries
are already installed but in a non-standard location then you can use the
flags --extra-include-dirs= and --extra-lib-dirs= to specify where they are.
cabal: Error: some packages failed to install:
darcs-2.3.1 failed during the configure step. The exception was:
exit: ExitFailure 1

참고로 darcs나 pandoc은 하스켈 프로그래머가 아니라도 많이 쓰는 유틸리티이기 때문에 사실 많은 플랫폼에서 바이너리나 패키지로 설치할 수 있다. 여기서 이렇게 cabal로 소스 설치를 해보는 것은 cabal 사용법을 보여줌으로써 cabal 사용법에 익숙해지도록 돕기 위함이다.

darcs의 경우는 다행히 별도의 윈도우즈에서도 -f-curl 옵션을 붙여서 다음과 같이 설치할 수 있다. 또 한세월 걸리기 때문에 이번에는 하스켈 홈페이지에서 Haskell 98 Language Report를 찾아서 좀 뒤적거려 보다고 또 하스켈로 배우는 프로그래밍(Programming in Haskell 우리말 판) 홈페이지에서 책광고 좀 하고 영문 온라인 동영상 강좌도 안내하면서 시간을 때운다.

만일 자신의 개발 플랫폼에 하스켈 플랫폼(Haskell platform)이 바이너리나 패키지로 제공되지 않는 경우에는 GHC와 Cabal을 개별적으로 설치한 다음 필요한 하스켈 관련 툴/라이브러리를 cabal을 이용해 하나씩 소스 컴파일을 통해 설치하 나가면 된다. GHC 홈페이지Download 페이지에서 현재 안정 버전인 6.10.4 버전 다운로드 페이지로 가서 각 운영체제 플랫폼에 맞는 GHC를 내려받아 설치한다. 윈도우즈나 OS X는 여기에 있는 바이너리로 설치치파일을 이용하는 것이 좋다. 단, 리눅스의 경우는 배포판 패키지로 설치하는 것이 편하므로 Distribution package 페이지를 참조하여 각 리눅스 배포판에서 제공하는 ghc 패키지를 설치한다. 그 다음으로는 Cabal을 설치해야 하는데 [Cabal 다운로드 페이지]를 참조하여 설치하면 될 것이다. 하스켈 플랫폼이 제공되는 환경이라도 하스켈 플랫폼에 구애받지 않고 더 최신 버전 라이브러리를 사용하고 싶을 경우에도 이러한 개별 패키지 설치 방법이 더 적당할 수도 있다.

행사 당일 날은 몰랐는데 대단히 재미있는 안내문서네요. ^_^

김우승