vars.mk 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. ADK_SUFFIX:= _${ADK_TARGET_SYSTEM}_${ADK_TARGET_LIBC}
  12. # some global dirs
  13. BASE_DIR:= $(TOPDIR)
  14. ifeq ($(ADK_DL_DIR),)
  15. DL_DIR?= $(BASE_DIR)/dl
  16. else
  17. DL_DIR?= $(ADK_DL_DIR)
  18. endif
  19. SCRIPT_DIR:= $(BASE_DIR)/scripts
  20. STAGING_HOST_DIR:= ${BASE_DIR}/host_${GNU_HOST_NAME}
  21. HOST_BUILD_DIR:= ${BASE_DIR}/host_build_${GNU_HOST_NAME}
  22. TOOLCHAIN_DIR:= ${BASE_DIR}/toolchain${ADK_SUFFIX}
  23. # dirs for cleandir
  24. FW_DIR_PFX:= $(BASE_DIR)/firmware
  25. BUILD_DIR_PFX:= $(BASE_DIR)/build_*
  26. STAGING_PKG_DIR_PFX:= ${BASE_DIR}/pkg_*
  27. STAGING_TARGET_DIR_PFX:=${BASE_DIR}/target_*
  28. TOOLCHAIN_DIR_PFX= $(BASE_DIR)/toolchain_*
  29. STAGING_HOST_DIR_PFX:= ${BASE_DIR}/host_*
  30. TARGET_DIR_PFX:= $(BASE_DIR)/root_*
  31. TARGET_DIR:= $(BASE_DIR)/root${ADK_SUFFIX}
  32. FW_DIR:= $(BASE_DIR)/firmware/${ADK_TARGET_SYSTEM}_${ADK_TARGET_LIBC}
  33. BUILD_DIR:= ${BASE_DIR}/build${ADK_SUFFIX}
  34. STAGING_TARGET_DIR:= ${BASE_DIR}/target${ADK_SUFFIX}
  35. STAGING_PKG_DIR:= ${BASE_DIR}/pkg${ADK_SUFFIX}
  36. STAGING_HOST2TARGET:= ../../target${ADK_SUFFIX}
  37. TOOLCHAIN_BUILD_DIR= $(BASE_DIR)/toolchain_build${ADK_SUFFIX}
  38. PACKAGE_DIR:= $(FW_DIR)/packages
  39. SCRIPT_TARGET_DIR:= ${STAGING_TARGET_DIR}/scripts
  40. # PATH variables
  41. TARGET_PATH= ${SCRIPT_DIR}:${STAGING_TARGET_DIR}/scripts:${TOOLCHAIN_DIR}/usr/bin:${STAGING_HOST_DIR}/usr/bin:${_PATH}
  42. HOST_PATH= ${SCRIPT_DIR}:${TOOLCHAIN_DIR}/usr/bin:${STAGING_HOST_DIR}/usr/bin:${_PATH}
  43. AUTOTOOL_PATH= ${TOOLCHAIN_DIR}/usr/bin:${STAGING_HOST_DIR}/usr/bin:${STAGING_TARGET_DIR}/scripts:${_PATH}
  44. ifeq ($(ADK_DISABLE_HONOUR_CFLAGS),)
  45. GCC_CHECK:= GCC_HONOUR_COPTS=2
  46. else
  47. GCC_CHECK:=
  48. endif
  49. GNU_TARGET_NAME:= $(ADK_TARGET_CPU_ARCH)-$(ADK_VENDOR)-linux-$(ADK_TARGET_SUFFIX)
  50. TARGET_CROSS:= $(TOOLCHAIN_DIR)/usr/bin/$(GNU_TARGET_NAME)-
  51. TARGET_COMPILER_PREFIX?=${TARGET_CROSS}
  52. CONFIGURE_TRIPLE:= --build=${GNU_HOST_NAME} \
  53. --host=${GNU_TARGET_NAME} \
  54. --target=${GNU_TARGET_NAME}
  55. ifneq ($(strip ${ADK_USE_CCACHE}),)
  56. TARGET_COMPILER_PREFIX=$(STAGING_HOST_DIR)/usr/bin/ccache ${TARGET_CROSS}
  57. endif
  58. # target tools
  59. TARGET_CC:= ${TARGET_COMPILER_PREFIX}gcc
  60. TARGET_CXX:= ${TARGET_COMPILER_PREFIX}g++
  61. TARGET_LD:= ${TARGET_COMPILER_PREFIX}ld
  62. TARGET_AR:= ${TARGET_COMPILER_PREFIX}ar
  63. TARGET_RANLIB:= ${TARGET_COMPILER_PREFIX}ranlib
  64. ifneq ($(ADK_TARGET_ABI_CFLAGS),)
  65. TARGET_CC+= $(ADK_TARGET_ABI_CFLAGS)
  66. TARGET_CXX+= $(ADK_TARGET_ABI_CFLAGS)
  67. endif
  68. TARGET_CPPFLAGS:=
  69. TARGET_CFLAGS:= $(ADK_TARGET_CFLAGS) -fwrapv -fno-ident -fhonour-copts
  70. TARGET_CXXFLAGS:= $(ADK_TARGET_CFLAGS) -fwrapv -fno-ident -fhonour-copts
  71. TARGET_LDFLAGS:= -L$(STAGING_TARGET_DIR)/lib -L$(STAGING_TARGET_DIR)/usr/lib \
  72. -Wl,-O1 -Wl,-rpath -Wl,/usr/lib \
  73. -Wl,-rpath-link -Wl,${STAGING_TARGET_DIR}/usr/lib
  74. # use -static-libgcc by default
  75. TARGET_CFLAGS+= -static-libgcc
  76. TARGET_CXXFLAGS+= -static-libgcc
  77. TARGET_LDFLAGS+= -static-libgcc
  78. # security optimization, see http://www.akkadia.org/drepper/dsohowto.pdf
  79. ifneq ($(ADK_TARGET_USE_LD_RELRO),)
  80. TARGET_LDFLAGS+= -Wl,-z,relro
  81. endif
  82. ifneq ($(ADK_TARGET_USE_LD_BIND_NOW),)
  83. TARGET_LDFLAGS+= -Wl,-z,now
  84. endif
  85. # needed for musl ppc
  86. ifeq ($(ADK_LINUX_PPC),y)
  87. ifeq ($(ADK_TARGET_LIB_MUSL),y)
  88. TARGET_LDFLAGS+= -Wl,--secure-plt
  89. endif
  90. endif
  91. ifeq ($(ADK_TARGET_USE_STATIC_LIBS),y)
  92. TARGET_CFLAGS+= -static
  93. TARGET_CXXFLAGS+= -static
  94. TARGET_LDFLAGS+= -static
  95. endif
  96. ifneq ($(ADK_TARGET_USE_SSP),)
  97. TARGET_CFLAGS+= -fstack-protector-all --param=ssp-buffer-size=4
  98. TARGET_CXXFLAGS+= -fstack-protector-all --param=ssp-buffer-size=4
  99. TARGET_LDFLAGS+= -fstack-protector-all
  100. endif
  101. ifneq ($(ADK_TARGET_USE_LD_GC),)
  102. TARGET_CFLAGS+= -fdata-sections -ffunction-sections
  103. TARGET_CXXFLAGS+= -fdata-sections -ffunction-sections
  104. TARGET_LDFLAGS+= -Wl,--gc-sections
  105. endif
  106. ifneq ($(ADK_TARGET_USE_LTO),)
  107. TARGET_CFLAGS+= -flto
  108. TARGET_CXXFLAGS+= -flto
  109. TARGET_LDFLAGS+= -flto
  110. endif
  111. # performance optimization, see http://www.akkadia.org/drepper/dsohowto.pdf
  112. ifneq ($(ADK_TARGET_USE_GNU_HASHSTYLE),)
  113. TARGET_LDFLAGS+= -Wl,--hash-style=gnu
  114. endif
  115. ifeq ($(ADK_LINUX_MICROBLAZE),y)
  116. TARGET_CFLAGS+= -mxl-barrel-shift
  117. TARGET_CXXFLAGS+= -mxl-barrel-shift
  118. endif
  119. ifeq ($(ADK_LINUX_XTENSA),y)
  120. TARGET_CFLAGS+= -mlongcalls -mtext-section-literals
  121. TARGET_CXXFLAGS+= -mlongcalls -mtext-section-literals
  122. endif
  123. ifneq ($(ADK_DEBUG),)
  124. ifeq ($(ADK_DEBUG_OPTS),y)
  125. TARGET_CFLAGS+= -g3 -fno-omit-frame-pointer $(ADK_TARGET_CFLAGS_OPT)
  126. TARGET_CXXFLAGS+= -g3 -fno-omit-frame-pointer $(ADK_TARGET_CFLAGS_OPT)
  127. else
  128. TARGET_CFLAGS+= -O0 -g3 -fno-omit-frame-pointer
  129. TARGET_CXXFLAGS+= -O0 -g3 -fno-omit-frame-pointer
  130. endif
  131. else
  132. TARGET_CPPFLAGS+= -DNDEBUG
  133. TARGET_CFLAGS+= -fomit-frame-pointer $(ADK_TARGET_CFLAGS_OPT)
  134. TARGET_CXXFLAGS+= -fomit-frame-pointer $(ADK_TARGET_CFLAGS_OPT)
  135. # stop generating eh_frame stuff
  136. TARGET_CFLAGS+= -fno-unwind-tables -fno-asynchronous-unwind-tables
  137. TARGET_CXXFLAGS+= -fno-unwind-tables -fno-asynchronous-unwind-tables
  138. # always add debug information
  139. TARGET_CFLAGS+= -g3
  140. TARGET_CXXFLAGS+= -g3
  141. endif
  142. ifeq ($(ADK_LINUX_ARM),y)
  143. ifeq ($(ADK_LINUX_ARM_WITH_THUMB),y)
  144. TARGET_CFLAGS+= -mthumb
  145. TARGET_CXXFLAGS+= -mthumb
  146. else
  147. TARGET_CFLAGS+= -marm
  148. TARGET_CXXFLAGS+= -marm
  149. endif
  150. endif
  151. # host compiler flags
  152. CPPFLAGS_FOR_BUILD:= -I$(STAGING_HOST_DIR)/usr/include
  153. CFLAGS_FOR_BUILD:= -O0 -g0
  154. CXXFLAGS_FOR_BUILD:= -O0 -g0
  155. LDFLAGS_FOR_BUILD:= -L$(STAGING_HOST_DIR)/usr/lib -Wl,-rpath -Wl,${STAGING_HOST_DIR}/usr/lib
  156. PATCH= PATH=${HOST_PATH} ${BASH} $(SCRIPT_DIR)/patch.sh
  157. PATCHP0= PATH=${HOST_PATH} patch -p0
  158. SED:= PATH=${HOST_PATH} sed -i -e
  159. LINUX_DIR:= $(BUILD_DIR)/linux
  160. KERNEL_MODULE_FLAGS:= ARCH=${ADK_TARGET_ARCH} \
  161. PREFIX=/usr \
  162. KERNEL_PATH=${LINUX_DIR} \
  163. KERNELDIR=${LINUX_DIR} \
  164. KERNEL_DIR=${LINUX_DIR} \
  165. CROSS_COMPILE="${TARGET_CROSS}" \
  166. CFLAGS_MODULE="-fhonour-copts" \
  167. V=1
  168. TARGET_CONFIGURE_OPTS= PATH='${TARGET_PATH}' \
  169. AR='$(TARGET_CROSS)ar' \
  170. AS='$(TARGET_CROSS)as' \
  171. LD='$(TARGET_CROSS)ld' \
  172. NM='$(TARGET_CROSS)nm' \
  173. RANLIB='$(TARGET_CROSS)ranlib' \
  174. STRIP='${TARGET_CROSS}strip' \
  175. OBJCOPY='${TARGET_CROSS}objcopy' \
  176. CC='$(TARGET_CC)' \
  177. GCC='$(TARGET_CC)' \
  178. CXX='$(TARGET_CXX)' \
  179. CROSS='$(TARGET_CROSS)' \
  180. CROSS_COMPILE='$(TARGET_CROSS)'
  181. HOST_CONFIGURE_OPTS= CC_FOR_BUILD='${CC_FOR_BUILD}' \
  182. CXX_FOR_BUILD='${CXX_FOR_BUILD}' \
  183. CPPFLAGS_FOR_BUILD='${CPPFLAGS_FOR_BUILD}' \
  184. CFLAGS_FOR_BUILD='${CFLAGS_FOR_BUILD}' \
  185. CXXFLAGS_FOR_BUILD='${CXXFLAGS_FOR_BUILD}' \
  186. LDFLAGS_FOR_BUILD='${LDFLAGS_FOR_BUILD}'
  187. PKG_SUFFIX:= $(strip $(subst ",, $(ADK_PACKAGE_SUFFIX)))
  188. ifeq ($(ADK_TARGET_PACKAGE_IPKG),y)
  189. PKG_BUILD:= PATH='${HOST_PATH}' \
  190. ${BASH} ${SCRIPT_DIR}/ipkg-build
  191. PKG_INSTALL:= PATH='${HOST_PATH}' \
  192. IPKG_TMP=$(BUILD_DIR)/tmp \
  193. IPKG_INSTROOT=$(TARGET_DIR) \
  194. IPKG_CONF_DIR=$(STAGING_TARGET_DIR)/etc \
  195. IPKG_OFFLINE_ROOT=$(TARGET_DIR) \
  196. BIN_DIR=$(STAGING_HOST_DIR)/usr/bin \
  197. ${BASH} ${SCRIPT_DIR}/ipkg \
  198. -force-defaults -force-depends install
  199. PKG_STATE_DIR:= $(TARGET_DIR)/usr/lib/ipkg
  200. else
  201. PKG_BUILD:= ${BASH} ${SCRIPT_DIR}/tarpkg build
  202. PKG_INSTALL:= PKG_INSTROOT=$(TARGET_DIR) \
  203. ${BASH} ${SCRIPT_DIR}/tarpkg install
  204. PKG_STATE_DIR:= $(TARGET_DIR)/usr/lib/pkg
  205. endif
  206. RSTRIP:= PATH="$(TARGET_PATH)" prefix='${TARGET_CROSS}' ${BASH} ${SCRIPT_DIR}/rstrip.sh
  207. STATCMD:=$(shell if stat -qs .>/dev/null 2>&1; then echo 'stat -f %z';else echo 'stat -c %s';fi)
  208. EXTRACT_CMD= PATH='${HOST_PATH}'; mkdir -p ${WRKDIR}; \
  209. cd ${WRKDIR} && \
  210. for file in ${FULLDISTFILES}; do case $$file in \
  211. *.cpio) \
  212. cat $$file | cpio -i -d ;; \
  213. *.tar) \
  214. tar -xf $$file ;; \
  215. *.cpio.Z | *.cpio.gz | *.cgz | *.mcz) \
  216. gzip -dc $$file | cpio -i -d ;; \
  217. *.tar.xz | *.txz) \
  218. xz -dc $$file | tar -xf - ;; \
  219. *.tar.Z | *.tar.gz | *.taz | *.tgz) \
  220. gzip -dc $$file | tar -xf - ;; \
  221. *.cpio.bz2 | *.cbz) \
  222. bzip2 -dc $$file | cpio -i -d ;; \
  223. *.tar.bz2 | *.tbz | *.tbz2) \
  224. bzip2 -dc $$file | tar -xf - ;; \
  225. *.zip) \
  226. cat $$file | cpio -id -H zip ;; \
  227. *.arm|*.jar) \
  228. mkdir ${WRKBUILD}; cp $$file ${WRKBUILD} ;; \
  229. *) \
  230. echo "Cannot extract '$$file'" >&2; \
  231. false ;; \
  232. esac; done
  233. ifeq ($(VERBOSE),1)
  234. QUIET:=
  235. else
  236. QUIET:= --quiet
  237. endif
  238. FETCH_CMD?= wget --timeout=$(ADK_WGET_TIMEOUT) -t 3 --no-check-certificate $(QUIET)
  239. ifeq ($(ADK_HOST_CYGWIN),y)
  240. EXEEXT:= .exe
  241. endif
  242. include $(TOPDIR)/mk/mirrors.mk