build: include homebrew include/library directory in cflags/ldflags on mac os x
[openwrt/svn-archive/archive.git] / include / kernel-defaults.mk
1 #
2 # Copyright (C) 2006-2015 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7
8 KERNEL_MAKEOPTS := -C $(LINUX_DIR) \
9 HOSTCFLAGS="$(HOST_CFLAGS) -Wall -Wmissing-prototypes -Wstrict-prototypes" \
10 CROSS_COMPILE="$(KERNEL_CROSS)" \
11 ARCH="$(LINUX_KARCH)" \
12 KBUILD_HAVE_NLS=no \
13 CONFIG_SHELL="$(BASH)" \
14 $(if $(findstring c,$(OPENWRT_VERBOSE)),V=1,V='')
15
16 ifdef CONFIG_STRIP_KERNEL_EXPORTS
17 KERNEL_MAKEOPTS += \
18 EXTRA_LDSFLAGS="-I$(KERNEL_BUILD_DIR) -include symtab.h"
19 endif
20
21 INITRAMFS_EXTRA_FILES ?= $(GENERIC_PLATFORM_DIR)/image/initramfs-base-files.txt
22
23 ifneq (,$(KERNEL_CC))
24 KERNEL_MAKEOPTS += CC="$(KERNEL_CC)"
25 endif
26
27 ifdef CONFIG_USE_SPARSE
28 KERNEL_MAKEOPTS += C=1 CHECK=$(STAGING_DIR_HOST)/bin/sparse
29 endif
30
31 export HOST_EXTRACFLAGS=-I$(STAGING_DIR_HOST)/include
32
33 # defined in quilt.mk
34 Kernel/Patch:=$(Kernel/Patch/Default)
35
36 KERNEL_GIT_OPTS:=
37 ifneq ($(strip $(CONFIG_KERNEL_GIT_LOCAL_REPOSITORY)),"")
38 KERNEL_GIT_OPTS+=--reference $(CONFIG_KERNEL_GIT_LOCAL_REPOSITORY)
39 endif
40
41 ifneq ($(strip $(CONFIG_KERNEL_GIT_BRANCH)),"")
42 KERNEL_GIT_OPTS+=--branch $(CONFIG_KERNEL_GIT_BRANCH)
43 endif
44
45 ifeq ($(strip $(CONFIG_EXTERNAL_KERNEL_TREE)),"")
46 ifeq ($(strip $(CONFIG_KERNEL_GIT_CLONE_URI)),"")
47 define Kernel/Prepare/Default
48 xzcat $(DL_DIR)/$(LINUX_SOURCE) | $(TAR) -C $(KERNEL_BUILD_DIR) $(TAR_OPTIONS)
49 $(Kernel/Patch)
50 touch $(LINUX_DIR)/.quilt_used
51 endef
52 else
53 define Kernel/Prepare/Default
54 git clone $(KERNEL_GIT_OPTS) $(CONFIG_KERNEL_GIT_CLONE_URI) $(LINUX_DIR)
55 endef
56 endif
57 else
58 define Kernel/Prepare/Default
59 mkdir -p $(KERNEL_BUILD_DIR)
60 if [ -d $(LINUX_DIR) ]; then \
61 rmdir $(LINUX_DIR); \
62 fi
63 ln -s $(CONFIG_EXTERNAL_KERNEL_TREE) $(LINUX_DIR)
64 endef
65 endif
66
67 ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
68 ifeq ($(strip $(CONFIG_EXTERNAL_CPIO)),"")
69 define Kernel/SetInitramfs/PreConfigure
70 grep -v -e INITRAMFS -e CONFIG_RD_ -e CONFIG_BLK_DEV_INITRD $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
71 echo 'CONFIG_BLK_DEV_INITRD=y' >> $(LINUX_DIR)/.config
72 echo 'CONFIG_INITRAMFS_SOURCE="$(strip $(TARGET_DIR) $(INITRAMFS_EXTRA_FILES))"' >> $(LINUX_DIR)/.config
73 endef
74 else
75 define Kernel/SetInitramfs/PreConfigure
76 grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
77 echo 'CONFIG_INITRAMFS_SOURCE="$(call qstrip,$(CONFIG_EXTERNAL_CPIO))"' >> $(LINUX_DIR)/.config
78 endef
79 endif
80
81 define Kernel/SetInitramfs
82 mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
83 $(call Kernel/SetInitramfs/PreConfigure)
84 echo 'CONFIG_INITRAMFS_ROOT_UID=$(shell id -u)' >> $(LINUX_DIR)/.config
85 echo 'CONFIG_INITRAMFS_ROOT_GID=$(shell id -g)' >> $(LINUX_DIR)/.config
86 echo "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_NONE),CONFIG_INITRAMFS_COMPRESSION_NONE=y,# CONFIG_INITRAMFS_COMPRESSION_NONE is not set)" >> $(LINUX_DIR)/.config
87 echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_GZIP),CONFIG_INITRAMFS_COMPRESSION_GZIP=y\nCONFIG_RD_GZIP=y,# CONFIG_INITRAMFS_COMPRESSION_GZIP is not set\n# CONFIG_RD_GZIP is not set)" >> $(LINUX_DIR)/.config
88 echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_BZIP2),CONFIG_INITRAMFS_COMPRESSION_BZIP2=y\nCONFIG_RD_BZIP2=y,# CONFIG_INITRAMFS_COMPRESSION_BZIP2 is not set\n# CONFIG_RD_BZIP2 is not set)" >> $(LINUX_DIR)/.config
89 echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZMA),CONFIG_INITRAMFS_COMPRESSION_LZMA=y\nCONFIG_RD_LZMA=y,# CONFIG_INITRAMFS_COMPRESSION_LZMA is not set\n# CONFIG_RD_LZMA is not set)" >> $(LINUX_DIR)/.config
90 echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZO),CONFIG_INITRAMFS_COMPRESSION_LZO=y\nCONFIG_RD_LZO=y,# CONFIG_INITRAMFS_COMPRESSION_LZO is not set\n# CONFIG_RD_LZO is not set)" >> $(LINUX_DIR)/.config
91 echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_XZ),CONFIG_INITRAMFS_COMPRESSION_XZ=y\nCONFIG_RD_XZ=y,# CONFIG_INITRAMFS_COMPRESSION_XZ is not set\n# CONFIG_RD_XZ is not set)" >> $(LINUX_DIR)/.config
92 echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZ4),CONFIG_INITRAMFS_COMPRESSION_LZ4=y\nCONFIG_RD_LZ4=y,# CONFIG_INITRAMFS_COMPRESSION_LZ4 is not set\n# CONFIG_RD_LZ4 is not set)" >> $(LINUX_DIR)/.config
93 endef
94 else
95 endif
96
97 define Kernel/SetNoInitramfs
98 mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
99 grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
100 echo 'CONFIG_INITRAMFS_SOURCE=""' >> $(LINUX_DIR)/.config
101 endef
102
103 define Kernel/Configure/Default
104 $(LINUX_CONF_CMD) > $(LINUX_DIR)/.config.target
105 # copy CONFIG_KERNEL_* settings over to .config.target
106 awk '/^(#[[:space:]]+)?CONFIG_KERNEL/{sub("CONFIG_KERNEL_","CONFIG_");print}' $(TOPDIR)/.config >> $(LINUX_DIR)/.config.target
107 echo "# CONFIG_KALLSYMS_EXTRA_PASS is not set" >> $(LINUX_DIR)/.config.target
108 echo "# CONFIG_KALLSYMS_ALL is not set" >> $(LINUX_DIR)/.config.target
109 echo "# CONFIG_KALLSYMS_UNCOMPRESSED is not set" >> $(LINUX_DIR)/.config.target
110 $(SCRIPT_DIR)/metadata.pl kconfig $(TMP_DIR)/.packageinfo $(TOPDIR)/.config $(KERNEL_PATCHVER) > $(LINUX_DIR)/.config.override
111 $(SCRIPT_DIR)/kconfig.pl 'm+' '+' $(LINUX_DIR)/.config.target /dev/null $(LINUX_DIR)/.config.override > $(LINUX_DIR)/.config
112 $(call Kernel/SetNoInitramfs)
113 rm -rf $(KERNEL_BUILD_DIR)/modules
114 $(_SINGLE) [ -d $(LINUX_DIR)/user_headers ] || $(MAKE) $(KERNEL_MAKEOPTS) INSTALL_HDR_PATH=$(LINUX_DIR)/user_headers headers_install
115 $(SH_FUNC) grep '=[ym]' $(LINUX_DIR)/.config | LC_ALL=C sort | md5s > $(LINUX_DIR)/.vermagic
116 endef
117
118 define Kernel/Configure/Initramfs
119 $(call Kernel/SetInitramfs)
120 endef
121
122 define Kernel/CompileModules/Default
123 rm -f $(LINUX_DIR)/vmlinux $(LINUX_DIR)/System.map
124 +$(MAKE) $(KERNEL_MAKEOPTS) modules
125 endef
126
127 OBJCOPY_STRIP = -R .reginfo -R .notes -R .note -R .comment -R .mdebug -R .note.gnu.build-id
128
129 # AMD64 shares the location with x86
130 ifeq ($(LINUX_KARCH),x86_64)
131 IMAGES_DIR:=../../x86/boot
132 endif
133
134 define Kernel/CopyImage
135 $(KERNEL_CROSS)objcopy -O binary $(OBJCOPY_STRIP) -S $(LINUX_DIR)/vmlinux $(LINUX_KERNEL)$(1)
136 $(KERNEL_CROSS)objcopy $(OBJCOPY_STRIP) -S $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux$(1).elf
137 $(CP) $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux.debug
138 $(foreach k, \
139 $(if $(KERNEL_IMAGES),$(KERNEL_IMAGES),$(filter-out dtbs,$(KERNELNAME))), \
140 $(CP) $(LINUX_DIR)/arch/$(LINUX_KARCH)/boot/$(IMAGES_DIR)/$(k) $(KERNEL_BUILD_DIR)/$(k)$(1); \
141 )
142 endef
143
144 define Kernel/CompileImage/Default
145 rm -f $(TARGET_DIR)/init
146 +$(MAKE) $(KERNEL_MAKEOPTS) $(if $(KERNELNAME),$(KERNELNAME),all) modules
147 $(call Kernel/CopyImage)
148 endef
149
150 ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
151 define Kernel/CompileImage/Initramfs
152 $(call Kernel/Configure/Initramfs)
153 $(CP) $(GENERIC_PLATFORM_DIR)/base-files/init $(TARGET_DIR)/init
154 rm -rf $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/usr/initramfs_data.cpio*
155 +$(MAKE) $(KERNEL_MAKEOPTS) $(if $(KERNELNAME),$(KERNELNAME),all) modules
156 $(call Kernel/CopyImage,-initramfs)
157 endef
158 else
159 define Kernel/CompileImage/Initramfs
160 endef
161 endif
162
163 define Kernel/Clean/Default
164 rm -f $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/.configured
165 rm -f $(LINUX_KERNEL)
166 $(_SINGLE)$(MAKE) -C $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) clean
167 endef
168
169