Makefile 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. # Makefile
  2. #
  3. # Copyright (c) 2009 Openmoko Inc.
  4. #
  5. # Authors Christopher Hall <hsw@openmoko.com>
  6. #
  7. # Redistribution and use in source and binary forms, with or without
  8. # modification, are permitted provided that the following conditions are
  9. # met:
  10. #
  11. # 1. Redistributions of source code must retain the above copyright
  12. # notice, this list of conditions and the following disclaimer.
  13. #
  14. # 2. Redistributions in binary form must reproduce the above copyright
  15. # notice, this list of conditions and the following disclaimer in
  16. # the documentation and/or other materials provided with the
  17. # distribution.
  18. #
  19. # THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY
  20. # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22. # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE
  23. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24. # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25. # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  26. # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  27. # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  28. # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  29. # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. FATFS_MODE = read-write
  31. # +++START_UPDATE_MAKEFILE: Start of auto included code
  32. # The text between the +++ and --- tags is copied by the
  33. # UpdateMakefiles script. Do not remove or change these tags.
  34. # ---
  35. # Autodetect root directory
  36. define FIND_ROOT_DIR
  37. while : ; do \
  38. d=$$(pwd) ; \
  39. [ -d "$${d}/samo-lib" ] && echo $${d} && exit 0 ; \
  40. [ X"/" = X"$${d}" ] && echo ROOT_DIRECTORY_NOT_FOUND && exit 1 ; \
  41. cd .. ; \
  42. done
  43. endef
  44. ROOT_DIR := $(shell ${FIND_ROOT_DIR})
  45. # Directory of Makefile includes
  46. MK_DIR := ${ROOT_DIR}/samo-lib/Mk
  47. # Include the initial Makefile setup
  48. include ${MK_DIR}/definitions.mk
  49. # ---END_UPDATE_MAKEFILE: End of auto included code
  50. $(call REQUIRED_BINARY, ${AWK}, awk)
  51. $(call REQUIRED_BINARY, gforth, gforth)
  52. INCLUDES += -I.
  53. INCLUDES += -I${DRIVERS_INCLUDE}
  54. INCLUDES += -I${SAMO_LIB_INCLUDE}
  55. INCLUDES += -I${FATFS_CONFIG_INCLUDE} -I${FATFS_INCLUDE}
  56. INCLUDES += -I${MINI_LIBC_INCLUDE}
  57. LIBS += ${FATFS_LIB}
  58. LIBS += ${DRIVERS_LIB}
  59. LIBS += ${MINI_LIBC_LIB}
  60. LIBS += $(shell ${CROSS_GCC} -print-libgcc-file-name)
  61. CROSS_LDFLAGS = -static --strip-all --no-gc-sections --omagic
  62. CROSS_ASFLAGS = -mc33pe --fatal-warnings
  63. CLEAN_FILES =
  64. TARGETS = forth.elf
  65. FORTH_PROGRAMS = programs/*.4?? programs/*.ini programs/*.tst
  66. .PHONY: all
  67. all: ${TARGETS} applications
  68. OBJECTS =
  69. OBJECTS += button.o
  70. OBJECTS += ctp.o
  71. OBJECTS += debug.o
  72. OBJECTS += FileSystem.o
  73. OBJECTS += iserial.o
  74. OBJECTS += PolledSerial.o
  75. OBJECTS += vector.o
  76. CLEAN_FILES += forth.s
  77. forth.s: header.s meta.fs forth-symbols.fi ansi-forth.fs forth-vector.fi trailer.s
  78. ${RM} "$@"
  79. cat header.s >> "$@"
  80. gforth meta.fs forth-symbols.fi ansi-forth.fs forth-vector.fi -e "bye" >> "$@"
  81. cat trailer.s >> "$@"
  82. forth-symbols.fi : sym.awk ansi-forth.fs forth-vector.fi
  83. ${AWK} -f sym.awk ansi-forth.fs forth-vector.fi > "$@"
  84. forth-vector.fi: Makefile
  85. ${RM} "$@"
  86. echo "\\ generated file - do not modify" >> "$@"
  87. echo >> "$@"
  88. echo "only forth definitions" >> "$@"
  89. echo "also meta-compiler" >> "$@"
  90. echo "meta-compile" >> "$@"
  91. echo >> "$@"
  92. echo "variable 'cold-run :: tick-cold-run" >> "$@"
  93. forth.elf: forth.o ${OBJECTS} ${LIBS}
  94. # Common macro for compiling individual forth applications
  95. MAKE_FORTH_APP = $(eval $(call MAKE_FORTH_APP1,$(strip ${1}),$(strip ${2}),$(strip ${3})))
  96. # the main application build rules
  97. define MAKE_FORTH_APP1
  98. CLEAN_FILES += ${1}.s
  99. CLEAN_FILES += ${1}.lds
  100. APPLICATIONS += ${1}.elf
  101. ${1}.s: header.s meta.fs ${1}-symbols.fi ansi-forth.fs ${1}.fi trailer.s
  102. $${RM} "$$@"
  103. cat header.s >> "$$@"
  104. gforth meta.fs ${1}-symbols.fi ansi-forth.fs ${1}.fi -e "bye" >> "$$@"
  105. cat trailer.s >> "$$@"
  106. ${1}-symbols.fi : sym.awk ansi-forth.fs ${1}.fi
  107. ${AWK} -f sym.awk ansi-forth.fs ${1}.fi > "$$@"
  108. ${1}.lds: forth.lds
  109. sed 's/forth\.o/${1}.o/g' <forth.lds > "$$@"
  110. ${1}.fi: $(wildcard programs/${1}.4th) $(wildcard programs/${1}.forth)
  111. $${RM} "$$@"
  112. echo "\\ generated file - do not modify" >> "$$@"
  113. echo >> "$$@"
  114. echo "only forth definitions" >> "$$@"
  115. echo "also meta-compiler" >> "$$@"
  116. echo "meta-compile" >> "$$@"
  117. echo >> "$$@"
  118. cat $$^ >> "$$@"
  119. echo >> "$$@"
  120. echo "create 'cold-run :: tick-cold-run" >> "$$@"
  121. echo "<',> ${2}" >> "$$@"
  122. ${1}.elf: ${1}.o ${OBJECTS} ${LIBS}
  123. endef
  124. # list of individual applications to cross compile
  125. $(call MAKE_FORTH_APP,calc,calculator)
  126. $(call MAKE_FORTH_APP,mtbf,mtbf-main)
  127. $(call MAKE_FORTH_APP,cob,cob-main)
  128. # target for compiling all appications
  129. .PHONY: applications
  130. applications: ${APPLICATIONS}
  131. .PHONY: install
  132. install: all
  133. @if [ ! -d "${DESTDIR}" ] ; then echo DESTDIR: "'"${DESTDIR}"'" is not a directory ; exit 1; fi
  134. ${COPY} ${TARGETS} ${APPLICATIONS} "${DESTDIR}"
  135. ${COPY} ${FORTH_PROGRAMS} "${DESTDIR}"
  136. .PHONY: clean
  137. clean:
  138. ${RM} *~ *.o *.d *.lst *.elf *.map *.asm33 *.fi *.p
  139. ${RM} ${CLEAN_FILES}
  140. %.o: %.s
  141. ${CROSS_AS} -o $@ ${CROSS_ASFLAGS} -ahlsm=${@:.o=.lst} $<
  142. %.elf: %.o ${OBJECTS} %.lds ${LIBS}
  143. ${CROSS_LD} ${CROSS_LDFLAGS} -T "${@:.elf=.lds}" -Map "${@:.elf=.map}" -o "$@" "$<" ${OBJECTS} ${LIBS}
  144. ${CROSS_STRIP} --remove-section=.comment "$@"
  145. ${CROSS_OBJDUMP} --section-headers "$@"
  146. include ${MK_DIR}/rules.mk