build.wake 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. tuple MachineExecutionEnvironment =
  2. IncludeDir_: String
  3. LibDir_: String
  4. LibMetal_: Path
  5. LibMetalGloss_: Path
  6. ConfigOptions: FreedomMetalConfigureOptions
  7. AllOutputs_: List Path
  8. global def getMachineExecutionEnvironmentLibMetal = getMachineExecutionEnvironmentLibMetal_
  9. global def getMachineExecutionEnvironmentLibMetalGloss = getMachineExecutionEnvironmentLibMetalGloss_
  10. global def getMachineExecutionEnvironmentIncludeDir = getMachineExecutionEnvironmentIncludeDir_
  11. global def getMachineExecutionEnvironmentLibDir = getMachineExecutionEnvironmentLibDir_
  12. global def getMachineExecutionEnvironmentAllOutputs = getMachineExecutionEnvironmentAllOutputs_
  13. global def getMachineExecutionEnvironmentRISCV_ARCH = _.getMachineExecutionEnvironmentConfigOptions.getFreedomMetalConfigureOptionsRISCV_ARCH
  14. global def getMachineExecutionEnvironmentRISCV_ABI = _.getMachineExecutionEnvironmentConfigOptions.getFreedomMetalConfigureOptionsRISCV_ABI
  15. global def getMachineExecutionEnvironmentRISCV_CMODEL = _.getMachineExecutionEnvironmentConfigOptions.getFreedomMetalConfigureOptionsRISCV_CMODEL
  16. global def getMachineExecutionEnvironmentHost = _.getMachineExecutionEnvironmentConfigOptions.getFreedomMetalConfigureOptionsHost
  17. global def getMachineExecutionEnvironmentPrefix = _.getMachineExecutionEnvironmentConfigOptions.getFreedomMetalConfigureOptionsOutputDir
  18. global def getMachineExecutionEnvironmentName = _.getMachineExecutionEnvironmentConfigOptions.getFreedomMetalConfigureOptionsMachineName
  19. global def getMachineExecutionEnvironmentHeader = _.getMachineExecutionEnvironmentConfigOptions.getFreedomMetalConfigureOptionsMachineHeader
  20. global def getMachineExecutionEnvironmentLdScript = _.getMachineExecutionEnvironmentConfigOptions.getFreedomMetalConfigureOptionsMachineLdScript
  21. def dir / subDir = "{dir.getPathName}/{subDir}"
  22. tuple FreedomMetalConfigureOptions =
  23. global Resources: List String
  24. global RISCV_ARCH: String
  25. global RISCV_ABI: String
  26. global RISCV_CMODEL: String
  27. global Host: String
  28. global OutputDir: String
  29. global MachineName: String
  30. global MachineHeader: Path
  31. global MachineInlineHeader: Path
  32. global PlatformHeader: Path
  33. global MachineLdScript: Path
  34. global def defaultSiFiveRISCVResources = "riscv-tools/2019.05.0", Nil
  35. global def makeFreedomMetalConfigureOptions arch abi cmodel host outputDir name header inlineHeader platformHeader ldScript =
  36. def resources = defaultSiFiveRISCVResources
  37. FreedomMetalConfigureOptions resources arch abi cmodel host outputDir name header inlineHeader platformHeader ldScript
  38. global tuple MakeElfOptions =
  39. global MEE: MachineExecutionEnvironment
  40. global ProgramSrcs: List Path
  41. global CFlags: List String
  42. global LFlags: List String
  43. global IncludeDirs: List String
  44. global ElfFile: String
  45. global def runFreedomMetalInstall options =
  46. def outputDir = options.getFreedomMetalConfigureOptionsOutputDir
  47. def meeHeader = options.getFreedomMetalConfigureOptionsMachineHeader
  48. def meeInline = options.getFreedomMetalConfigureOptionsMachineInlineHeader
  49. def platformHeader = options.getFreedomMetalConfigureOptionsPlatformHeader
  50. def meeLdScript = options.getFreedomMetalConfigureOptionsMachineLdScript
  51. def machineName = options.getFreedomMetalConfigureOptionsMachineName
  52. def wrapperScript = source "{here}/scripts/autoconf_wrapper"
  53. def metalInstallDir = outputDir
  54. def installedFreedomMetal =
  55. def inputs =
  56. sources "freedom-metal" `.*`
  57. | filter (!matches `freedom-metal/doc/.*` _.getPathName)
  58. def cmdline =
  59. "rsync",
  60. "-r",
  61. "--exclude", "freedom-metal/doc",
  62. "--exclude", "freedom-metal/.git",
  63. "--exclude", "*.wake",
  64. "freedom-metal",
  65. outputDir,
  66. Nil
  67. def fnOutputs _ =
  68. files "freedom-metal" `.*`
  69. | filter (!matches `freedom-metal/(\.git|doc)/.*` _)
  70. | filter (!matches `.*\.(in|am|m4|wake)` _) # exclude these because autoconf modfies them
  71. | filter (!matches `(.*/)?(configure)` _)
  72. | map ("{metalInstallDir}/{_}")
  73. makePlan cmdline inputs
  74. | setPlanFnOutputs fnOutputs
  75. | setPlanLocalOnly True
  76. | runJob
  77. | getJobOutputs
  78. def runDir = "{metalInstallDir}/freedom-metal"
  79. def cmdline =
  80. relative runDir wrapperScript.getPathName,
  81. options.getFreedomMetalConfigureOptionsHost,
  82. machineName,
  83. relative runDir meeHeader.getPathName,
  84. relative runDir meeInline.getPathName,
  85. relative runDir platformHeader.getPathName,
  86. relative runDir meeLdScript.getPathName,
  87. relative runDir outputDir,
  88. Nil
  89. def inputs = mkdir outputDir, wrapperScript, meeHeader, meeLdScript, installedFreedomMetal
  90. def foutputs _ =
  91. files "{outputDir}/include" `.*`
  92. ++ files "{outputDir}/lib" `.*`
  93. def withCFlags =
  94. def march = options.getFreedomMetalConfigureOptionsRISCV_ARCH
  95. def mabi = options.getFreedomMetalConfigureOptionsRISCV_ABI
  96. def cmodel = options.getFreedomMetalConfigureOptionsRISCV_CMODEL
  97. "CFLAGS=-march={march} -mabi={mabi} -g -mcmodel={cmodel}", _
  98. def makeOutputs =
  99. makePlan cmdline inputs
  100. | setPlanLocalOnly True
  101. | setPlanFnOutputs foutputs
  102. | setPlanDirectory runDir
  103. | setPlanResources options.getFreedomMetalConfigureOptionsResources
  104. | editPlanEnvironment withCFlags
  105. | runJob
  106. | getJobOutputs
  107. def getFile f msg =
  108. filter (simplify f ==~ _.getPathName) makeOutputs
  109. | head
  110. | getOrElse msg.makeError.makeBadPath
  111. def libmetal =
  112. def machineName = options.getFreedomMetalConfigureOptionsMachineName
  113. def fileName = "{outputDir}/lib/libriscv__mmachine__{machineName}.a"
  114. getFile fileName "Failed to compile libmetal: {fileName}"
  115. def libmetalGloss =
  116. def fileName = "{outputDir}/lib/libriscv__menv__metal.a"
  117. getFile fileName "Failed to compile libGloss: {fileName}"
  118. def includeDir = "{outputDir}/include"
  119. def libDir = "{outputDir}/lib"
  120. MachineExecutionEnvironment includeDir libDir libmetal libmetalGloss options makeOutputs