vars.mk 9.2 KB

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