OSDN Git Service

dnsmasq: Update to version 2.86
[immortalwrt/immortalwrt.git] / target / sdk / Makefile
1
2 # Copyright (C) 2006-2014 OpenWrt.org
3 # Copyright (C) 2016 LEDE Project
4 #
5 # This is free software, licensed under the GNU General Public License v2.
6 # See /LICENSE for more information.
7 #
8
9 include $(TOPDIR)/rules.mk
10 include $(INCLUDE_DIR)/kernel.mk
11 include $(INCLUDE_DIR)/version.mk
12 include $(INCLUDE_DIR)/download.mk
13
14 override MAKEFLAGS=
15
16 SDK_NAME:=$(VERSION_DIST_SANITIZED)-sdk-$(if $(CONFIG_VERSION_FILENAMES),$(VERSION_NUMBER)-)$(BOARD)$(if $(SUBTARGET),-$(SUBTARGET))$(if $(GCCV),_gcc-$(GCCV))$(DIR_SUFFIX).$(HOST_OS)-$(HOST_ARCH)
17 SDK_BUILD_DIR:=$(BUILD_DIR)/$(SDK_NAME)
18
19 STAGING_SUBDIR_HOST := staging_dir/host
20 STAGING_SUBDIR_TARGET := staging_dir/$(TARGET_DIR_NAME)
21 STAGING_SUBDIR_TOOLCHAIN := staging_dir/toolchain-$(ARCH)$(ARCH_SUFFIX)_gcc-$(GCCV)_$(LIBC)$(if $(CONFIG_arm),_eabi)
22
23 BUNDLER_PATH := $(subst $(space),:,$(filter-out $(TOPDIR)/%,$(subst :,$(space),$(PATH))))
24 BUNDLER_COMMAND := PATH=$(BUNDLER_PATH) $(XARGS) $(SCRIPT_DIR)/bundle-libraries.sh $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)
25
26 EXCLUDE_DIRS:= \
27         */stamp \
28         */stampfiles \
29         */man \
30         */info \
31         */root-* \
32         initial \
33         *.install.clean \
34         *.install.flags \
35         *.install \
36         */doc \
37         */share/locale
38
39 SDK_DIRS = \
40                 $(STAGING_SUBDIR_HOST) \
41                 $(STAGING_SUBDIR_TOOLCHAIN)
42
43 GIT_URL:=$(shell git config --get remote.origin.url 2>/dev/null)
44 GIT_URL:=$(if $(CONFIG_BUILDBOT),$(filter git://% http://% https://%,$(GIT_URL)),$(GIT_URL))
45 GIT_COMMIT:=$(shell git rev-parse HEAD 2>/dev/null)
46 GIT_BRANCH:=$(filter-out HEAD,$(shell git rev-parse --abbrev-ref HEAD 2>/dev/null))
47 GIT_TAGNAME:=$(shell git show-ref --tags --dereference 2>/dev/null | sed -ne '/^$(GIT_COMMIT) / { s|^.*/||; s|\^.*||; p }')
48
49 BASE_FEED:=$(if $(GIT_URL),src-git base $(GIT_URL)$(if $(GIT_BRANCH),;$(GIT_BRANCH),$(if $(GIT_TAGNAME),;$(GIT_TAGNAME))))
50 BASE_FEED:=$(if $(BASE_FEED),$(BASE_FEED),$(shell cd $(TOPDIR); LC_ALL=C git svn info 2>/dev/null | sed -ne 's/^URL: /src-gitsvn base /p'))
51 BASE_FEED:=$(if $(BASE_FEED),$(BASE_FEED),$(shell cd $(TOPDIR); LC_ALL=C svn info 2>/dev/null | sed -ne 's/^URL: /src-svn base /p'))
52 BASE_FEED:=$(if $(BASE_FEED),$(BASE_FEED),src-git base $(PROJECT_GIT)/openwrt/openwrt.git$(if $(GIT_BRANCH),;$(GIT_BRANCH),$(if $(GIT_TAGNAME),;$(GIT_TAGNAME))))
53
54 KDIR_BASE = $(patsubst $(TOPDIR)/%,%,$(LINUX_DIR))
55 KDIR_ARCHES = $(LINUX_KARCH)
56
57 # arch/arm64/ includes reference files in arch/arm/, so we'll need both
58 ifeq ($(LINUX_KARCH),arm64)
59   KDIR_ARCHES += arm
60 endif
61
62 KERNEL_FILES_ARCH = \
63         Makefile* \
64         module.lds \
65         Kbuild.platforms \
66         */Platform \
67         include \
68         */include \
69         scripts \
70         kernel/asm-offsets.s
71
72 KERNEL_FILES_BASE := \
73         .config \
74         Makefile \
75         scripts \
76         include \
77         Module.symvers \
78         modules.builtin \
79         $(foreach arch,$(KDIR_ARCHES),$(addprefix arch/$(arch)/,$(KERNEL_FILES_ARCH)))
80
81 KERNEL_FILES := $(patsubst $(TOPDIR)/%,%,$(wildcard $(addprefix $(LINUX_DIR)/,$(KERNEL_FILES_BASE))))
82
83 all: compile
84
85 $(BIN_DIR)/$(SDK_NAME).tar.xz: clean
86         mkdir -p \
87                 $(SDK_BUILD_DIR)/dl \
88                 $(SDK_BUILD_DIR)/package \
89                 $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TARGET)/include \
90                 $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TARGET)/usr/include
91
92         $(CP) -L $(INCLUDE_DIR) $(SCRIPT_DIR) $(SDK_BUILD_DIR)/
93         $(TAR) -cf - -C $(TOPDIR) \
94                 `cd $(TOPDIR); find $(KDIR_BASE)/ -name \*.ko` \
95                 `cd $(TOPDIR); find $(KDIR_BASE)/firmware/ -newer $(KDIR_BASE)/firmware/Makefile \
96                         -type f -name '*.bin' -or -name '*.cis' -or -name '*.csp' -or -name '*.dsp' -or -name '*.fw'` \
97                 $(foreach exclude,$(EXCLUDE_DIRS),--exclude="$(exclude)") \
98                 $(SDK_DIRS) $(KERNEL_FILES) | \
99                 $(TAR) -xf - -C $(SDK_BUILD_DIR)
100
101         # Copy usbip sources, this is required for the usbip userspace packages to be buildable by the SDK.
102         $(TAR) -cf - -C $(TOPDIR) $(KDIR_BASE)/tools/usb/usbip/ | \
103                 $(TAR) -xf - -C $(SDK_BUILD_DIR)
104
105         # Copy objtool executables.  They are required for building external
106         # modules if "Compile-time stack metadata validation" is enabled.
107         if grep -q '^CONFIG_STACK_VALIDATION=y' $(LINUX_DIR)/.config; then \
108                 $(TAR) -cf - -C $(TOPDIR) \
109                                 `cd $(TOPDIR); find $(KDIR_BASE)/tools/objtool -type f -executable` | \
110                         $(TAR) -xf - -C $(SDK_BUILD_DIR); \
111         fi
112
113         (cd $(SDK_BUILD_DIR); find $(STAGING_SUBDIR_HOST)/bin $(STAGING_SUBDIR_HOST)/usr/bin \
114                 $(STAGING_SUBDIR_TOOLCHAIN)/bin $(STAGING_SUBDIR_TOOLCHAIN)/*/bin $(STAGING_SUBDIR_TOOLCHAIN)/libexec \
115                 $(KDIR_BASE) \
116                 -type f | $(BUNDLER_COMMAND))
117
118         @-( \
119                 find \
120                         $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/bin \
121                         $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/usr/bin \
122                         $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TOOLCHAIN)/bin \
123                         $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TOOLCHAIN)/*/bin \
124                         $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TOOLCHAIN)/libexec \
125                         -type f; \
126                 find \
127                         $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/lib \
128                         $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/usr/lib \
129                         -type f -name \*.so\*; \
130         ) | xargs strip 2>/dev/null >/dev/null
131
132         mkdir -p $(SDK_BUILD_DIR)/target/linux
133         $(CP) $(GENERIC_PLATFORM_DIR) $(PLATFORM_DIR) $(SDK_BUILD_DIR)/target/linux/
134         rm -rf \
135                 $(SDK_BUILD_DIR)/target/linux/*/files* \
136                 $(SDK_BUILD_DIR)/target/linux/*/patches*
137         ./convert-config.pl $(TOPDIR)/.config > $(SDK_BUILD_DIR)/Config-build.in
138         $(CP) -L \
139                 $(TOPDIR)/LICENSES \
140                 $(TOPDIR)/COPYING \
141                 $(TOPDIR)/rules.mk \
142                 ./files/Config.in \
143                 ./files/Makefile \
144                 ./files/include/prepare.mk \
145                 ./files/README.SDK \
146                 $(SDK_BUILD_DIR)/
147         mkdir -p $(SDK_BUILD_DIR)/package/kernel
148         $(CP) \
149                 $(TOPDIR)/package/Makefile \
150                 $(TOPDIR)/package/libs/toolchain \
151                 $(SDK_BUILD_DIR)/package/
152         $(CP) \
153                 $(TOPDIR)/package/kernel/linux \
154                 $(SDK_BUILD_DIR)/package/kernel/
155
156         -rm -rf $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/.prereq-build
157
158         -rm -f $(SDK_BUILD_DIR)/feeds.conf.default
159         $(if $(BASE_FEED),echo "$(BASE_FEED)" > $(SDK_BUILD_DIR)/feeds.conf.default)
160         if [ -f $(TOPDIR)/feeds.conf ]; then \
161                 cat $(TOPDIR)/feeds.conf >> $(SDK_BUILD_DIR)/feeds.conf.default; \
162         else \
163                 cat $(TOPDIR)/feeds.conf.default >> $(SDK_BUILD_DIR)/feeds.conf.default; \
164         fi
165         $(SED) 's,^# REVISION:=.*,REVISION:=$(REVISION),g' $(SDK_BUILD_DIR)/include/version.mk
166         $(SED) 's,^# SOURCE_DATE_EPOCH:=.*,SOURCE_DATE_EPOCH:=$(SOURCE_DATE_EPOCH),g' $(SDK_BUILD_DIR)/include/version.mk
167         $(SED) '/LINUX_VERMAGIC:=/ { s,unknown,$(LINUX_VERMAGIC),g }' $(SDK_BUILD_DIR)/include/kernel.mk
168         find $(SDK_BUILD_DIR) -name .git | $(XARGS) rm -rf
169         find $(SDK_BUILD_DIR) -name .svn | $(XARGS) rm -rf
170         find $(SDK_BUILD_DIR) -name CVS | $(XARGS) rm -rf
171         -make -C $(SDK_BUILD_DIR)/scripts/config clean
172         (cd $(BUILD_DIR); \
173                 tar -I 'xz -T0 -7e' -cf $@ $(SDK_NAME); \
174         )
175
176 download:
177 prepare:
178 compile: $(BIN_DIR)/$(SDK_NAME).tar.xz
179 install: compile
180
181 clean:
182         rm -rf $(SDK_BUILD_DIR) $(BIN_DIR)/$(SDK_NAME).tar.xz