1----------------------------------------------------------------------
2-- Copyright (c) 2009, 2011, 2012, ETH Zurich.
3-- All rights reserved.
4--
5-- This file is distributed under the terms in the attached LICENSE file.
6-- If you do not find this file, copies can be found by writing to:
7-- ETH Zurich D-INFK CAB F.78, Universitaetstr 6, CH-8092 Zurich. 
8-- Attn: Systems Group.
9--
10-- Hakefile for /hake
11--
12----------------------------------------------------------------------
13
14let
15  hsInDir af tf dir = inDir af tf dir ".hs"
16  hakesrc = find hsInDir "."
17  hake_rtsopts = "-H128M -A4M -N4"
18in
19[ Rule ([ Str "ghc -O --make",
20          Str "-XDeriveDataTypeable",
21          Str "-XStandaloneDeriving",
22          Str "-XScopedTypeVariables",
23          Str "-package ghc",
24          Str "-package ghc-mtl",
25          Str "-package ghc-paths",
26          Str "-package bytestring-trie",
27          Str "-o", Out "hake" "/hake",
28          Str "-outputdir", NoDep BuildTree "root" "/hake",
29          NStr "-i", NoDep SrcTree "src" "",
30          NStr "-i", NoDep BuildTree "hake" "/",
31          Str "-rtsopts=all",
32          Str ("-with-rtsopts=\"" ++ hake_rtsopts ++ "\""),
33          Str "-threaded",
34          In SrcTree "src" "Main.hs",
35          Dep InstallTree "" "Config.hs",
36          Str "$(LDFLAGS)"
37        ] 
38        ++ [Dep SrcTree "src" f | f <- hakesrc]),
39
40  -- Copy files required for interpreting Hakefiles
41  includeFile [
42    "ArchDefaults.hs",
43    "Args.hs",
44    "HakeTypes.hs",
45    "RuleDefs.hs",
46    "Tools.hs",
47    "TreeDB.hs",
48    "ARMv7.hs",
49    "ARMv8.hs",
50    "K1om.hs",
51    "X86_32.hs",
52    "X86_64.hs"
53  ],
54  Phony "help" False $ concat [ [Str "@echo", Str ("\"" ++ x ++ "\""), NL] | x <- [
55     "------------------------------------------------------------------"
56    ,"This is the 'help' target for the Barrelfish Makefile.  This Makefile"
57    ,"has been generated by hake in the top-level directory of your build tree."
58    ,"See the Hake documentation for more information."
59    ,""
60    ,"This Makefile contains build targets for the following architectures:"
61    ,""
62    , (Data.List.intercalate ", " Config.architectures)
63    ,""
64    ,"To change configuration options, edit the Config.hs file in the hake"
65    ,"subdirectory of this directory and run 'make Makefile'."
66    ,""
67    ,"Useful make targets:"
68    ," - <file>:           any file which can be built in the Barrelfish tree"
69    ," - 'help':           show this help text"
70    ," - 'help-platforms': show the platforms (file collections) which can be built"
71    ," - 'help-boot':      show the boot sequences which can be initiated"
72    ," - 'clean':          remove most generated files"
73    ," - 'realclean':      remove all generated files (clears the build tree)"
74    ," - 'Documentation':  build all Technical Notes"
75    ," - 'Makefile':       attempt to re-run hake"
76    ,""
77  ] ],
78  Phony "help-platforms-header" False $ concat [ [Str "@echo", Str ("\"" ++ x ++ "\""), NL] | x <- [
79     "------------------------------------------------------------------"
80    ,"Platforms supported by this Makefile.  Use 'make <platform name>':"
81    ," (these are the platforms available with your architecture choices)"
82  ] ],
83  Phony "help-boot-header" False $ concat [ [Str "@echo", Str ("\"" ++ x ++ "\""), NL] | x <- [
84     "------------------------------------------------------------------"
85    ,"Boot instructions supported by this Makefile.  Use 'make <boot name>':"
86    ," (these are the targets available with your architecture choices)"
87    ,""
88  ] ],
89  Phony "clean" False (
90    [ Str "$(RM)", Str "-r", Str "tools", Str "docs" ] ++
91    (map Str Config.architectures) ++
92    [ Dep BuildTree "root" "/clean-platform" ]),
93  -- Legacy target for scalebench to install modules
94  Phony "install" False ([
95    Dep BuildTree "root" "/$(MODULES)",
96    Str "@echo \"\";",
97    Str "echo \"Installing modules...\" ;",   
98    Str "if [ $${#MODULES[@]} -eq 0 ]; then",
99    Str "    echo \"   > Modules is empty, did you mean install_X86_64_Basic? \" ;",
100    Str "    exit 0;",
101    Str "fi;",
102    Str "for m in ${MODULES}; do",
103    Str "  if [ ! -f ${INSTALL_PREFIX}/$$m ] ||",
104    Str "      [ $$(stat -c%Y $$m) -ne $$(stat -c%Y ${INSTALL_PREFIX}/$$m) ]; then",
105    Str "         do_update=1;",
106    Str "         echo \"  > Installing $$m\" ;",
107    Str "         mkdir -p ${INSTALL_PREFIX}/$$(dirname $$m);",
108    Str "         install -p $$m ${INSTALL_PREFIX}/$$m;",
109    Str "  fi;",
110    Str "done;",
111    Str "if [ ! $$do_update ]; then",
112    Str "    echo \"  > All up to date\" ;",
113    Str "fi;",
114    Str "echo \"\";",
115    Str "echo \"done.\" ;"
116  ]),
117  Rule ([
118    Str "sed -r",
119    Str "'s#@CMAKE_SOURCE_DIR@#${SRCDIR}#g'",
120    In SrcTree "root" "/doc/Doxyfile.cmake",
121    Str ">",
122    Out "root" "/Doxyfile"
123  ]),
124  Phony "doxygen" False ([
125    Str "doxygen",
126    In BuildTree "root" "/Doxyfile"
127  ])
128]
129