Application.mk 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. ############################################################################
  2. # apps/Application.mk
  3. #
  4. # Copyright (C) 2015 Gregory Nutt. All rights reserved.
  5. # Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved.
  6. # Authors: Gregory Nutt <gnutt@nuttx.org>
  7. # Paul Alexander Patience <paul-a.patience@polymtl.ca>
  8. #
  9. # Redistribution and use in source and binary forms, with or without
  10. # modification, are permitted provided that the following conditions
  11. # are met:
  12. #
  13. # 1. Redistributions of source code must retain the above copyright
  14. # notice, this list of conditions and the following disclaimer.
  15. # 2. Redistributions in binary form must reproduce the above copyright
  16. # notice, this list of conditions and the following disclaimer in
  17. # the documentation and/or other materials provided with the
  18. # distribution.
  19. # 3. Neither the name NuttX nor the names of its contributors may be
  20. # used to endorse or promote products derived from this software
  21. # without specific prior written permission.
  22. #
  23. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  26. # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  27. # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  28. # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  29. # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  30. # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  31. # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  33. # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34. # POSSIBILITY OF SUCH DAMAGE.
  35. #
  36. ############################################################################
  37. # If this is an executable program (with MAINSRC), we must build it as a
  38. # loadable module for the KERNEL build (always) or if the tristate module
  39. # has the value "m"
  40. ifneq ($(MAINSRC),)
  41. ifeq ($(MODULE),m)
  42. BUILD_MODULE = y
  43. endif
  44. ifeq ($(CONFIG_BUILD_KERNEL),y)
  45. BUILD_MODULE = y
  46. endif
  47. endif
  48. # The GNU make CURDIR will always be a POSIX-like path with forward slashes
  49. # as path segment separators. If we know that this is a native build, then
  50. # we need to fix up the path so the DELIM will match the actual delimiter.
  51. ifeq ($(CONFIG_WINDOWS_NATIVE),y)
  52. CWD = $(strip ${shell echo %CD% | cut -d: -f2})
  53. else
  54. CWD = $(CURDIR)
  55. endif
  56. ifeq ($(CONFIG_CYGWIN_WINTOOL),y)
  57. LDLIBS += "${shell cygpath -w $(BIN)}"
  58. else
  59. LDLIBS += $(BIN)
  60. endif
  61. SUFFIX = $(subst $(DELIM),.,$(CWD))
  62. PROGNAME := $(shell echo $(PROGNAME))
  63. # Object files
  64. RASRCS = $(filter %.s,$(ASRCS))
  65. CASRCS = $(filter %.S,$(ASRCS))
  66. RAOBJS = $(RASRCS:=$(SUFFIX)$(OBJEXT))
  67. CAOBJS = $(CASRCS:=$(SUFFIX)$(OBJEXT))
  68. COBJS = $(CSRCS:=$(SUFFIX)$(OBJEXT))
  69. CXXOBJS = $(CXXSRCS:=$(SUFFIX)$(OBJEXT))
  70. MAINCXXSRCS = $(filter %$(CXXEXT),$(MAINSRC))
  71. MAINCSRCS = $(filter %.c,$(MAINSRC))
  72. MAINCXXOBJ = $(MAINCXXSRCS:=$(SUFFIX)$(OBJEXT))
  73. MAINCOBJ = $(MAINCSRCS:=$(SUFFIX)$(OBJEXT))
  74. SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS) $(MAINSRC)
  75. OBJS = $(RAOBJS) $(CAOBJS) $(COBJS) $(CXXOBJS)
  76. ifneq ($(BUILD_MODULE),y)
  77. OBJS += $(MAINCOBJ) $(MAINCXXOBJ)
  78. endif
  79. DEPPATH += --dep-path .
  80. DEPPATH += --obj-path .
  81. VPATH += :.
  82. # Targets follow
  83. all:: $(OBJS)
  84. .PHONY: clean depend distclean
  85. .PRECIOUS: $(BIN)
  86. define ELFASSEMBLE
  87. @echo "AS: $1"
  88. $(Q) $(CC) -c $(AELFFLAGS) $($(strip $1)_AELFFLAGS) $1 -o $2
  89. endef
  90. define ELFCOMPILE
  91. @echo "CC: $1"
  92. $(Q) $(CC) -c $(CELFFLAGS) $($(strip $1)_CELFFLAGS) $1 -o $2
  93. endef
  94. define ELFCOMPILEXX
  95. @echo "CXX: $1"
  96. $(Q) $(CXX) -c $(CXXELFFLAGS) $($(strip $1)_CXXELFFLAGS) $1 -o $2
  97. endef
  98. define ELFLD
  99. @echo "LD: $2"
  100. $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) $(ARCHCRT0OBJ) $1 $(LDLIBS) -o $2
  101. endef
  102. $(RAOBJS): %.s$(SUFFIX)$(OBJEXT): %.s
  103. $(if $(and $(CONFIG_BUILD_LOADABLE),$(AELFFLAGS)), \
  104. $(call ELFASSEMBLE, $<, $@), $(call ASSEMBLE, $<, $@))
  105. $(CAOBJS): %.S$(SUFFIX)$(OBJEXT): %.S
  106. $(if $(and $(CONFIG_BUILD_LOADABLE),$(AELFFLAGS)), \
  107. $(call ELFASSEMBLE, $<, $@), $(call ASSEMBLE, $<, $@))
  108. $(COBJS): %.c$(SUFFIX)$(OBJEXT): %.c
  109. $(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \
  110. $(call ELFCOMPILE, $<, $@), $(call COMPILE, $<, $@))
  111. $(CXXOBJS): %$(CXXEXT)$(SUFFIX)$(OBJEXT): %$(CXXEXT)
  112. $(if $(and $(CONFIG_BUILD_LOADABLE),$(CXXELFFLAGS)), \
  113. $(call ELFCOMPILEXX, $<, $@), $(call COMPILEXX, $<, $@))
  114. archive:
  115. ifeq ($(CONFIG_CYGWIN_WINTOOL),y)
  116. $(call ARCHIVE_ADD, "${shell cygpath -w $(BIN)}", $(OBJS))
  117. else
  118. $(call ARCHIVE_ADD, $(BIN), $(OBJS))
  119. endif
  120. ifeq ($(BUILD_MODULE),y)
  121. $(MAINCXXOBJ): %$(CXXEXT)$(SUFFIX)$(OBJEXT): %$(CXXEXT)
  122. $(if $(and $(CONFIG_BUILD_LOADABLE),$(CXXELFFLAGS)), \
  123. $(call ELFCOMPILEXX, $<, $@), $(call COMPILEXX, $<, $@))
  124. $(MAINCOBJ): %.c$(SUFFIX)$(OBJEXT): %.c
  125. $(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \
  126. $(call ELFCOMPILE, $<, $@), $(call COMPILE, $<, $@))
  127. PROGLIST := $(wordlist 1,$(words $(MAINCOBJ) $(MAINCXXOBJ)),$(PROGNAME))
  128. PROGLIST := $(addprefix $(BINDIR)$(DELIM),$(PROGLIST))
  129. PROGOBJ := $(MAINCOBJ) $(MAINCXXOBJ)
  130. $(PROGLIST): $(MAINCOBJ) $(MAINCXXOBJ)
  131. $(Q) mkdir -p $(BINDIR)
  132. ifeq ($(CONFIG_CYGWIN_WINTOOL),y)
  133. $(call ELFLD,$(firstword $(PROGOBJ)),"${shell cygpath -w $(firstword $(PROGLIST))}")
  134. else
  135. $(call ELFLD,$(firstword $(PROGOBJ)),$(firstword $(PROGLIST)))
  136. endif
  137. $(Q) chmod +x $(firstword $(PROGLIST))
  138. ifneq ($(CONFIG_DEBUG_SYMBOLS),y)
  139. $(Q) $(STRIP) $(firstword $(PROGLIST))
  140. endif
  141. $(eval PROGLIST=$(filter-out $(firstword $(PROGLIST)),$(PROGLIST)))
  142. $(eval PROGOBJ=$(filter-out $(firstword $(PROGOBJ)),$(PROGOBJ)))
  143. install:: $(PROGLIST)
  144. else
  145. MAINNAME := $(addsuffix _main,$(PROGNAME))
  146. $(MAINCXXOBJ): %$(CXXEXT)$(SUFFIX)$(OBJEXT): %$(CXXEXT)
  147. $(eval $<_CXXFLAGS += ${shell $(DEFINE) "$(CXX)" main=$(firstword $(MAINNAME))})
  148. $(eval $<_CXXELFFLAGS += ${shell $(DEFINE) "$(CXX)" main=$(firstword $(MAINNAME))})
  149. $(eval MAINNAME=$(filter-out $(firstword $(MAINNAME)),$(MAINNAME)))
  150. $(if $(and $(CONFIG_BUILD_LOADABLE),$(CXXELFFLAGS)), \
  151. $(call ELFCOMPILEXX, $<, $@), $(call COMPILEXX, $<, $@))
  152. $(MAINCOBJ): %.c$(SUFFIX)$(OBJEXT): %.c
  153. $(eval $<_CFLAGS += ${shell $(DEFINE) "$(CC)" main=$(firstword $(MAINNAME))})
  154. $(eval $<_CELFFLAGS += ${shell $(DEFINE) "$(CC)" main=$(firstword $(MAINNAME))})
  155. $(eval MAINNAME=$(filter-out $(firstword $(MAINNAME)),$(MAINNAME)))
  156. $(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \
  157. $(call ELFCOMPILE, $<, $@), $(call COMPILE, $<, $@))
  158. install::
  159. endif # BUILD_MODULE
  160. context::
  161. ifneq ($(PROGNAME),)
  162. REGLIST := $(addprefix $(BUILTIN_REGISTRY)$(DELIM),$(addsuffix .bdat,$(PROGNAME)))
  163. APPLIST := $(PROGNAME)
  164. $(REGLIST): $(DEPCONFIG) Makefile
  165. $(call REGISTER,$(firstword $(APPLIST)),$(firstword $(PRIORITY)),$(firstword $(STACKSIZE)),$(if $(BUILD_MODULE),,$(firstword $(APPLIST))_main))
  166. $(eval APPLIST=$(filter-out $(firstword $(APPLIST)),$(APPLIST)))
  167. $(if $(filter-out $(firstword $(PRIORITY)),$(PRIORITY)),$(eval PRIORITY=$(filter-out $(firstword $(PRIORITY)),$(PRIORITY))))
  168. $(if $(filter-out $(firstword $(STACKSIZE)),$(STACKSIZE)),$(eval STACKSIZE=$(filter-out $(firstword $(STACKSIZE)),$(STACKSIZE))))
  169. register:: $(REGLIST)
  170. else
  171. register::
  172. endif
  173. .depend: Makefile $(wildcard $(foreach SRC, $(SRCS), $(addsuffix /$(SRC), $(subst :, ,$(VPATH))))) $(DEPCONFIG)
  174. $(Q) $(MKDEP) $(DEPPATH) --obj-suffix .c$(SUFFIX)$(OBJEXT) "$(CC)" -- $(CFLAGS) -- $(filter %.c,$^) >Make.dep
  175. $(Q) $(MKDEP) $(DEPPATH) --obj-suffix .S$(SUFFIX)$(OBJEXT) "$(CC)" -- $(CFLAGS) -- $(filter %.S,$^) >>Make.dep
  176. $(Q) $(MKDEP) $(DEPPATH) --obj-suffix $(CXXEXT)$(SUFFIX)$(OBJEXT) "$(CXX)" -- $(CXXFLAGS) -- $(filter %$(CXXEXT),$^) >>Make.dep
  177. $(Q) touch $@
  178. depend:: .depend
  179. clean::
  180. $(call CLEAN)
  181. distclean:: clean
  182. $(call DELFILE, Make.dep)
  183. $(call DELFILE, .depend)
  184. -include Make.dep