I want to write build rules for a self-hosted compiler. Taking the example of GHC, the GHC compiler is written in Haskell, and compiles Haskell. I want to first compile the source using an existing copy of the GHC compiler (phase1), then compile the compiler using the phase1 compiler (phase2) then compile the compiler using the phase2 compiler. How can I encode that in Shake?
问问题
106 次
1 回答
2
这个问题类似于编写定点构建规则。一些假设:
- 我假设每个源文件都编译为一个没有额外依赖项的目标文件(包含/导入文件的复杂性是正交的)
- 我假设阶段 1 的对象和结果最终在目录
phase1
等中。
您可以定义:
want ["phase3/ghc" <.> exe]
let getPhase x = read $ drop (length "phase") $ takeDirectory1 x :: Int
"//*.o" *> \out ->
let src = dropDirectory1 out -<.> "hs"
let phase = getPhase out
let compiler = if p == 1 then "ghc" else "phase" ++ show (p-1) </> "ghc" <.> exe
need $ src : [compiler | p /= 1]
cmd [compiler] "-c" [src] "-o" out
("//ghc" <.> exe) *> \out ->
let os = map (takeDirectory1 out </>) ["Main.o","Module2.o",...]
need os
cmd "link -o" [out] os
于 2013-06-24T19:02:16.737 回答