build.mk 13 KB

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