Makefile.am 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. # Copyright 2018-2019 SiFive, Inc
  2. # SPDX-License-Identifier: Apache-2.0
  3. # Every test depends on the generated linker script.
  4. $(check_PROGRAMS): riscv__mmachine__@MACHINE_NAME@.lds
  5. # Every test depends on the freshly-compiled library.
  6. $(check_PROGRAMS): libriscv__mmachine__@MACHINE_NAME@.a
  7. # Generates a linker script that's more reasonable that whatever GCC's default
  8. # is.
  9. ldsdir = $(libdir)
  10. lds_DATA = riscv__mmachine__@MACHINE_NAME@.lds
  11. if PRECONFIGURED
  12. riscv__mmachine__@MACHINE_NAME@.lds: @MACHINE_HEADER@
  13. cp $< $@
  14. else # !PRECONFIGURED
  15. riscv__mmachine__@MACHINE_NAME@.lds: @LDSCRIPT_GENERATOR@ @MACHINE_NAME@.dtb
  16. $< --dtb $(filter %.dtb,$^) --linker $@
  17. endif # PRECONFIGURED
  18. # Generates a SPEC file that sets a reasonable set of default options for this
  19. # build.
  20. specdir = $(libdir)
  21. spec_DATA =
  22. spec_DATA += riscv__mmachine__@MACHINE_NAME@.specs
  23. if PRECONFIGURED
  24. riscv__mmachine__@MACHINE_NAME@.specs:
  25. touch $@
  26. else # !PRECONFIGURED
  27. riscv__mmachine__@MACHINE_NAME@.specs: @SPECS_GENERATOR@ @MACHINE_NAME@.dtb
  28. $< --dtb $(filter %.dtb,$^) --specs $@ --prefix @prefix@ --machine @MACHINE_NAME@
  29. endif # PRECONFIGURED
  30. spec_DATA += riscv__menv__metal.specs
  31. riscv__menv__metal.specs: riscv__menv__metal.specs.in
  32. cat $^ > $@
  33. # In order to generate code that's actually compatible with a machine we must
  34. # pass the march and mabi arguments to GCC that coorespond to the hardware.
  35. # This is handled by generating a makefile fragment, including it, and then
  36. # adding those argument to CFLAGS.
  37. -include @MACHINE_NAME@.mk
  38. if PRECONFIGURED
  39. @MACHINE_NAME@.mk: @MACHINE_MAKEATTRIBUTES@
  40. cp $< $@
  41. else # !PRECONFIGURED
  42. @MACHINE_NAME@.mk: @MAKEATTRIBUTES_GENERATOR@ @MACHINE_NAME@.dtb
  43. $< --dtb $(filter %.dtb,$^) --output $@
  44. endif # PRECONFIGURED
  45. # Install some METAL-specific headers, one of which is automatically generated.
  46. # The files that aren't automatically generated are the same for all machines.
  47. nobase_include_HEADERS = \
  48. metal/drivers/fixed-clock.h \
  49. metal/drivers/fixed-factor-clock.h \
  50. metal/drivers/riscv_clint0.h \
  51. metal/drivers/riscv_cpu.h \
  52. metal/drivers/riscv_plic0.h \
  53. metal/drivers/sifive_ccache0.h \
  54. metal/drivers/sifive_clic0.h \
  55. metal/drivers/sifive_fe310-g000_hfrosc.h \
  56. metal/drivers/sifive_fe310-g000_hfxosc.h \
  57. metal/drivers/sifive_fe310-g000_lfrosc.h \
  58. metal/drivers/sifive_fe310-g000_pll.h \
  59. metal/drivers/sifive_fe310-g000_prci.h \
  60. metal/drivers/sifive_fu540-c000_l2.h \
  61. metal/drivers/sifive_global-external-interrupts0.h \
  62. metal/drivers/sifive_gpio-buttons.h \
  63. metal/drivers/sifive_gpio-leds.h \
  64. metal/drivers/sifive_gpio-switches.h \
  65. metal/drivers/sifive_gpio0.h \
  66. metal/drivers/sifive_local-external-interrupts0.h \
  67. metal/drivers/sifive_rtc0.h \
  68. metal/drivers/sifive_spi0.h \
  69. metal/drivers/sifive_test0.h \
  70. metal/drivers/sifive_trace.h \
  71. metal/drivers/sifive_uart0.h \
  72. metal/drivers/sifive_wdog0.h \
  73. metal/machine/inline.h \
  74. metal/machine/platform.h \
  75. metal/button.h \
  76. metal/cache.h \
  77. metal/clock.h \
  78. metal/compiler.h \
  79. metal/cpu.h \
  80. metal/gpio.h \
  81. metal/interrupt.h \
  82. metal/io.h \
  83. metal/itim.h \
  84. metal/led.h \
  85. metal/lock.h \
  86. metal/machine.h \
  87. metal/memory.h \
  88. metal/pmp.h \
  89. metal/privilege.h \
  90. metal/rtc.h \
  91. metal/shutdown.h \
  92. metal/spi.h \
  93. metal/switch.h \
  94. metal/timer.h \
  95. metal/time.h \
  96. metal/tty.h \
  97. metal/uart.h \
  98. metal/watchdog.h
  99. if PRECONFIGURED
  100. metal/machine.h: @MACHINE_HEADER@
  101. @mkdir -p $(dir $@)
  102. cp $< $@
  103. metal/machine/inline.h: @MACHINE_INLINE@
  104. @mkdir -p $(dir $@)
  105. cp $< $@
  106. metal/machine/platform.h: @PLATFORM_HEADER@
  107. @mkdir -p $(dir $@)
  108. cp $< $@
  109. else # !PRECONFIGURED
  110. # Builds the machine-specific METAL header file, which paramaterizes the METAL for
  111. # one specific machine. This is automatically picked up by GCC so users
  112. # automatically get the relevant definitions. This is a two-step process:
  113. # first a DTB is built, and then the DTB is converted to a header file using an
  114. # external tool.
  115. @MACHINE_NAME@.dtb: @DTC@ @MACHINE_DTS@
  116. $< $(filter %.dts,$^) -o $@ -O dtb -I dts
  117. metal/machine.h: @METAL_HEADER_GENERATOR@ @MACHINE_NAME@.dtb
  118. @mkdir -p $(dir $@)
  119. $< --dtb $(filter %.dtb,$^) --output $@
  120. metal/machine/platform.h: @BARE_HEADER_GENERATOR@ @MACHINE_NAME@.dtb
  121. @mkdir -p $(dir $@)
  122. $< -d $(filter %.dtb,$^) -o $@
  123. endif # PRECONFIGURED
  124. # Quash an automake warning.
  125. lib_LIBRARIES =
  126. # Everything in here is compiled into a single library, which contains all the
  127. # source files in the project. It's named for one specific machine, which GCC
  128. # uses to select the target machine that this METAL implementation points at.
  129. lib_LIBRARIES += libriscv__mmachine__@MACHINE_NAME@.a
  130. libriscv__mmachine__@MACHINE_NAME@_a_CFLAGS = @MENV_METAL@ @MMACHINE_MACHINE_NAME@
  131. libriscv__mmachine__@MACHINE_NAME@_a_CCASFLAGS = @MENV_METAL@ @MMACHINE_MACHINE_NAME@
  132. # This will generate these sources before the compilation step
  133. BUILT_SOURCES = \
  134. metal/machine.h \
  135. metal/machine/inline.h \
  136. metal/machine/platform.h \
  137. riscv__menv__metal.specs \
  138. riscv__mmachine__@MACHINE_NAME@.specs
  139. libriscv__mmachine__@MACHINE_NAME@_a_SOURCES = \
  140. src/drivers/fixed-clock.c \
  141. src/drivers/fixed-factor-clock.c \
  142. src/drivers/inline.c \
  143. src/drivers/riscv_clint0.c \
  144. src/drivers/riscv_cpu.c \
  145. src/drivers/riscv_plic0.c \
  146. src/drivers/sifive_ccache0.c \
  147. src/drivers/sifive_clic0.c \
  148. src/drivers/sifive_fe310-g000_hfrosc.c \
  149. src/drivers/sifive_fe310-g000_hfxosc.c \
  150. src/drivers/sifive_fe310-g000_lfrosc.c \
  151. src/drivers/sifive_fe310-g000_pll.c \
  152. src/drivers/sifive_fe310-g000_prci.c \
  153. src/drivers/sifive_fu540-c000_l2.c \
  154. src/drivers/sifive_global-external-interrupts0.c \
  155. src/drivers/sifive_gpio-buttons.c \
  156. src/drivers/sifive_gpio-leds.c \
  157. src/drivers/sifive_gpio-switches.c \
  158. src/drivers/sifive_gpio0.c \
  159. src/drivers/sifive_local-external-interrupts0.c \
  160. src/drivers/sifive_rtc0.c \
  161. src/drivers/sifive_spi0.c \
  162. src/drivers/sifive_test0.c \
  163. src/drivers/sifive_trace.c \
  164. src/drivers/sifive_uart0.c \
  165. src/drivers/sifive_wdog0.c \
  166. src/button.c \
  167. src/cache.c \
  168. src/clock.c \
  169. src/cpu.c \
  170. src/entry.S \
  171. src/gpio.c \
  172. src/interrupt.c \
  173. src/led.c \
  174. src/lock.c \
  175. src/memory.c \
  176. src/pmp.c \
  177. src/privilege.c \
  178. src/rtc.c \
  179. src/shutdown.c \
  180. src/spi.c \
  181. src/switch.c \
  182. src/synchronize_harts.c \
  183. src/timer.c \
  184. src/time.c \
  185. src/trap.S \
  186. src/tty.c \
  187. src/uart.c \
  188. src/vector.S \
  189. src/watchdog.c
  190. # Freedom METAL has its own libgloss implementation that is only built in
  191. # --with-builtin-libgloss is passed to configure.
  192. if WITH_BUILTIN_LIBGLOSS
  193. lib_LIBRARIES += libriscv__menv__metal.a
  194. libriscv__menv__metal_a_SOURCES = \
  195. gloss/crt0.S \
  196. gloss/nanosleep.c \
  197. gloss/sys_access.c \
  198. gloss/sys_chdir.c \
  199. gloss/sys_chmod.c \
  200. gloss/sys_chown.c \
  201. gloss/sys_close.c \
  202. gloss/sys_execve.c \
  203. gloss/sys_exit.c \
  204. gloss/sys_faccessat.c \
  205. gloss/sys_fork.c \
  206. gloss/sys_fstat.c \
  207. gloss/sys_fstatat.c \
  208. gloss/sys_ftime.c \
  209. gloss/sys_getcwd.c \
  210. gloss/sys_getpid.c \
  211. gloss/sys_gettimeofday.c \
  212. gloss/sys_isatty.c \
  213. gloss/sys_kill.c \
  214. gloss/sys_link.c \
  215. gloss/sys_lseek.c \
  216. gloss/sys_lstat.c \
  217. gloss/sys_open.c \
  218. gloss/sys_openat.c \
  219. gloss/sys_read.c \
  220. gloss/sys_sbrk.c \
  221. gloss/sys_stat.c \
  222. gloss/sys_sysconf.c \
  223. gloss/sys_times.c \
  224. gloss/sys_unlink.c \
  225. gloss/sys_utime.c \
  226. gloss/sys_wait.c \
  227. gloss/sys_write.c
  228. endif
  229. # Quash an automake warning.
  230. check_PROGRAMS =
  231. # The simplest possible pair of tests: one that passes and one that fails
  232. check_PROGRAMS += return_pass
  233. return_pass_SOURCES = test/return_pass.c
  234. return_pass_CFLAGS = @MENV_METAL@ @MMACHINE_MACHINE_NAME@
  235. return_pass_LDFLAGS = -L. -Wl,--gc-sections -Wl,-Map=return_pass.map
  236. check_PROGRAMS += return_fail
  237. return_fail_SOURCES = test/return_fail.c
  238. return_fail_CFLAGS = @MENV_METAL@ @MMACHINE_MACHINE_NAME@
  239. return_fail_LDFLAGS = -L. -Wl,--gc-sections -Wl,-Map=return_fail.map
  240. # A simple "Hello, World!" program that directly uses the METAL interface to
  241. # print to the serial terminal.
  242. check_PROGRAMS += hello
  243. hello_SOURCES = test/hello.c
  244. hello_CFLAGS = @MENV_METAL@ @MMACHINE_MACHINE_NAME@
  245. hello_LDFLAGS = -L. -Wl,--gc-sections -Wl,-Map=hello.map
  246. # Extra clean targets
  247. clean-local:
  248. -rm -rf @MACHINE_NAME@.mk
  249. -rm -rf metal/machine.h metal/machine/platform.h
  250. -rm -rf @MACHINE_NAME@.dtb metal-@MACHINE_NAME@.lds
  251. -rm -rf *.map *.specs