vars.mk 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. # This file is part of the OpenADK project. OpenADK is copyrighted
  2. # material, please see the LICENCE file in the top-level directory.
  3. CP= cp -fpR
  4. INSTALL_DIR= install -d -m0755
  5. INSTALL_DATA= install -m0644
  6. INSTALL_BIN= install -m0755
  7. INSTALL_SCRIPT= install -m0755
  8. MAKEFLAGS= $(EXTRA_MAKEFLAGS)
  9. BUILD_USER= $(shell id -un)
  10. BUILD_GROUP= $(shell id -gn)
  11. # some global dirs
  12. BASE_DIR:= $(TOPDIR)
  13. ifeq ($(ADK_DL_DIR),)
  14. DL_DIR?= $(BASE_DIR)/dl
  15. else
  16. DL_DIR?= $(ADK_DL_DIR)
  17. endif
  18. TOOLS_BUILD_DIR= $(BASE_DIR)/tools_build
  19. SCRIPT_DIR:= $(BASE_DIR)/scripts
  20. STAGING_HOST_DIR:= ${BASE_DIR}/host_${GNU_HOST_NAME}
  21. # PFX dirs for cleandir
  22. FW_DIR_PFX:= $(BASE_DIR)/firmware
  23. BUILD_DIR_PFX:= $(BASE_DIR)/build_*
  24. STAGING_PKG_DIR_PFX:= ${BASE_DIR}/pkg_*
  25. STAGING_TARGET_DIR_PFX:=${BASE_DIR}/target_*
  26. TOOLCHAIN_BUILD_DIR_PFX=$(BASE_DIR)/toolchain_build_*
  27. STAGING_HOST_DIR_PFX:= ${BASE_DIR}/host_*
  28. TARGET_DIR_PFX:= $(BASE_DIR)/root_*
  29. ifeq ($(ADK_TARGET_ABI),)
  30. TARGET_DIR:= $(BASE_DIR)/root_${ADK_TARGET_SYSTEM}_${CPU_ARCH}_${ADK_TARGET_LIBC}
  31. FW_DIR:= $(BASE_DIR)/firmware/${ADK_TARGET_SYSTEM}_${CPU_ARCH}_${ADK_TARGET_LIBC}
  32. BUILD_DIR:= ${BASE_DIR}/build_${ADK_TARGET_SYSTEM}_${CPU_ARCH}_${ADK_TARGET_LIBC}
  33. STAGING_TARGET_DIR:= ${BASE_DIR}/target_${CPU_ARCH}_${ADK_TARGET_LIBC}
  34. STAGING_PKG_DIR:= ${BASE_DIR}/pkg_${ADK_TARGET_SYSTEM}_${CPU_ARCH}_${ADK_TARGET_LIBC}
  35. STAGING_HOST2TARGET:= ../target_${CPU_ARCH}_${ADK_TARGET_LIBC}
  36. TOOLCHAIN_BUILD_DIR= $(BASE_DIR)/toolchain_build_${CPU_ARCH}_${ADK_TARGET_LIBC}
  37. else
  38. TARGET_DIR:= $(BASE_DIR)/root_${ADK_TARGET_SYSTEM}_${CPU_ARCH}_${ADK_TARGET_LIBC}_${ADK_TARGET_ABI}
  39. FW_DIR:= $(BASE_DIR)/firmware/${ADK_TARGET_SYSTEM}_${CPU_ARCH}_${ADK_TARGET_LIBC}_${ADK_TARGET_ABI}
  40. BUILD_DIR:= ${BASE_DIR}/build_${ADK_TARGET_SYSTEM}_${CPU_ARCH}_${ADK_TARGET_LIBC}_${ADK_TARGET_ABI}
  41. STAGING_TARGET_DIR:= ${BASE_DIR}/target_${CPU_ARCH}_${ADK_TARGET_LIBC}_${ADK_TARGET_ABI}
  42. STAGING_PKG_DIR:= ${BASE_DIR}/pkg_${ADK_TARGET_SYSTEM}_${CPU_ARCH}_${ADK_TARGET_LIBC}_${ADK_TARGET_ABI}
  43. STAGING_HOST2TARGET:= ../target_${CPU_ARCH}_${ADK_TARGET_LIBC}_${ADK_TARGET_ABI}
  44. TOOLCHAIN_BUILD_DIR= $(BASE_DIR)/toolchain_build_${CPU_ARCH}_${ADK_TARGET_LIBC}_${ADK_TARGET_ABI}
  45. endif
  46. PACKAGE_DIR:= $(FW_DIR)/packages
  47. SCRIPT_TARGET_DIR:= ${STAGING_TARGET_DIR}/scripts
  48. # PATH variables
  49. TARGET_PATH= ${SCRIPT_DIR}:${STAGING_TARGET_DIR}/scripts:${STAGING_HOST_DIR}/bin:${STAGING_HOST_DIR}/usr/bin:${_PATH}
  50. HOST_PATH= ${SCRIPT_DIR}:${STAGING_HOST_DIR}/bin:${STAGING_HOST_DIR}/usr/bin:${_PATH}
  51. AUTOTOOL_PATH= ${STAGING_HOST_DIR}/bin:${STAGING_HOST_DIR}/usr/bin:${STAGING_TARGET_DIR}/scripts:${_PATH}
  52. ifeq ($(ADK_TARGET_ABI_X32),y)
  53. GNU_TARGET_NAME= $(CPU_ARCH)-x32-linux-$(ADK_TARGET_SUFFIX)
  54. else
  55. GNU_TARGET_NAME= $(CPU_ARCH)-$(ADK_VENDOR)-linux-$(ADK_TARGET_SUFFIX)
  56. endif
  57. ifeq ($(ADK_DISABLE_HONOUR_CFLAGS),)
  58. GCC_CHECK:= GCC_HONOUR_COPTS=2
  59. else
  60. GCC_CHECK:=
  61. endif
  62. TARGET_CROSS:= $(STAGING_HOST_DIR)/bin/$(GNU_TARGET_NAME)-
  63. TARGET_COMPILER_PREFIX?=${TARGET_CROSS}
  64. CONFIGURE_TRIPLE:= --build=${GNU_HOST_NAME} --host=${GNU_TARGET_NAME} --target=${GNU_TARGET_NAME}
  65. ifneq ($(strip ${ADK_USE_CCACHE}),)
  66. TARGET_COMPILER_PREFIX=ccache ${TARGET_CROSS}
  67. endif
  68. # target compiler flags
  69. TARGET_CC:= ${TARGET_COMPILER_PREFIX}gcc
  70. TARGET_CXX:= ${TARGET_COMPILER_PREFIX}g++
  71. TARGET_LD:= ${TARGET_COMPILER_PREFIX}ld
  72. MODE_FLAGS:=
  73. ifeq ($(ADK_LINUX_ARM),y)
  74. ifeq ($(ADK_LINUX_ARM_WITH_THUMB),y)
  75. MODE_FLAGS:= -mthumb
  76. else
  77. MODE_FLAGS:= -marm
  78. endif
  79. endif
  80. TARGET_CPPFLAGS:=
  81. TARGET_CFLAGS:= $(TARGET_CFLAGS_ARCH) -fwrapv -fno-ident -fhonour-copts $(ADK_TARGET_ABI_CFLAGS) $(MODE_FLAGS)
  82. TARGET_CFLAGS_LIBC:= $(TARGET_CFLAGS_ARCH) -fwrapv -fno-ident -fhonour-copts $(TARGET_OPTIMIZATION) $(MODE_FLAGS)
  83. TARGET_CXXFLAGS:= $(TARGET_CFLAGS_ARCH) -fwrapv -fno-ident $(MODE_FLAGS)
  84. TARGET_LDFLAGS:= -L$(STAGING_TARGET_DIR)/lib -L$(STAGING_TARGET_DIR)/usr/lib \
  85. -Wl,-O1 -Wl,-rpath -Wl,/usr/lib \
  86. -Wl,-rpath-link -Wl,${STAGING_TARGET_DIR}/usr/lib \
  87. $(ADK_TARGET_ABI_LDFLAGS)
  88. # security optimization, see http://www.akkadia.org/drepper/dsohowto.pdf
  89. TARGET_LDFLAGS+= -Wl,-z,relro,-z,now
  90. # needed for musl ppc
  91. ifeq ($(ADK_LINUX_PPC),y)
  92. ifeq ($(ADK_TARGET_LIB_MUSL),y)
  93. TARGET_LDFLAGS+= -Wl,--secure-plt
  94. endif
  95. endif
  96. ifneq ($(ADK_TOOLCHAIN_GCC_USE_SSP),)
  97. TARGET_CFLAGS+= -fstack-protector
  98. TARGET_CXXFLAGS+= -fstack-protector
  99. TARGET_LDFLAGS+= -fstack-protector
  100. endif
  101. ifneq ($(ADK_TOOLCHAIN_GCC_USE_LTO),)
  102. TARGET_CFLAGS+= -flto
  103. TARGET_CXXFLAGS+= -flto
  104. TARGET_LDFLAGS+= -flto
  105. endif
  106. ifneq ($(ADK_DEBUG),)
  107. TARGET_CFLAGS+= -g3 -fno-omit-frame-pointer
  108. else
  109. TARGET_CPPFLAGS+= -DNDEBUG
  110. TARGET_CFLAGS+= -fomit-frame-pointer $(TARGET_OPTIMIZATION)
  111. # stop generating eh_frame stuff
  112. TARGET_CFLAGS+= -fno-unwind-tables -fno-asynchronous-unwind-tables
  113. # always add debug information
  114. TARGET_CFLAGS+= -g3
  115. endif
  116. # A nifty macro to make testing gcc features easier (from uClibc project)
  117. check_gcc=$(shell \
  118. if $(CC_FOR_BUILD) $(1) -Werror -S -o /dev/null -xc /dev/null > /dev/null 2>&1; \
  119. then echo "$(1)"; else echo "$(2)"; fi)
  120. CF_FOR_BUILD=$(call check_gcc,-fhonour-copts,)
  121. # host compiler flags
  122. CXX_FOR_BUILD?= g++
  123. CPPFLAGS_FOR_BUILD?= -I$(STAGING_HOST_DIR)/usr/include
  124. CFLAGS_FOR_BUILD= -O2 -Wall $(CF_FOR_BUILD)
  125. CXXFLAGS_FOR_BUILD?= -O2 -Wall
  126. LDFLAGS_FOR_BUILD?= -L$(STAGING_HOST_DIR)/usr/lib
  127. FLAGS_FOR_BUILD= ${CPPFLAGS_FOR_BUILD} ${CFLAGS_FOR_BUILD} ${LDFLAGS_FOR_BUILD}
  128. PATCH= ${BASH} $(SCRIPT_DIR)/patch.sh
  129. SED:= PATH=${HOST_PATH} sed -i -e
  130. LINUX_DIR:= $(BUILD_DIR)/linux
  131. KERNEL_MODULE_FLAGS:= ARCH=${ARCH} \
  132. KERNEL_PATH=${LINUX_DIR} KERNELDIR=${LINUX_DIR} KERNEL_DIR=${LINUX_DIR} \
  133. PREFIX=/usr CROSS_COMPILE="${TARGET_CROSS}" \
  134. LDFLAGS="$(ADK_TARGET_KERNEL_LDFLAGS)" CFLAGS_MODULE="-fhonour-copts" V=1
  135. TARGET_CONFIGURE_OPTS= PATH='${TARGET_PATH}' \
  136. AR='$(TARGET_CROSS)ar' \
  137. AS='$(TARGET_CROSS)as' \
  138. LD='$(TARGET_CROSS)ld' \
  139. NM='$(TARGET_CROSS)nm' \
  140. RANLIB='$(TARGET_CROSS)ranlib' \
  141. STRIP='${TARGET_CROSS}strip' \
  142. OBJCOPY='${TARGET_CROSS}objcopy' \
  143. CC='$(TARGET_CC)' \
  144. GCC='$(TARGET_CC)' \
  145. CXX='$(TARGET_CXX)' \
  146. CROSS='$(TARGET_CROSS)' \
  147. CROSS_COMPILE='$(TARGET_CROSS)'
  148. HOST_CONFIGURE_OPTS= CC_FOR_BUILD='${CC_FOR_BUILD}' \
  149. CPPFLAGS_FOR_BUILD='${CPPFLAGS_FOR_BUILD}' \
  150. CXX_FOR_BUILD='${CXX_FOR_BUILD}' \
  151. CFLAGS_FOR_BUILD='${CFLAGS_FOR_BUILD}' \
  152. LDFLAGS_FOR_BUILD='${LDFLAGS_FOR_BUILD}'
  153. PKG_SUFFIX:= $(strip $(subst ",, $(ADK_PACKAGE_SUFFIX)))
  154. ifeq ($(ADK_TARGET_PACKAGE_IPKG),y)
  155. PKG_BUILD:= PATH='${TARGET_PATH}' \
  156. ${BASH} ${SCRIPT_DIR}/ipkg-build
  157. PKG_INSTALL:= IPKG_TMP=$(BUILD_DIR)/tmp \
  158. IPKG_INSTROOT=$(TARGET_DIR) \
  159. IPKG_CONF_DIR=$(STAGING_TARGET_DIR)/etc \
  160. IPKG_OFFLINE_ROOT=$(TARGET_DIR) \
  161. BIN_DIR=$(STAGING_HOST_DIR)/usr/bin \
  162. ${BASH} ${SCRIPT_DIR}/ipkg \
  163. -force-defaults -force-depends install
  164. PKG_STATE_DIR:= $(TARGET_DIR)/usr/lib/ipkg
  165. else
  166. PKG_BUILD:= ${BASH} ${SCRIPT_DIR}/tarpkg build
  167. PKG_INSTALL:= PKG_INSTROOT=$(TARGET_DIR) \
  168. ${BASH} ${SCRIPT_DIR}/tarpkg install
  169. PKG_STATE_DIR:= $(TARGET_DIR)/usr/lib/pkg
  170. endif
  171. RSTRIP:= PATH="$(TARGET_PATH)" prefix='${TARGET_CROSS}' ${BASH} ${SCRIPT_DIR}/rstrip.sh
  172. STATCMD:=$(shell if stat -qs .>/dev/null 2>&1; then echo 'stat -f %z';else echo 'stat -c %s';fi)
  173. EXTRACT_CMD= mkdir -p ${WRKDIR}; \
  174. cd ${WRKDIR} && \
  175. for file in ${FULLDISTFILES}; do case $$file in \
  176. *.cpio) \
  177. cat $$file | $(STAGING_HOST_DIR)/usr/bin/cpio -i -d ;; \
  178. *.tar) \
  179. tar -xf $$file ;; \
  180. *.cpio.Z | *.cpio.gz | *.cgz | *.mcz) \
  181. gzip -dc $$file | $(STAGING_HOST_DIR)/usr/bin/cpio -i -d ;; \
  182. *.tar.xz | *.txz) \
  183. $(STAGING_HOST_DIR)/usr/bin/xz -dc $$file | tar -xf - ;; \
  184. *.tar.Z | *.tar.gz | *.taz | *.tgz) \
  185. gzip -dc $$file | tar -xf - ;; \
  186. *.cpio.bz2 | *.cbz) \
  187. $(STAGING_HOST_DIR)/usr/bin/bzip2 -dc $$file | $(STAGING_HOST_DIR)/usr/bin/cpio -i -d ;; \
  188. *.tar.bz2 | *.tbz | *.tbz2) \
  189. $(STAGING_HOST_DIR)/usr/bin/bzip2 -dc $$file | tar -xf - ;; \
  190. *.zip) \
  191. cat $$file | $(STAGING_HOST_DIR)/usr/bin/cpio -ivd -H zip ;; \
  192. *.arm) \
  193. cp $$file ${WRKDIR} ;; \
  194. *) \
  195. echo "Cannot extract '$$file'" >&2; \
  196. false ;; \
  197. esac; done
  198. ifeq ($(VERBOSE),1)
  199. QUIET:=
  200. else
  201. QUIET:= --quiet
  202. endif
  203. FETCH_CMD?= wget --timeout=$(ADK_WGET_TIMEOUT) -t 3 --no-check-certificate $(QUIET)
  204. ifeq ($(ADK_HOST_CYGWIN),y)
  205. EXEEXT:= .exe
  206. endif
  207. include $(TOPDIR)/mk/mirrors.mk