vars.mk 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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. ifeq ($(ADK_TARGET_UCLINUX),y)
  54. ADK_TARGET_LINUXTYPE:= uclinux
  55. else
  56. ADK_TARGET_LINUXTYPE:= linux
  57. endif
  58. GNU_TARGET_NAME:= $(ADK_TARGET_CPU_ARCH)-$(ADK_VENDOR)-$(ADK_TARGET_LINUXTYPE)-$(ADK_TARGET_SUFFIX)
  59. ifeq ($(ADK_TARGET_ARCH_C6X),y)
  60. GNU_TARGET_NAME:= $(ADK_TARGET_CPU_ARCH)-$(ADK_TARGET_LINUXTYPE)
  61. endif
  62. TARGET_CROSS:= $(TOOLCHAIN_DIR)/usr/bin/$(GNU_TARGET_NAME)-
  63. TARGET_COMPILER_PREFIX?=${TARGET_CROSS}
  64. CONFIGURE_TRIPLE:= --build=${GNU_HOST_NAME} \
  65. --host=${GNU_TARGET_NAME} \
  66. --target=${GNU_TARGET_NAME}
  67. ifneq ($(strip ${ADK_USE_CCACHE}),)
  68. TARGET_COMPILER_PREFIX=$(STAGING_HOST_DIR)/usr/bin/ccache ${TARGET_CROSS}
  69. endif
  70. # target tools
  71. TARGET_CC:= ${TARGET_COMPILER_PREFIX}gcc
  72. # use a gcc wrapper for coldfire/arm uclinux support
  73. ifeq ($(ADK_TARGET_UCLINUX),y)
  74. ifeq ($(ADK_TARGET_ARCH_M68K),y)
  75. TARGET_CC:= adk-uclinux-gcc
  76. endif
  77. ifeq ($(ADK_TARGET_ARCH_ARM),y)
  78. TARGET_CC:= adk-uclinux-gcc
  79. endif
  80. endif
  81. TARGET_CXX:= ${TARGET_COMPILER_PREFIX}g++
  82. TARGET_LD:= ${TARGET_COMPILER_PREFIX}ld
  83. TARGET_AR:= ${TARGET_COMPILER_PREFIX}ar
  84. TARGET_RANLIB:= ${TARGET_COMPILER_PREFIX}ranlib
  85. ifneq ($(ADK_TARGET_ABI_CFLAGS),)
  86. TARGET_CC+= $(ADK_TARGET_ABI_CFLAGS)
  87. TARGET_CXX+= $(ADK_TARGET_ABI_CFLAGS)
  88. endif
  89. TARGET_CPPFLAGS:=
  90. TARGET_CFLAGS:= $(ADK_TARGET_CFLAGS) -fwrapv -fno-ident -fhonour-copts
  91. TARGET_CXXFLAGS:= $(ADK_TARGET_CFLAGS) -fwrapv -fno-ident -fhonour-copts
  92. TARGET_LDFLAGS:= -L$(STAGING_TARGET_DIR)/lib -L$(STAGING_TARGET_DIR)/usr/lib \
  93. -Wl,-O1 -Wl,-rpath -Wl,/usr/lib \
  94. -Wl,-rpath-link -Wl,${STAGING_TARGET_DIR}/usr/lib
  95. ifeq ($(ADK_TARGET_BINFMT_FLAT),y)
  96. TARGET_LDFLAGS+= -elf2flt
  97. endif
  98. ifeq ($(ADK_TARGET_ARCH_M68K),y)
  99. ifeq ($(ADK_TARGET_BINFMT_FLAT_SEP_DATA),y)
  100. TARGET_CFLAGS+= -msep-data
  101. TARGET_CXXFLAGS+= -msep-data
  102. endif
  103. endif
  104. ifeq ($(ADK_TARGET_LIB_MUSL),y)
  105. # use -static-libgcc by default only for musl
  106. TARGET_CFLAGS+= -static-libgcc
  107. TARGET_CXXFLAGS+= -static-libgcc
  108. TARGET_LDFLAGS+= -static-libgcc
  109. endif
  110. # security optimization, see http://www.akkadia.org/drepper/dsohowto.pdf
  111. ifneq ($(ADK_TARGET_USE_LD_RELRO),)
  112. TARGET_LDFLAGS+= -Wl,-z,relro
  113. endif
  114. ifneq ($(ADK_TARGET_USE_LD_BIND_NOW),)
  115. TARGET_LDFLAGS+= -Wl,-z,now
  116. endif
  117. # needed for musl ppc
  118. ifeq ($(ADK_TARGET_ARCH_PPC),y)
  119. ifeq ($(ADK_TARGET_LIB_MUSL),y)
  120. TARGET_LDFLAGS+= -Wl,--secure-plt
  121. endif
  122. endif
  123. ifeq ($(ADK_TARGET_USE_STATIC_LIBS),y)
  124. TARGET_CFLAGS+= -static
  125. TARGET_CXXFLAGS+= -static
  126. TARGET_LDFLAGS+= -static
  127. endif
  128. ifneq ($(ADK_TARGET_USE_SSP),)
  129. TARGET_CFLAGS+= -fstack-protector-all --param=ssp-buffer-size=4
  130. TARGET_CXXFLAGS+= -fstack-protector-all --param=ssp-buffer-size=4
  131. TARGET_LDFLAGS+= -fstack-protector-all
  132. endif
  133. ifneq ($(ADK_TARGET_USE_LD_GC),)
  134. TARGET_CFLAGS+= -fdata-sections -ffunction-sections
  135. TARGET_CXXFLAGS+= -fdata-sections -ffunction-sections
  136. TARGET_LDFLAGS+= -Wl,--gc-sections
  137. endif
  138. ifneq ($(ADK_TARGET_USE_LTO),)
  139. TARGET_CFLAGS+= -flto
  140. TARGET_CXXFLAGS+= -flto
  141. TARGET_LDFLAGS+= -flto
  142. endif
  143. # performance optimization, see http://www.akkadia.org/drepper/dsohowto.pdf
  144. ifneq ($(ADK_TARGET_USE_GNU_HASHSTYLE),)
  145. TARGET_LDFLAGS+= -Wl,--hash-style=gnu
  146. endif
  147. ifeq ($(ADK_TARGET_ARCH_MICROBLAZE),y)
  148. TARGET_CFLAGS+= -mxl-barrel-shift
  149. TARGET_CXXFLAGS+= -mxl-barrel-shift
  150. endif
  151. ifeq ($(ADK_TARGET_ARCH_XTENSA),y)
  152. TARGET_CFLAGS+= -mlongcalls -mtext-section-literals
  153. TARGET_CXXFLAGS+= -mlongcalls -mtext-section-literals
  154. endif
  155. # add configured cflags for optimization
  156. TARGET_CFLAGS+= $(ADK_TARGET_CFLAGS_OPT)
  157. TARGET_CXXFLAGS+= $(ADK_TARGET_CFLAGS_OPT)
  158. # always add debug information
  159. TARGET_CFLAGS+= -g3
  160. TARGET_CXXFLAGS+= -g3
  161. ifneq ($(ADK_DEBUG),)
  162. TARGET_CFLAGS+= -fno-omit-frame-pointer
  163. TARGET_CXXFLAGS+= -fno-omit-frame-pointer
  164. TARGET_CFLAGS+= -funwind-tables -fasynchronous-unwind-tables
  165. TARGET_CXXFLAGS+= -funwind-tables -fasynchronous-unwind-tables
  166. else
  167. TARGET_CPPFLAGS+= -DNDEBUG
  168. TARGET_CFLAGS+= -fomit-frame-pointer
  169. TARGET_CXXFLAGS+= -fomit-frame-pointer
  170. # stop generating eh_frame stuff
  171. TARGET_CFLAGS+= -fno-unwind-tables -fno-asynchronous-unwind-tables
  172. TARGET_CXXFLAGS+= -fno-unwind-tables -fno-asynchronous-unwind-tables
  173. endif
  174. ifeq ($(ADK_TARGET_ARCH_ARM),y)
  175. ifeq ($(ADK_TARGET_ARCH_ARM_WITH_THUMB),y)
  176. TARGET_CFLAGS+= -mthumb -Wa,-mimplicit-it=thumb
  177. TARGET_CXXFLAGS+= -mthumb -Wa,-mimplicit-it=thumb
  178. else
  179. TARGET_CFLAGS+= -marm
  180. TARGET_CXXFLAGS+= -marm
  181. endif
  182. endif
  183. # host compiler and linker flags
  184. HOST_CPPFLAGS:= -I$(STAGING_HOST_DIR)/usr/include
  185. HOST_CFLAGS:= -O0 -g0
  186. HOST_CXXFLAGS:= -O0 -g0
  187. HOST_LDFLAGS:= -L$(STAGING_HOST_DIR)/usr/lib -Wl,-rpath -Wl,${STAGING_HOST_DIR}/usr/lib
  188. PATCH= PATH='${HOST_PATH}' ${BASH} $(SCRIPT_DIR)/patch.sh
  189. PATCHP0= PATH='${HOST_PATH}' patch -p0
  190. ifeq ($(ADK_STATIC_TOOLCHAIN),y)
  191. HOST_STATIC_CFLAGS:= -static -Wl,-static
  192. HOST_STATIC_CXXFLAGS:= -static -Wl,-static
  193. HOST_STATIC_LDFLAGS:= -Wl,-static
  194. HOST_STATIC_LLDFLAGS:= -all-static
  195. endif
  196. SED:= PATH='${HOST_PATH}' sed -i -e
  197. XZ:= PATH='${HOST_PATH}' xz
  198. LINUX_DIR:= $(BUILD_DIR)/linux
  199. KERNEL_MODULE_FLAGS:= ARCH=${ADK_TARGET_ARCH} \
  200. PREFIX=/usr \
  201. KERNEL_PATH=${LINUX_DIR} \
  202. KERNELDIR=${LINUX_DIR} \
  203. KERNEL_DIR=${LINUX_DIR} \
  204. CROSS_COMPILE="${TARGET_CROSS}" \
  205. CFLAGS_MODULE="-fhonour-copts" \
  206. V=1
  207. COMMON_ENV= CONFIG_SHELL='$(strip ${SHELL})' \
  208. AUTOM4TE='${STAGING_HOST_DIR}/usr/bin/autom4te' \
  209. M4='${STAGING_HOST_DIR}/usr/bin/m4' \
  210. LIBTOOLIZE='${STAGING_HOST_DIR}/usr/bin/libtoolize -q' \
  211. VERBOSE=1
  212. TARGET_ENV= AR='$(TARGET_CROSS)ar' \
  213. AS='$(TARGET_CROSS)as' \
  214. LD='$(TARGET_CROSS)ld' \
  215. NM='$(TARGET_CROSS)nm' \
  216. RANLIB='$(TARGET_CROSS)ranlib' \
  217. STRIP='$(TARGET_CROSS)strip' \
  218. OBJCOPY='$(TARGET_CROSS)objcopy' \
  219. CC='$(TARGET_CC)' \
  220. GCC='$(TARGET_CC)' \
  221. CXX='$(TARGET_CXX)' \
  222. CROSS='$(TARGET_CROSS)' \
  223. CROSS_COMPILE='$(TARGET_CROSS)' \
  224. CFLAGS='$(TARGET_CFLAGS)' \
  225. CXXFLAGS='$(TARGET_CXXFLAGS)' \
  226. CPPFLAGS='$(TARGET_CPPFLAGS)' \
  227. LDFLAGS='$(TARGET_LDFLAGS)' \
  228. CC_FOR_BUILD='$(HOST_CC)' \
  229. CXX_FOR_BUILD='$(HOST_CXX)' \
  230. CPPFLAGS_FOR_BUILD='$(HOST_CPPFLAGS)' \
  231. CFLAGS_FOR_BUILD='$(HOST_CFLAGS)' \
  232. CXXFLAGS_FOR_BUILD='$(HOST_CXXFLAGS)' \
  233. LDFLAGS_FOR_BUILD='$(HOST_LDFLAGS)' \
  234. LIBS_FOR_BUILD='$(HOST_LIBS)'
  235. HOST_ENV= CC='$(HOST_CC)' \
  236. CXX='$(HOST_CXX)' \
  237. CPPFLAGS='$(HOST_CPPFLAGS)' \
  238. CFLAGS='$(HOST_CFLAGS)' \
  239. CXXFLAGS='$(HOST_CXXFLAGS)' \
  240. LDFLAGS='$(HOST_LDFLAGS)'
  241. PKG_SUFFIX:= $(strip $(subst ",, $(ADK_PACKAGE_SUFFIX)))
  242. ifeq ($(ADK_TARGET_PACKAGE_IPKG),y)
  243. PKG_BUILD:= PATH='${HOST_PATH}' \
  244. ${BASH} ${SCRIPT_DIR}/ipkg-build
  245. PKG_INSTALL:= PATH='${HOST_PATH}' \
  246. IPKG_TMP=$(BUILD_DIR)/tmp \
  247. IPKG_INSTROOT=$(TARGET_DIR) \
  248. IPKG_CONF_DIR=$(STAGING_TARGET_DIR)/etc \
  249. IPKG_OFFLINE_ROOT=$(TARGET_DIR) \
  250. BIN_DIR=$(STAGING_HOST_DIR)/usr/bin \
  251. ${BASH} ${SCRIPT_DIR}/ipkg \
  252. -force-defaults -force-depends install
  253. PKG_STATE_DIR:= $(TARGET_DIR)/usr/lib/ipkg
  254. endif
  255. ifeq ($(ADK_TARGET_PACKAGE_OPKG),y)
  256. PKG_BUILD:= PATH='${HOST_PATH}' \
  257. ${BASH} ${SCRIPT_DIR}/ipkg-build
  258. PKG_INSTALL:= PATH='${HOST_PATH}' \
  259. IPKG_TMP=$(BUILD_DIR)/tmp \
  260. IPKG_INSTROOT=$(TARGET_DIR) \
  261. IPKG_CONF_DIR=$(STAGING_TARGET_DIR)/etc \
  262. IPKG_OFFLINE_ROOT=$(TARGET_DIR) \
  263. BIN_DIR=$(STAGING_HOST_DIR)/usr/bin \
  264. ${BASH} ${SCRIPT_DIR}/ipkg \
  265. -force-defaults -force-depends install
  266. PKG_STATE_DIR:= $(TARGET_DIR)/usr/lib/opkg
  267. endif
  268. ifeq ($(ADK_TARGET_PACKAGE_TXZ),y)
  269. PKG_BUILD:= PATH='${HOST_PATH}' ${BASH} ${SCRIPT_DIR}/tarpkg build
  270. PKG_INSTALL:= PKG_INSTROOT='$(TARGET_DIR)' \
  271. PATH='${HOST_PATH}' ${BASH} ${SCRIPT_DIR}/tarpkg install
  272. PKG_STATE_DIR:= $(TARGET_DIR)/usr/lib/pkg
  273. endif
  274. RSTRIP:= PATH="$(TARGET_PATH)" prefix='${TARGET_CROSS}' ${BASH} ${SCRIPT_DIR}/rstrip.sh
  275. STATCMD:=$(shell if stat -qs .>/dev/null 2>&1; then echo 'stat -f %z';else echo 'stat -c %s';fi)
  276. EXTRACT_CMD= PATH='${HOST_PATH}'; mkdir -p ${WRKDIR}; \
  277. cd ${WRKDIR} && \
  278. for file in ${FULLDISTFILES}; do case $$file in \
  279. *.cpio) \
  280. cat $$file | cpio -i -d ;; \
  281. *.tar) \
  282. tar -xf $$file ;; \
  283. *.cpio.Z | *.cpio.gz | *.cgz | *.mcz) \
  284. gzip -dc $$file | cpio -i -d ;; \
  285. *.tar.xz | *.txz) \
  286. xz -dc $$file | tar -xf - ;; \
  287. *.tar.Z | *.tar.gz | *.taz | *.tgz) \
  288. gzip -dc $$file | tar -xf - ;; \
  289. *.cpio.bz2 | *.cbz) \
  290. bzip2 -dc $$file | cpio -i -d ;; \
  291. *.tar.bz2 | *.tbz | *.tbz2) \
  292. bzip2 -dc $$file | tar -xf - ;; \
  293. *.zip) \
  294. cat $$file | cpio -id -H zip ;; \
  295. *.arm|*.jar|*.ids.gz) \
  296. mkdir ${WRKBUILD}; cp $$file ${WRKBUILD} ;; \
  297. *.bin) \
  298. sh $$file --force --auto-accept ;; \
  299. *) \
  300. echo "Cannot extract '$$file'" >&2; \
  301. false ;; \
  302. esac; done
  303. ifeq ($(ADK_VERBOSE),1)
  304. QUIET:=
  305. else
  306. QUIET:= --quiet
  307. endif
  308. FETCH_CMD?= wget --timeout=$(ADK_WGET_TIMEOUT) -t 3 --no-check-certificate $(QUIET)
  309. ifeq ($(ADK_HOST_CYGWIN),y)
  310. EXEEXT:= .exe
  311. endif
  312. include $(ADK_TOPDIR)/mk/mirrors.mk