Makefile 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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}, gawk)
  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 forth.text
  68. OBJECTS =
  69. OBJECTS += button.o
  70. OBJECTS += ctp.o
  71. OBJECTS += debug.o
  72. OBJECTS += FileSystem.o
  73. OBJECTS += BoardRevision.o
  74. OBJECTS += iserial.o
  75. OBJECTS += PolledSerial.o
  76. OBJECTS += vector.o
  77. CLEAN_FILES += forth.s
  78. forth.s: header.s meta.fs forth-symbols.fi ansi-forth.fs forth-vector.fi trailer.s
  79. ${RM} "$@"
  80. cat header.s >> "$@"
  81. gforth meta.fs forth-symbols.fi ansi-forth.fs forth-vector.fi -e "bye" >> "$@"
  82. cat trailer.s >> "$@"
  83. forth-symbols.fi : sym.awk ansi-forth.fs forth-vector.fi
  84. ${AWK} -f sym.awk ansi-forth.fs forth-vector.fi > "$@"
  85. forth-vector.fi: Makefile
  86. ${RM} "$@"
  87. echo "\\ generated file - do not modify" >> "$@"
  88. echo >> "$@"
  89. echo "only forth definitions" >> "$@"
  90. echo "also meta-compiler" >> "$@"
  91. echo "meta-compile" >> "$@"
  92. echo >> "$@"
  93. echo "variable 'cold-run :: tick-cold-run" >> "$@"
  94. forth.elf: forth.o ${OBJECTS} ${LIBS}
  95. forth.text: ansi-forth.fs document.awk
  96. ${AWK} -f document.awk ansi-forth.fs > "$@"
  97. # Common macro for compiling individual forth applications
  98. MAKE_FORTH_APP = $(eval $(call MAKE_FORTH_APP1,$(strip ${1}),$(strip ${2}),$(strip ${3})))
  99. # the main application build rules
  100. define MAKE_FORTH_APP1
  101. CLEAN_FILES += ${1}.s
  102. CLEAN_FILES += ${1}.lds
  103. APPLICATIONS += ${1}.elf
  104. ${1}.s: header.s meta.fs ${1}-symbols.fi ansi-forth.fs ${1}.fi trailer.s
  105. $${RM} "$$@"
  106. cat header.s >> "$$@"
  107. gforth meta.fs ${1}-symbols.fi ansi-forth.fs ${1}.fi -e "bye" >> "$$@"
  108. cat trailer.s >> "$$@"
  109. ${1}-symbols.fi : sym.awk ansi-forth.fs ${1}.fi
  110. ${AWK} -f sym.awk ansi-forth.fs ${1}.fi > "$$@"
  111. ${1}.lds: forth.lds
  112. sed 's/forth\.o/${1}.o/g' <forth.lds > "$$@"
  113. ${1}.fi: $(wildcard programs/${1}.4th) $(wildcard programs/${1}.forth)
  114. $${RM} "$$@"
  115. echo "\\ generated file - do not modify" >> "$$@"
  116. echo >> "$$@"
  117. echo "only forth definitions" >> "$$@"
  118. echo "also meta-compiler" >> "$$@"
  119. echo "meta-compile" >> "$$@"
  120. echo >> "$$@"
  121. cat $$^ >> "$$@"
  122. echo >> "$$@"
  123. echo "create 'cold-run :: tick-cold-run" >> "$$@"
  124. echo "<',> ${2}" >> "$$@"
  125. ${1}.elf: ${1}.o ${OBJECTS} ${LIBS}
  126. endef
  127. # list of individual applications to cross compile
  128. $(call MAKE_FORTH_APP,calc,calculator)
  129. $(call MAKE_FORTH_APP,mtbf,mtbf-main)
  130. $(call MAKE_FORTH_APP,cob,cob-main)
  131. # target for compiling all appications
  132. .PHONY: applications
  133. applications: ${APPLICATIONS}
  134. .PHONY: install
  135. install: all
  136. @if [ ! -d "${DESTDIR}" ] ; then echo DESTDIR: "'"${DESTDIR}"'" is not a directory ; exit 1; fi
  137. ${COPY} ${TARGETS} ${APPLICATIONS} "${DESTDIR}"
  138. ${COPY} ${FORTH_PROGRAMS} "${DESTDIR}"
  139. .PHONY: clean
  140. clean:
  141. ${RM} *~ *.o *.d *.lst *.elf *.map *.asm33 *.fi *.p forth.text
  142. ${RM} ${CLEAN_FILES}
  143. %.o: %.s
  144. ${CROSS_AS} -o $@ ${CROSS_ASFLAGS} -ahlsm=${@:.o=.lst} $<
  145. %.elf: %.o ${OBJECTS} %.lds ${LIBS}
  146. ${CROSS_LD} ${CROSS_LDFLAGS} -T "${@:.elf=.lds}" -Map "${@:.elf=.map}" -o "$@" "$<" ${OBJECTS} ${LIBS}
  147. ${CROSS_STRIP} --remove-section=.comment "$@"
  148. ${CROSS_OBJDUMP} --section-headers "$@"
  149. include ${MK_DIR}/rules.mk