vars.mk 8.5 KB

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