vars.mk 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. BASE_DIR:= $(TOPDIR)
  12. DISTDIR?= ${BASE_DIR}/dl
  13. BUILD_DIR:= ${BASE_DIR}/build_${ADK_TARGET_SYSTEM}_${CPU_ARCH}_${ADK_TARGET_LIBC}
  14. BUILD_DIR_PFX:= $(BASE_DIR)/build_*
  15. STAGING_PKG_DIR:= ${BASE_DIR}/pkg_${ADK_TARGET_SYSTEM}_${CPU_ARCH}_${ADK_TARGET_LIBC}
  16. STAGING_PKG_DIR_PFX:= ${BASE_DIR}/pkg_*
  17. STAGING_HOST_DIR:= ${BASE_DIR}/host_${CPU_ARCH}_${ADK_TARGET_LIBC}
  18. STAGING_HOST_DIR_PFX:= ${BASE_DIR}/host_*
  19. # use headers and foo-config from system
  20. ifneq ($(ADK_NATIVE),)
  21. STAGING_TARGET_DIR:=
  22. SCRIPT_TARGET_DIR:= /usr/bin
  23. else
  24. STAGING_TARGET_DIR:= ${BASE_DIR}/target_${CPU_ARCH}_${ADK_TARGET_LIBC}
  25. SCRIPT_TARGET_DIR:= ${STAGING_TARGET_DIR}/scripts
  26. endif
  27. STAGING_DIR:= ${BASE_DIR}/target_${CPU_ARCH}_${ADK_TARGET_LIBC}
  28. STAGING_TARGET_DIR_PFX:=${BASE_DIR}/target_*
  29. # relation from STAGING_HOST_DIR to STAGING_TARGET_DIR (for gcc to find
  30. # its sysroot while staying relocatable)
  31. STAGING_HOST2TARGET:= ../target_${CPU_ARCH}_${ADK_TARGET_LIBC}
  32. TOOLCHAIN_BUILD_DIR= $(BASE_DIR)/toolchain_build_${CPU_ARCH}_${ADK_TARGET_LIBC}
  33. TOOLCHAIN_BUILD_DIR_PFX=$(BASE_DIR)/toolchain_build_*
  34. TOOLS_BUILD_DIR= $(BASE_DIR)/tools_build
  35. TOOLS_DIR:= $(BASE_DIR)/bin/tools
  36. SCRIPT_DIR:= $(BASE_DIR)/scripts
  37. BIN_DIR:= $(BASE_DIR)/bin/${ADK_TARGET_SYSTEM}_${CPU_ARCH}_${ADK_TARGET_LIBC}
  38. BIN_DIR_PFX:= $(BASE_DIR)/bin
  39. PACKAGE_DIR:= $(BIN_DIR)/packages
  40. TARGET_DIR:= $(BASE_DIR)/root_${ADK_TARGET_SYSTEM}_${CPU_ARCH}_${ADK_TARGET_LIBC}
  41. TARGET_DIR_PFX:= $(BASE_DIR)/root_*
  42. TARGET_PATH= ${SCRIPT_DIR}:${TOOLS_DIR}:${STAGING_HOST_DIR}/bin:${STAGING_HOST_DIR}/usr/bin:${STAGING_TARGET_DIR}/scripts:${_PATH}
  43. REAL_GNU_TARGET_NAME= $(CPU_ARCH)-$(ADK_VENDOR)-linux-$(ADK_TARGET_SUFFIX)
  44. GNU_TARGET_NAME= $(CPU_ARCH)-$(ADK_VENDOR)-linux
  45. ifeq ($(ADK_NATIVE),y)
  46. TARGET_CROSS:=
  47. TARGET_COMPILER_PREFIX?=
  48. else
  49. TARGET_CROSS:= $(STAGING_HOST_DIR)/bin/$(REAL_GNU_TARGET_NAME)-
  50. TARGET_COMPILER_PREFIX?=${TARGET_CROSS}
  51. endif
  52. ifneq ($(strip ${ADK_USE_CCACHE}),)
  53. TARGET_COMPILER_PREFIX=ccache ${TARGET_CROSS}
  54. endif
  55. # target compiler flags
  56. TARGET_CC:= ${TARGET_COMPILER_PREFIX}gcc
  57. TARGET_CXX:= ${TARGET_COMPILER_PREFIX}g++
  58. TARGET_LD:= ${TARGET_COMPILER_PREFIX}ld
  59. TARGET_CPPFLAGS:= -I${STAGING_TARGET_DIR}/usr/include
  60. TARGET_CFLAGS:= $(TARGET_CFLAGS_ARCH) -fwrapv -fno-ident -fhonour-copts
  61. TARGET_CXXFLAGS:= $(TARGET_CFLAGS_ARCH) -fwrapv -fno-ident
  62. TARGET_LDFLAGS:= -Wl,-O2 -Wl,-rpath -Wl,/usr/lib \
  63. -Wl,-rpath-link -Wl,${STAGING_TARGET_DIR}/usr/lib \
  64. -L${STAGING_TARGET_DIR}/lib -L${STAGING_TARGET_DIR}/usr/lib
  65. ifneq ($(ADK_NATIVE),)
  66. TARGET_CPPFLAGS:=
  67. TARGET_CFLAGS:= $(TARGET_CFLAGS_ARCH) -fwrapv -fno-ident -fhonour-copts
  68. TARGET_LDFLAGS:=
  69. endif
  70. ifneq ($(ADK_STATIC),)
  71. TARGET_CFLAGS+= -static
  72. TARGET_CXXFLAGS+= -static
  73. TARGET_LDFLAGS+= -static
  74. endif
  75. ifneq ($(ADK_TOOLCHAIN_GCC_USE_SSP),)
  76. TARGET_CFLAGS+= -fstack-protector
  77. TARGET_CXXFLAGS+= -fstack-protector
  78. TARGET_LDFLAGS+= -fstack-protector
  79. endif
  80. ifneq ($(ADK_TOOLCHAIN_GCC_USE_LTO),)
  81. TARGET_CFLAGS+= -flto
  82. TARGET_CXXFLAGS+= -flto
  83. TARGET_LDFLAGS+= -flto
  84. endif
  85. ifneq ($(ADK_DEBUG),)
  86. TARGET_CFLAGS+= -g3 -fno-omit-frame-pointer
  87. else
  88. TARGET_CPPFLAGS+= -DNDEBUG
  89. TARGET_CFLAGS+= -fomit-frame-pointer $(TARGET_OPTIMIZATION)
  90. endif
  91. # A nifty macro to make testing gcc features easier (from uClibc project)
  92. check_gcc=$(shell \
  93. if $(CC_FOR_BUILD) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; \
  94. then echo "$(1)"; else echo "$(2)"; fi)
  95. CF_FOR_BUILD=$(call check_gcc,-fhonour-copts,)
  96. # host compiler flags
  97. CPPFLAGS_FOR_BUILD?=
  98. CFLAGS_FOR_BUILD= -O2 -Wall $(CF_FOR_BUILD)
  99. CXXFLAGS_FOR_BUILD?= -O2 -Wall
  100. LDFLAGS_FOR_BUILD?=
  101. FLAGS_FOR_BUILD= ${CPPFLAGS_FOR_BUILD} ${CFLAGS_FOR_BUILD} ${LDFLAGS_FOR_BUILD}
  102. PATCH= ${BASH} $(SCRIPT_DIR)/patch.sh
  103. SED:= sed -i -e
  104. LINUX_DIR:= $(BUILD_DIR)/linux
  105. LINUX_HEADER_DIR:= $(STAGING_DIR)/linux-header
  106. KERNEL_MODULE_FLAGS:= ARCH=${ARCH} KERNELVERSION="2.6" \
  107. KERNEL_PATH=${LINUX_DIR} KERNELDIR=${LINUX_DIR} KERNEL_DIR=${LINUX_DIR} \
  108. PREFIX=/usr CROSS_COMPILE="${TARGET_CROSS}" \
  109. LDFLAGS="" CFLAGS_MODULE="-fhonour-copts" V=1
  110. TARGET_CONFIGURE_OPTS= PATH='${TARGET_PATH}' \
  111. AR='$(TARGET_CROSS)ar' \
  112. AS='$(TARGET_CROSS)as' \
  113. LD='$(TARGET_CROSS)ld' \
  114. NM='$(TARGET_CROSS)nm' \
  115. RANLIB='$(TARGET_CROSS)ranlib' \
  116. STRIP='${TARGET_CROSS}strip' \
  117. OBJCOPY='${TARGET_CROSS}objcopy' \
  118. CC='$(TARGET_CC)' \
  119. GCC='$(TARGET_CC)' \
  120. CXX='$(TARGET_CXX)' \
  121. CROSS='$(TARGET_CROSS)'
  122. HOST_CONFIGURE_OPTS= CC_FOR_BUILD='${CC_FOR_BUILD}' \
  123. CPPFLAGS_FOR_BUILD='${CPPFLAGS_FOR_BUILD}' \
  124. CFLAGS_FOR_BUILD='${CFLAGS_FOR_BUILD}' \
  125. LDFLAGS_FOR_BUILD='${LDFLAGS_FOR_BUILD}'
  126. PKG_SUFFIX:= $(strip $(subst ",, $(ADK_PACKAGE_SUFFIX)))
  127. ifeq ($(ADK_TARGET_PACKAGE_IPKG),y)
  128. PKG_BUILD:= PATH='${TARGET_PATH}' \
  129. ${BASH} ${SCRIPT_DIR}/ipkg-build
  130. PKG_INSTALL:= IPKG_TMP=$(BUILD_DIR)/tmp \
  131. IPKG_INSTROOT=$(TARGET_DIR) \
  132. IPKG_CONF_DIR=$(STAGING_TARGET_DIR)/etc \
  133. IPKG_OFFLINE_ROOT=$(TARGET_DIR) \
  134. TOOLS_DIR=$(TOOLS_DIR) \
  135. ${BASH} ${SCRIPT_DIR}/ipkg \
  136. -force-defaults -force-depends install
  137. PKG_STATE_DIR:= $(TARGET_DIR)/usr/lib/ipkg
  138. else
  139. PKG_BUILD:= ${BASH} ${SCRIPT_DIR}/tarpkg build
  140. PKG_INSTALL:= PKG_INSTROOT=$(TARGET_DIR) \
  141. ${BASH} ${SCRIPT_DIR}/tarpkg install
  142. PKG_STATE_DIR:= $(TARGET_DIR)/usr/lib/pkg
  143. endif
  144. ifeq ($(ADK_NATIVE),y)
  145. RSTRIP:= prefix=' ' ${BASH} ${SCRIPT_DIR}/rstrip.sh
  146. else
  147. RSTRIP:= prefix='${TARGET_CROSS}' ${BASH} ${SCRIPT_DIR}/rstrip.sh
  148. endif
  149. STATCMD:=$(shell if stat -qs .>/dev/null 2>&1; then echo 'stat -f %z';else echo 'stat -c %s';fi)
  150. EXTRACT_CMD= mkdir -p ${WRKDIR}; \
  151. cd ${WRKDIR} && \
  152. for file in ${FULLDISTFILES}; do case $$file in \
  153. *.cpio) \
  154. cat $$file | $(TOOLS_DIR)/cpio -i -d ;; \
  155. *.tar) \
  156. tar -xf $$file ;; \
  157. *.cpio.Z | *.cpio.gz | *.cgz | *.mcz) \
  158. gzip -dc $$file | $(TOOLS_DIR)/cpio -i -d ;; \
  159. *.tar.Z | *.tar.gz | *.taz | *.tgz) \
  160. gzip -dc $$file | tar -xf - ;; \
  161. *.cpio.bz2 | *.cbz) \
  162. bzip2 -dc $$file | $(TOOLS_DIR)/cpio -i -d ;; \
  163. *.tar.bz2 | *.tbz | *.tbz2) \
  164. bzip2 -dc $$file | tar -xf - ;; \
  165. *.zip) \
  166. cat $$file | $(TOOLS_DIR)/cpio -ivd -H zip ;; \
  167. *.arm) \
  168. cp $$file ${WRKDIR} ;; \
  169. *) \
  170. echo "Cannot extract '$$file'" >&2; \
  171. false ;; \
  172. esac; done
  173. ifeq ($(VERBOSE),1)
  174. QUIET:=
  175. else
  176. QUIET:= --quiet
  177. endif
  178. FETCH_CMD?= wget --timeout=30 $(QUIET)
  179. ifeq ($(ADK_HOST_CYGWIN),y)
  180. EXEEXT:= .exe
  181. endif
  182. include $(TOPDIR)/mk/mirrors.mk