common.mk 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #-------------------------------------------------------------------------------
  2. # Copyright (c) 2012 Freescale Semiconductor, Inc.
  3. # All rights reserved.
  4. #
  5. # Redistribution and use in source and binary forms, with or without modification,
  6. # are permitted provided that the following conditions are met:
  7. #
  8. # o Redistributions of source code must retain the above copyright notice, this list
  9. # of conditions and the following disclaimer.
  10. #
  11. # o Redistributions in binary form must reproduce the above copyright notice, this
  12. # list of conditions and the following disclaimer in the documentation and/or
  13. # other materials provided with the distribution.
  14. #
  15. # o Neither the name of Freescale Semiconductor, Inc. nor the names of its
  16. # contributors may be used to endorse or promote products derived from this
  17. # software without specific prior written permission.
  18. #
  19. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  23. # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. #-------------------------------------------------------------------------------
  30. #-------------------------------------------------------------------------------
  31. # Root paths
  32. #-------------------------------------------------------------------------------
  33. # At this point, the path to this makefile was just appended to MAKEFILE_LIST. We make
  34. # use of this to get the root directory of the SDK. This variable is exported to child
  35. # instances of make.
  36. this_makefile := $(firstword $(MAKEFILE_LIST))
  37. export SDK_ROOT := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))../)
  38. # The rest of the paths are defined in a separate makefile for easy access.
  39. include $(SDK_ROOT)/mk/paths.mk
  40. #-------------------------------------------------------------------------------
  41. # Utility
  42. #-------------------------------------------------------------------------------
  43. # Kludge to create a variable equal to a single space.
  44. empty :=
  45. space := $(empty) $(empty)
  46. #-------------------------------------------------------------------------------
  47. # OS
  48. #-------------------------------------------------------------------------------
  49. # Get the OS name. Known values are "Linux", "CYGWIN_NT-5.1", and "Darwin".
  50. os_name := $(shell uname -s)
  51. # Set to 1 if running on cygwin.
  52. is_cygwin := $(and $(findstring CYGWIN,$(os_name)),1)
  53. # Set to 1 if running on redhat.
  54. is_redhat := $(shell if [ -f /etc/redhat-release ]; then echo 1 ; fi)
  55. # Disable parallel builds for cygwin since they hang.
  56. ifeq "$(is_cygwin)" "1"
  57. .NOTPARALLEL:
  58. endif
  59. #-------------------------------------------------------------------------------
  60. # Logging options
  61. #-------------------------------------------------------------------------------
  62. # Enable color output by default.
  63. BUILD_SDK_COLOR ?= 1
  64. # Normally, commands in recipes are prefixed with '@' so the command itself
  65. # is not echoed by make. But if VERBOSE is defined (set to anything non-empty),
  66. # then the '@' is removed from recipes. The 'at' variable is used to control
  67. # this. Similarly, 'silent_make' is used to pass the -s option to child make
  68. # invocations when not in VERBOSE mode.
  69. ifeq "$(VERBOSE)" "1"
  70. at :=
  71. silent_make :=
  72. else
  73. at := @
  74. silent_make := -s
  75. endif
  76. # These colors must be printed with the printf command. echo won't handle the
  77. # escape sequences.
  78. color_default = \033[00m
  79. color_bold = \033[01m
  80. color_red = \033[31m
  81. color_green = \033[32m
  82. color_yellow = \033[33m
  83. color_blue = \033[34m
  84. color_magenta = \033[35m
  85. color_cyan = \033[36m
  86. color_orange = \033[38;5;172m
  87. color_light_blue = \033[38;5;039m
  88. color_gray = \033[38;5;008m
  89. color_purple = \033[38;5;097m
  90. ifeq "$(BUILD_SDK_COLOR)" "1"
  91. color_build := $(color_light_blue)
  92. color_c := $(color_green)
  93. color_cxx := $(color_green)
  94. color_cpp := $(color_orange)
  95. color_asm := $(color_magenta)
  96. color_ar := $(color_yellow)
  97. color_link := $(color_purple)
  98. endif
  99. # Used in printmessage if the color args are not present.
  100. color_ :=
  101. # Use in recipes to print color messages if printing to a terminal. If
  102. # BUILD_SDK_COLOR is not set to 1, this reverts to a simple uncolorized printf.
  103. # A newline is added to the end of the printed message.
  104. #
  105. # Arguments:
  106. # 1 - name of the color variable (see above), minus the "color_" prefix
  107. # 2 - first colorized part of the message
  108. # 3 - first uncolorized part of the message
  109. # 4 - color name for second colorized message
  110. # 5 - second colorized message
  111. # 6 - second uncolorized part of the message
  112. # 7 - uncolorized prefix on the whole line; this is last because it is expected to be used rarely
  113. #
  114. # All arguments are optional.
  115. #
  116. # Use like:
  117. # $(call printmessage,cyan,Building, remainder of the message...)
  118. ifeq "$(BUILD_SDK_COLOR)" "1"
  119. define printmessage
  120. if [ -t 1 ]; then printf "$(7)$(color_$(1))$(2)$(color_default)$(3)$(color_$(4))$(5)$(color_default)$(6)\n" ; \
  121. else printf "$(7)$(2)$(3)$(5)$(6)\n" ; fi
  122. endef
  123. else
  124. define printmessage
  125. printf "$(7)$(2)$(3)$(5)$(6)\n" ; fi
  126. endef
  127. endif
  128. #-------------------------------------------------------------------------------
  129. # Compiler and tools
  130. #-------------------------------------------------------------------------------
  131. # For all the paths built below, we assume that the Mentor CodeSourcery release of gcc is
  132. # being used. Other distributions of gcc may work, but have not been tested.
  133. # Set compiler version defaults.
  134. CROSS_COMPILE = arm-none-eabi-
  135. # Strip off the trailing '-', resulting in arm-none-eabi
  136. CROSS_COMPILE_STRIP := $(CROSS_COMPILE:%-=%)
  137. # Build tool names.
  138. CC = $(CROSS_COMPILE)gcc
  139. CXX = $(CROSS_COMPILE)g++
  140. LD = $(CROSS_COMPILE)ld
  141. AS = $(CROSS_COMPILE)as
  142. AR = $(CROSS_COMPILE)ar
  143. OBJCOPY = $(CROSS_COMPILE)objcopy
  144. # Ask the compiler for its version
  145. CC_VERSION := $(shell $(CC) -dumpversion)
  146. # Get the compiler directory. We have to go through this sillyness in order to support
  147. # paths with spaces in their names, such as under Cygwin where the CodeSourcery compiler
  148. # is normally installed under C:\Program Files\.
  149. CC_PREFIX := $(shell dirname "`which $(CC)`")/..
  150. # Standard library include paths.
  151. LIBGCC_LDPATH = $(CC_PREFIX)/lib/gcc/$(CROSS_COMPILE_STRIP)/$(CC_VERSION)/$(CC_LIB_POST)
  152. LIBC_LDPATH = $(CC_PREFIX)/$(CROSS_COMPILE_STRIP)/lib/$(CC_LIB_POST)
  153. # System header file include paths.
  154. CC_INCLUDE = $(CC_PREFIX)/lib/gcc/$(CROSS_COMPILE_STRIP)/$(CC_VERSION)/include
  155. CC_INCLUDE_FIXED = $(CC_PREFIX)/lib/gcc/$(CROSS_COMPILE_STRIP)/$(CC_VERSION)/include-fixed
  156. LIBC_INCLUDE = $(CC_PREFIX)/$(CROSS_COMPILE_STRIP)/include
  157. #-------------------------------------------------------------------------------
  158. # Target and board configuration
  159. #-------------------------------------------------------------------------------
  160. include $(SDK_ROOT)/mk/config.mk
  161. #-------------------------------------------------------------------------------
  162. # Compiler flags
  163. #-------------------------------------------------------------------------------
  164. include $(SDK_ROOT)/mk/flags.mk