build.mk 13 KB

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