root/trunk/freewrt/target/Makefile

Revision 3674, 3.6 kB (checked in by n0-1, 1 year ago)

as I wonder each time how exactly the kernel config is built, I finally documented it

Line 
1 # $FreeWRT$
2 #-
3 # This file is part of the FreeWRT project. FreeWRT is copyrighted
4 # material, please see the LICENCE file in the top-level directory
5 # or at http://www.freewrt.org/licence for details.
6
7 include $(TOPDIR)/rules.mk
8 include $(TOPDIR)/mk/targets.mk
9
10 all: install
11
12 $(BIN_DIR):
13         mkdir -p $(BIN_DIR)
14
15 linux-compile: 
16 linux-install: $(BIN_DIR)
17
18 ### Kernel .config Creation
19 # The following target combines all kernel-related variables and
20 # config files into a single one to be used as the final kernel
21 # configuration when building. This is how it's done:
22 # 1) fetch all FWRT_KPACKAGE_KMOD_* vars into
23 #    .fwrtkernelconfig.modules and set them to "m"
24 # 2) fetch all enabled FWRT_KERNEL_* vars into
25 #    .fwrtkernelconfig.kernel (no conversion, as they are booleans)
26 # 3) repeat 2) for the disabled ones and save them into
27 #    .fwrtkernelconfig.nokernel (for some obscure reason)
28 # 4) get the board-specific static kernel config and place it into
29 #    .fwrtkernelconfig.board
30 # 5) prepare for merging:
31 #    * if a variable is disabled in .fwrtkernelconfig.board and
32 #      enabled in either of .fwrtkernelconfig.{modules,kernel},
33 #      remove it from .fwrtkernelconfig.board
34 #    * append ${FS_CMDLINE} to the kernel commandline inside
35 #      .fwrtkernelconfig.board
36 # 6) merge (cat) it all together into .fwrtkernelconfig.tmp
37 # 7) check if .fwrtkernelconfig.tmp differs from the current one
38 #    (.fwrtkernelconfig) at all, overwriting the current one
39 #    only if it does (so the timestamp stays intact)
40 # 8) remove the temporary .fwrtkernelconfig.tmp
41 ###
42 config-prepare: $(TOPDIR)/.config
43         sed -n '/^FWRT_KPACKAGE_KMOD/s//CONFIG/p' ${TOPDIR}/.config | \
44             sed 's/=y/=m/' >${BUILD_DIR}/.fwrtkernelconfig.modules
45         sed -n '/^FWRT_KERNEL/s//CONFIG/p' ${TOPDIR}/.config \
46             >${BUILD_DIR}/.fwrtkernelconfig.kernel
47         sed -n '/^# FWRT_KERNEL/s//# CONFIG/p' ${TOPDIR}/.config \
48             >${BUILD_DIR}/.fwrtkernelconfig.nokernel
49         cp linux/${BOARD}-${KERNEL}/kernelconfig \
50             ${BUILD_DIR}/.fwrtkernelconfig.board
51         (cat ${BUILD_DIR}/.fwrtkernelconfig.{modules,kernel} | \
52             while IFS='=' read symbol value; do \
53                 echo ",g/^# $$symbol/d"; \
54         done; \
55         echo ',g^\(CONFIG_CMDLINE="\)\(.*\)"s\1\2 ${FS_CMDLINE}"'; \
56         echo wq) | ed -s ${BUILD_DIR}/.fwrtkernelconfig.board
57         cd ${BUILD_DIR} && cat .fwrtkernelconfig.board \
58             .fwrtkernelconfig.kernel .fwrtkernelconfig.modules \
59             >.fwrtkernelconfig.tmp
60         cd ${BUILD_DIR} && cmp -s .fwrtkernelconfig.tmp .fwrtkernelconfig || \
61             cp .fwrtkernelconfig.tmp .fwrtkernelconfig
62         -rm -f ${BUILD_DIR}/.fwrtkernelconfig.tmp
63
64 prepare: linux-prepare
65 compile: linux-compile
66 ifneq ($(strip ${FWRT_TARGET_NOKERNEL})$(strip ${FWRT_TARGET_ROOTFS_INITRAMFS}),)
67 install: image_clean linux-noinstall image_install
68 else
69 install: image_clean linux-install image_install
70 endif
71 clean: linux-clean image_clean
72
73 image_clean:
74         rm -f $(BIN_DIR)/$(FWRT_PREFIX)-*
75
76 image_install:
77 ifneq ($(strip ${FWRT_TARGET_NOKERNEL}),)
78         ${MAKE} -C image/nokernel install-prepare install
79 else
80         $(MAKE) -C image/$(BOARD) install-prepare
81         $(MAKE) -C image/$(BOARD) install
82 endif
83
84 %-clean:
85         $(TRACE) target/$(patsubst %-clean,%,$@)-clean
86         $(MAKE) -C $(patsubst %-clean,%,$@) clean
87 %-prepare:
88         $(TRACE) target/$(patsubst %-prepare,%,$@)-prepare
89         $(MAKE) -C $(patsubst %-prepare,%,$@) prepare
90 %-compile: %-prepare
91         $(TRACE) target/$(patsubst %-compile,%,$@)-compile
92         $(MAKE) -C $(patsubst %-compile,%,$@) compile
93 %-install: %-compile
94         $(TRACE) target/$(patsubst %-install,%,$@)-install
95         $(MAKE) -C $(patsubst %-install,%,$@) install
96 %-noinstall:
97         $(TRACE) target/$(patsubst %-noinstall,%,$@)-noinstall
98         $(MAKE) -C $(patsubst %-noinstall,%,$@) noinstall
99
Note: See TracBrowser for help on using the browser.