build.mk 13 KB

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