build.mk 13 KB

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