3d engine indev
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
2.5KB

  1. include Makefile.cfg
  2. target=fx9860g
  3. CONFIG.TARGET = fx
  4. CONFIG.TARGET.LONG = fx9860g
  5. PREFIX = /usr/lib/gcc/sh3eb-elf/9.1.0/
  6. toolchain = sh3eb-elf
  7. CONFIG.MACROS = -DFX9860G
  8. machine := -m3 -mb
  9. # Compiler flags, assembler flags, dependency generation, archiving
  10. cflags := $(machine) -ffreestanding -nostdlib -Wall -Wextra -std=c11 -Os \
  11. -fstrict-volatile-bitfields -I include $(CONFIG.MACROS) \
  12. $(CONFIG.CFLAGS) $(FLAGS)
  13. sflags := $(CONFIG.MACROS)
  14. dflags = -MMD -MT $@ -MF $(@:.o=.d) -MP
  15. arflags :=
  16. # Target file
  17. target := libfxengine.a
  18. # Automatic names for object and dependency files
  19. src2obj = $(1:src/%=build/%).o
  20. src2dep = $(1:src/%=build/%).d
  21. # Source files
  22. src := $(shell find src \
  23. -name '*.[csS]' -print)
  24. src_obj := $(foreach s,$(src),$(call src2obj,$s))
  25. # All object files
  26. obj := $(src_obj) $(spe_obj)
  27. #
  28. # Toolchain
  29. #
  30. gcc = $(toolchain)-gcc
  31. as = $(toolchain)-as
  32. ld = $(toolchain)-ld
  33. ar = $(toolchain)-ar
  34. objcopy = $(toolchain)-objcopy
  35. #
  36. # Version management
  37. #
  38. # Version symbol is obtained by using the last commit hash on 7 nibbles
  39. version_hash = 0x0$(shell git rev-parse --short HEAD)
  40. #
  41. # Build rules
  42. #
  43. all: $(target)
  44. $(target): $(obj)
  45. $(call cmd_l,ar,$@) $(ar) rcs $(arflags) $@ $^
  46. # Assembler sources
  47. build/%.s.o: src/%.s build/%.s.d
  48. @ mkdir -p $(dir $@)
  49. $(call cmd_b,as,$*.s) $(gcc) -c $< -o $@ $(sflags)
  50. build/%.S.o: src/%.S build/%.S.d
  51. @ mkdir -p $(dir $@)
  52. $(call cmd_b,as,$*.S) $(gcc) -c $< -o $@ $(sflags)
  53. # C sources
  54. build/%.c.o: src/%.c build/%.c.d
  55. @ mkdir -p $(dir $@)
  56. $(call cmd_b,gcc,$*.c) $(gcc) -c $< -o $@ $(dflags) $(cflags)
  57. # Version symbol. ld generates a .stack section for unknown reasons; I remove
  58. # it in the linker script.
  59. version.o: ../.git/HEAD
  60. @ mkdir -p $(dir $@)
  61. @ echo "_FXENGINE_VERSION = $(version_hash);" > $@.txt
  62. $(call cmd_b,ld,$@) $(ld) -r -R $@.txt -o $@
  63. #
  64. # Installing
  65. #
  66. m644 := -m 644
  67. # Disable -m on Mac OS
  68. ifeq "$(shell uname)" "Darwin"
  69. m644 :=
  70. endif
  71. uninstall:
  72. rm -f $(PREFIX)/$(target)
  73. rm -rf $(PREFIX)/include/fxengine
  74. install:
  75. @make uninstall
  76. install -d $(PREFIX)
  77. install $(target) $(m644) $(PREFIX)
  78. cp -r include/fxengine $(PREFIX)/include
  79. #
  80. # Utilities
  81. #
  82. # Directories: make conveniently leaves a '/' at the end of $(dir ...)
  83. %/:
  84. @ mkdir -p $@
  85. # Don't try to unlink directories once they're built (that wouldn't work =p)
  86. .PRECIOUS: %/
  87. # Dependency information
  88. -include $(shell [ -d src ] && find src -name *.d)
  89. build/%.d: ;
  90. .PRECIOUS: build/%.d
  91. .PHONY: all clean distclean
  92. # Do not output full commands by default
  93. VERBOSE ?=