Makefile 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # Copyright (c) 2009 Openmoko Inc.
  2. #
  3. # This program is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. # +++START_UPDATE_MAKEFILE: Start of auto included code
  16. # The text between the +++ and --- tags is copied by the
  17. # UpdateMakefiles script. Do not remove or change these tags.
  18. # ---
  19. # Autodetect root directory
  20. define FIND_ROOT_DIR
  21. while : ; do \
  22. d=$$(pwd) ; \
  23. [ -d "$${d}/samo-lib" ] && echo $${d} && exit 0 ; \
  24. [ X"/" = X"$${d}" ] && echo ROOT_DIRECTORY_NOT_FOUND && exit 1 ; \
  25. cd .. ; \
  26. done
  27. endef
  28. ROOT_DIR := $(shell ${FIND_ROOT_DIR})
  29. # Directory of Makefile includes
  30. MK_DIR := ${ROOT_DIR}/samo-lib/Mk
  31. # Include the initial Makefile setup
  32. include ${MK_DIR}/definitions.mk
  33. # ---END_UPDATE_MAKEFILE: End of auto included code
  34. INCLUDES = -I${MINI_LIBC_INCLUDE}
  35. INCLUDES += -I${FATFS_INCLUDE}
  36. INCLUDES += -I${DRIVERS_INCLUDE}
  37. INCLUDES += -I${SAMO_LIB_INCLUDE}
  38. vpath %.c src
  39. TYPE_LIST = read-only read-write
  40. TARGETS = all
  41. .PHONY: all
  42. all: $(foreach type, ${TYPE_LIST}, lib/${type}/libtinyfat.a)
  43. define BUILD
  44. lib/$(strip ${1}):
  45. $${RM} -r $$@
  46. mkdir -p $$@
  47. lib/$(strip ${1})/libtinyfat.a: lib/$(strip ${1})
  48. build-$(strip ${1}): Makefile
  49. $${RM} -r $$@
  50. mkdir -p $$@
  51. @echo SAMO_LIB = $${SAMO_LIB} >> $$@/Makefile
  52. @echo include $${MK_DIR}/definitions.mk >> $$@/Makefile
  53. @echo INCLUDES = $${INCLUDES} | sed 's@\.\./\.\./@../../../@g' >> $$@/Makefile
  54. @echo vpath %.c ../src >> $$@/Makefile
  55. @echo INCLUDES += -I../config/c33/$(strip ${1})/ >> $$@/Makefile
  56. @echo TARGETS = all >> $$@/Makefile
  57. @echo include $${SAMO_LIB}/Mk/rules.mk >> $$@/Makefile
  58. endef
  59. # macros to generate rules
  60. MAKE_RULE = $(eval $(call MAKE_RULE1,${1},${2}))
  61. define MAKE_RULE1
  62. lib/$(strip ${1})/libtinyfat.a: build-$(strip ${1})/$(strip ${2})
  63. build-$(strip ${1})/$(strip ${2}): build-$(strip ${1})
  64. $${MAKE} -C build-$(strip ${1}) ${2}
  65. $${AR} r lib/$(strip ${1})/libtinyfat.a $$@
  66. endef
  67. # master rules
  68. $(foreach type, ${TYPE_LIST}, $(eval $(call BUILD,${type})))
  69. # create all the individual object file rules
  70. $(call MAKE_RULE,read-only,tff.o)
  71. # $(call MAKE_RULE,read-only,mmc.o)
  72. $(call MAKE_RULE,read-write,tff.o)
  73. # $(call MAKE_RULE,read-write,mmc.o)
  74. $(call MAKE_RULE,read-write,GetFATTime.o)
  75. clean:
  76. $(RM) *.[do] *.asm33
  77. $(RM) -r $(foreach type, ${TYPE_LIST}, build-${type})
  78. $(RM) $(foreach type, ${TYPE_LIST}, lib/${type}/libtinyfat.a)
  79. ${RM} -r lib
  80. include ${MK_DIR}/rules.mk