build.mk 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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. TOPDIR=$(shell pwd)
  4. export TOPDIR
  5. ifneq ($(shell umask 2>/dev/null | sed 's/0*022/OK/'),OK)
  6. $(error your umask is not 022)
  7. endif
  8. CONFIG_CONFIG_IN = Config.in
  9. CONFIG = config
  10. DEFCONFIG= ADK_DEVELSYSTEM=n \
  11. ADK_DEBUG=n \
  12. ADK_STATIC=n \
  13. ADK_MAKE_PARALLEL=n \
  14. ADK_FORCE_PARALLEL=n \
  15. ADK_PACKAGE_GRUB=n \
  16. ADK_PACKAGE_BASE_FILES=y \
  17. BUSYBOX_SELINUX=n \
  18. BUSYBOX_MODPROBE_SMALL=n \
  19. BUSYBOX_EJECT=n \
  20. BUSYBOX_BUILD_LIBBUSYBOX=n \
  21. BUSYBOX_FEATURE_2_4_MODULES=n \
  22. BUSYBOX_LOCALE_SUPPORT=n \
  23. BUSYBOX_FEATURE_PREFER_APPLETS=n \
  24. BUSYBOX_FEATURE_SUID=n \
  25. BUSYBOX_SELINUXENABLED=n \
  26. BUSYBOX_FEATURE_INSTALLER=n \
  27. BUSYBOX_PAM=n \
  28. BUSYBOX_FLASH_LOCK=n \
  29. BUSYBOX_FLASH_UNLOCK=n \
  30. BUSYBOX_FLASH_ERASEALL=n \
  31. BUSYBOX_PIE=n \
  32. BUSYBOX_DEBUG=n \
  33. BUSYBOX_NOMMU=n \
  34. BUSYBOX_WERROR=n \
  35. BUSYBOX_STATIC=n \
  36. ADK_KERNEL_RT2X00_DEBUG=n \
  37. ADK_KERNEL_ATH5K_DEBUG=n
  38. noconfig_targets:= menuconfig \
  39. _config \
  40. _mconfig \
  41. distclean \
  42. tags
  43. MAKECLEANDIR_SYMBOLS= ADK_TARGET_LIB_UCLIBC \
  44. ADK_TARGET_LIB_GLIBC \
  45. ADK_TARGET_LIB_ECLIBC \
  46. ADK_DEBUG
  47. MAKECLEAN_SYMBOLS= ADK_TARGET_PACKAGE_IPKG \
  48. ADK_TARGET_PACKAGE_RPM \
  49. ADK_TARGET_PACKAGE_TGZ
  50. POSTCONFIG= -@ \
  51. if [ -f .config.old ];then \
  52. if [ -d .cfg ];then \
  53. what=cleantarget; \
  54. for symbol in ${MAKECLEANDIR_SYMBOLS}; do \
  55. newval=$$(grep -e "^$$symbol=" -e "^\# $$symbol " .config); \
  56. oldval=$$(cat .cfg/"$$symbol" 2>&-); \
  57. [[ $$newval = $$oldval ]] && continue; \
  58. echo; \
  59. echo >&2 "WARNING: Toolchain related options have changed, 'make" \
  60. "$$what' might be required!"; \
  61. break; \
  62. done; \
  63. what=clean; \
  64. for symbol in ${MAKECLEAN_SYMBOLS}; do \
  65. newval=$$(grep -e "^$$symbol=" -e "^\# $$symbol " .config); \
  66. oldval=$$(cat .cfg/"$$symbol" 2>&-); \
  67. [[ $$newval = $$oldval ]] && continue; \
  68. echo; \
  69. echo >&2 "WARNING: Package backend related options have changed, 'make" \
  70. "$$what' might be required!"; \
  71. break; \
  72. done; \
  73. fi; \
  74. if [ "$$(grep ^BUSYBOX .config|md5sum)" != "$$(grep ^BUSYBOX .config.old|md5sum)" ];then \
  75. if [ -f build_*/w-busybox*/busybox*/.configure_done ];then \
  76. rm build_*/w-busybox*/busybox*/.configure_done; \
  77. fi; \
  78. fi; \
  79. fi
  80. # Pull in the user's configuration file
  81. ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),)
  82. -include $(TOPDIR)/.config
  83. endif
  84. ifeq ($(strip $(ADK_HAVE_DOT_CONFIG)),y)
  85. include $(TOPDIR)/rules.mk
  86. include ${TOPDIR}/mk/split-cfg.mk
  87. all: world
  88. allcopy: all
  89. $(CP) $(BIN_DIR) $(TOPDIR)/bulkdir/${targetdir}/
  90. ${TOPDIR}/package/Depends.mk: ${TOPDIR}/.config
  91. mksh ${TOPDIR}/package/depmaker
  92. .NOTPARALLEL:
  93. .PHONY: all world clean cleantarget cleandir distclean image_clean
  94. world: $(DISTDIR) $(BUILD_DIR) $(TARGET_DIR) $(PACKAGE_DIR) ${TOPDIR}/.cfg/ADK_HAVE_DOT_CONFIG
  95. ${BASH} ${TOPDIR}/scripts/scan-pkgs.sh
  96. ifeq ($(ADK_NATIVE),y)
  97. $(MAKE) -f mk/build.mk toolchain/kernel-headers-prepare target/config-prepare target/compile package/compile root_clean package/install package_index target/install
  98. else
  99. ifeq ($(ADK_TOOLCHAIN_ONLY),y)
  100. $(MAKE) -f mk/build.mk toolchain/install package/compile
  101. else
  102. $(MAKE) -f mk/build.mk toolchain/install target/config-prepare target/compile package/compile root_clean package/install package_index target/install
  103. endif
  104. endif
  105. package_index:
  106. ifeq ($(ADK_TARGET_PACKAGE_IPKG),y)
  107. -cd ${PACKAGE_DIR} && \
  108. ${BASH} ${TOPDIR}/scripts/ipkg-make-index.sh . >Packages
  109. endif
  110. $(DISTDIR):
  111. mkdir -p $(DISTDIR)
  112. $(BUILD_DIR):
  113. mkdir -p $(BUILD_DIR)
  114. $(TARGET_DIR):
  115. mkdir -p $(TARGET_DIR)
  116. $(PACKAGE_DIR):
  117. mkdir -p ${PACKAGE_DIR}/.stamps
  118. ${STAGING_DIR} ${STAGING_DIR}/etc ${STAGING_TOOLS}:
  119. mkdir -p ${STAGING_DIR}/{bin,etc,lib,usr/include} \
  120. ${STAGING_TOOLS}/{bin,lib}
  121. ${STAGING_DIR}/etc/ipkg.conf: ${STAGING_DIR}/etc
  122. echo "dest root /" >${STAGING_DIR}/etc/ipkg.conf
  123. echo "option offline_root ${TARGET_DIR}" >>$(STAGING_DIR)/etc/ipkg.conf
  124. package/%: ${TOPDIR}/.cfg/ADK_HAVE_DOT_CONFIG ${STAGING_DIR}/etc/ipkg.conf ${TOPDIR}/package/Depends.mk
  125. $(MAKE) -C package $(patsubst package/%,%,$@)
  126. target/%: ${TOPDIR}/.cfg/ADK_HAVE_DOT_CONFIG
  127. $(MAKE) -C target $(patsubst target/%,%,$@)
  128. toolchain/%: ${STAGING_DIR}
  129. $(MAKE) -C toolchain $(patsubst toolchain/%,%,$@)
  130. image:
  131. $(MAKE) -C target image
  132. switch:
  133. echo "Saving configuration for target: ${ADK_TARGET}"
  134. cp -p .config .config.${ADK_TARGET}
  135. if [ -f .config.old ];then cp -p .config.old .config.old.${ADK_TARGET};fi
  136. mv .cfg .cfg.${ADK_TARGET}
  137. if [ -f .config.${TARGET} ];then cp -p .config.${TARGET} .config; \
  138. cp -p .config.old.${TARGET} .config.old; \
  139. mv .cfg.${TARGET} .cfg; \
  140. echo "Setting configuration to target: ${TARGET}"; \
  141. else echo "No old target config found";mv .config .config.bak; make TARGET=${TARGET};fi
  142. kernelconfig:
  143. cp $(TOPDIR)/target/$(ADK_TARGET)/kernel.config $(BUILD_DIR)/linux/.config
  144. $(MAKE) -C $(BUILD_DIR)/linux/ ARCH=$(ARCH) menuconfig
  145. cp $(BUILD_DIR)/linux/.config $(TOPDIR)/target/$(ADK_TARGET)/kernel.config
  146. #############################################################
  147. #
  148. # Cleanup and misc junk
  149. #
  150. #############################################################
  151. root_clean:
  152. @$(TRACE) root_clean
  153. rm -rf $(TARGET_DIR)
  154. mkdir -p $(TARGET_DIR)
  155. # Do a per-package clean here, too. This way stale headers and
  156. # libraries from cross_*/target/ get wiped away, which keeps
  157. # future package build's configure scripts from returning false
  158. # dependencies information.
  159. clean:
  160. @$(TRACE) clean
  161. $(MAKE) -C $(CONFIG) clean
  162. for d in ${STAGING_PARENT}; do \
  163. for f in $$(ls $$d/pkg/[a-z]* 2>/dev/null); do \
  164. while read file ; do \
  165. rm $$d/target/$$file 2>/dev/null; \
  166. done < $$f ; \
  167. rm $$f ; \
  168. done \
  169. done
  170. rm -rf $(BUILD_DIR) $(BIN_DIR) $(TARGET_DIR) ${TOPDIR}/.cfg \
  171. ${TOPDIR}/package/pkglist.d
  172. rm -f ${TOPDIR}/package/*/info.mk ${TOPDIR}/package/Depends.mk
  173. cleankernel:
  174. @$(TRACE) cleankernel
  175. rm -rf $(TOOLCHAIN_BUILD_DIR)/linux* $(BUILD_DIR)/linux
  176. cleandir:
  177. @$(TRACE) cleandir
  178. @$(MAKE) -C $(CONFIG) clean $(MAKE_TRACE)
  179. rm -rf $(BUILD_DIR_PFX) $(BIN_DIR_PFX) $(TARGET_DIR_PFX) \
  180. ${TOPDIR}/.cfg* ${TOPDIR}/package/pkglist.d
  181. rm -rf $(TOOLCHAIN_BUILD_DIR_PFX) $(STAGING_PARENT_PFX) \
  182. $(TOOLS_BUILD_DIR)
  183. rm -f .menu .tmpconfig.h ${TOPDIR}/package/*/info.mk \
  184. ${TOPDIR}/package/Depends.mk ${TOPDIR}/prereq.mk
  185. cleantarget:
  186. @$(TRACE) cleantarget
  187. @$(MAKE) -C $(CONFIG) clean $(MAKE_TRACE)
  188. rm -rf $(BUILD_DIR) $(BIN_DIR) $(TARGET_DIR) ${TOPDIR}/.cfg
  189. rm -rf $(TOOLCHAIN_BUILD_DIR) $(STAGING_PARENT) all.config .defconfig
  190. rm -f .tmpconfig.h ${TOPDIR}/package/*/info.mk
  191. distclean:
  192. @$(TRACE) distclean
  193. @$(MAKE) -C $(CONFIG) clean $(MAKE_TRACE)
  194. @rm -rf $(BUILD_DIR_PFX) $(BIN_DIR_PFX) $(TARGET_DIR_PFX) $(DISTDIR) \
  195. ${TOPDIR}/.cfg* ${TOPDIR}/package/pkglist.d $(TOPDIR)/bulkdir
  196. @rm -rf $(TOOLCHAIN_BUILD_DIR_PFX) $(STAGING_PARENT_PFX) $(TOOLS_BUILD_DIR)
  197. @rm -f .config* .defconfig .tmpconfig.h all.config ${TOPDIR}/prereq.mk \
  198. .menu ${TOPDIR}/package/*/info.mk ${TOPDIR}/package/Depends.mk
  199. else # ! ifeq ($(strip $(ADK_HAVE_DOT_CONFIG)),y)
  200. ifeq ($(filter-out distclean,${MAKECMDGOALS}),)
  201. include ${TOPDIR}/mk/vars.mk
  202. else
  203. include $(TOPDIR)/prereq.mk
  204. export BASH HOSTCC HOSTCFLAGS MAKE LANGUAGE LC_ALL OStype PATH
  205. endif
  206. all: menuconfig
  207. @echo "Start the build with \"make\" or with \"make v\" to be verbose"
  208. # configuration
  209. # ---------------------------------------------------------------------------
  210. # force entering the subdir, as dependency checking is done there
  211. .PHONY: $(CONFIG)/conf $(CONFIG)/mconf
  212. $(CONFIG)/conf:
  213. @$(MAKE) -C $(CONFIG) conf
  214. $(CONFIG)/mconf:
  215. @$(MAKE) -C $(CONFIG)
  216. defconfig: .menu $(CONFIG)/conf
  217. ifeq (${OStype},Linux)
  218. @echo ADK_HOST_LINUX=y > $(TOPDIR)/.defconfig
  219. endif
  220. ifeq (${OStype},FreeBSD)
  221. @echo ADK_HOST_FREEBSD=y > $(TOPDIR)/.defconfig
  222. endif
  223. ifeq (${OStype},MirBSD)
  224. @echo ADK_HOST_MIRBSD=y > $(TOPDIR)/.defconfig
  225. endif
  226. ifeq (${OStype},OpenBSD)
  227. @echo ADK_HOST_OPENBSD=y > $(TOPDIR)/.defconfig
  228. endif
  229. ifeq (${OStype},NetBSD)
  230. @echo ADK_HOST_NETBSD=y > $(TOPDIR)/.defconfig
  231. endif
  232. ifneq (,$(filter CYGWIN%,${OStype}))
  233. @echo ADK_HOST_CYGWIN=y > $(TOPDIR)/.defconfig
  234. endif
  235. @if [ ! -z "$(TARGET)" ];then \
  236. grep "^config" target/Config.in \
  237. |grep -i "$(TARGET)" \
  238. |sed -e "s#^config \(.*\)#\1=y#" \
  239. >> $(TOPDIR)/.defconfig; \
  240. for symbol in ${DEFCONFIG}; do \
  241. echo $$symbol >> $(TOPDIR)/.defconfig; \
  242. done; \
  243. fi
  244. ifneq (,$(filter qemu%,${TARGET}))
  245. @echo ADK_LINUX_QEMU=y >> $(TOPDIR)/.defconfig
  246. endif
  247. ifneq (,$(filter rescue%,${TARGET}))
  248. @echo ADK_LINUX_RESCUE=y >> $(TOPDIR)/.defconfig
  249. endif
  250. ifneq (,$(filter rb%,${TARGET}))
  251. @echo ADK_LINUX_MIKROTIK=y >> $(TOPDIR)/.defconfig
  252. endif
  253. @if [ ! -z "$(TARGET)" ];then \
  254. $(CONFIG)/conf -D .defconfig $(CONFIG_CONFIG_IN); \
  255. fi
  256. modconfig:
  257. ifeq (${OStype},Linux)
  258. @echo ADK_HOST_LINUX=y > $(TOPDIR)/all.config
  259. endif
  260. ifeq (${OStype},FreeBSD)
  261. @echo ADK_HOST_FREEBSD=y > $(TOPDIR)/all.config
  262. endif
  263. ifeq (${OStype},MirBSD)
  264. @echo ADK_HOST_MIRBSD=y > $(TOPDIR)/all.config
  265. endif
  266. ifeq (${OStype},OpenBSD)
  267. @echo ADK_HOST_OPENBSD=y > $(TOPDIR)/all.config
  268. endif
  269. ifeq (${OStype},NetBSD)
  270. @echo ADK_HOST_NETBSD=y > $(TOPDIR)/all.config
  271. endif
  272. ifneq (,$(filter CYGWIN%,${OStype}))
  273. @echo ADK_HOST_CYGWIN=y > $(TOPDIR)/all.config
  274. endif
  275. @if [ ! -z "$(TARGET)" ];then \
  276. grep "^config" target/Config.in \
  277. |grep -i "$(TARGET)" \
  278. |sed -e "s#^config \(.*\)#\1=y#" \
  279. >> $(TOPDIR)/all.config; \
  280. for symbol in ${DEFCONFIG}; do \
  281. echo $$symbol >> $(TOPDIR)/all.config; \
  282. done; \
  283. fi
  284. @if [ ! -z "$(FS)" ];then \
  285. grep "^config" target/Config.in \
  286. |grep -i "$(FS)" \
  287. |sed -e "s#^config \(.*\)#\1=y#" \
  288. >> $(TOPDIR)/all.config; \
  289. fi
  290. @if [ ! -z "$(PKG)" ];then \
  291. grep "^config" target/Config.in \
  292. |grep -i "$(PKG)" \
  293. |sed -e "s#^config \(.*\)#\1=y#" \
  294. >> $(TOPDIR)/all.config; \
  295. fi
  296. @if [ ! -z "$(LIBC)" ];then \
  297. grep "^config" target/Config.in \
  298. |grep -i "$(LIBC)" \
  299. |sed -e "s#^config \(.*\)#\1=y#" \
  300. >> $(TOPDIR)/all.config; \
  301. fi
  302. ifneq (,$(filter %_qemu,${TARGET}))
  303. @echo ADK_LINUX_QEMU=y >> $(TOPDIR)/all.config
  304. endif
  305. ifneq (,$(filter %_rescue,${TARGET}))
  306. @echo ADK_LINUX_RESCUE=y >> $(TOPDIR)/all.config
  307. endif
  308. ifneq (,$(filter rb%,${TARGET}))
  309. @echo ADK_LINUX_MIKROTIK=y >> $(TOPDIR)/all.config
  310. endif
  311. menuconfig: $(CONFIG)/mconf defconfig .menu
  312. @if [ ! -f .config ];then \
  313. $(CONFIG)/conf -D .defconfig $(CONFIG_CONFIG_IN); \
  314. fi
  315. @$(CONFIG)/mconf $(CONFIG_CONFIG_IN)
  316. ${POSTCONFIG}
  317. _config: $(CONFIG)/conf .menu
  318. -@touch .config
  319. @$(CONFIG)/conf ${W} $(CONFIG_CONFIG_IN) >/dev/null
  320. ${POSTCONFIG}
  321. .NOTPARALLEL: _mconfig
  322. _mconfig: ${CONFIG}/conf _mconfig2 _config
  323. _mconfig2: ${CONFIG}/conf modconfig .menu
  324. @${CONFIG}/conf -m ${RCONFIG} >/dev/null
  325. distclean:
  326. @$(MAKE) -C $(CONFIG) clean
  327. @rm -rf $(BUILD_DIR) $(TOOLS_BUILD_DIR) $(BIN_DIR) $(DISTDIR) \
  328. ${TOPDIR}/.cfg* ${TOPDIR}/package/pkglist.d
  329. @rm -rf $(TOOLCHAIN_BUILD_DIR) $(STAGING_PARENT) $(TARGET_DIR)
  330. @rm -f .config* .defconfig all.config .tmpconfig.h ${TOPDIR}/prereq.mk \
  331. .menu ${TOPDIR}/package/*/info.mk ${TOPDIR}/package/Depends.mk
  332. endif # ! ifeq ($(strip $(ADK_HAVE_DOT_CONFIG)),y)
  333. # build all targets and combinations
  334. bulk:
  335. while read target libc fs p; do \
  336. mkdir -p $(TOPDIR)/bulkdir/$$target-$$libc-$$fs; \
  337. ( \
  338. echo === building $$target $$libc $$fs on $$(date); \
  339. $(MAKE) prereq && \
  340. if [ "x$$p" = xy ];then \
  341. $(MAKE) TARGET=$$target LIBC=$$libc FS=$$fs PKG=ipkg \
  342. allmodconfig; \
  343. else \
  344. $(MAKE) TARGET=$$target LIBC=$$libc FS=$$fs PKG=ipkg \
  345. defconfig; \
  346. fi && \
  347. $(MAKE) VERBOSE=1 -f mk/build.mk allcopy \
  348. targetdir=$$target-$$libc-$$fs; \
  349. $(MAKE) cleantarget; \
  350. rm .config; \
  351. ) 2>&1 | tee $(TOPDIR)/bulkdir/$$target-$$libc-$$fs/log; \
  352. done <${TOPDIR}/target/bulk.lst
  353. .menu menu:
  354. mksh $(TOPDIR)/package/pkgmaker
  355. @:>.menu
  356. .PHONY: menu