build.mk 13 KB

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