build.mk 11 KB

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