1
0

build.mk 13 KB

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