ramips: fix ZyXEL NWA55AXE model name
[openwrt/openwrt.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 master 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 kernel/module.lds
72
73 KERNEL_FILES_BASE := \
74 .config \
75 Makefile \
76 scripts \
77 tools/objtool \
78 include \
79 Module.symvers \
80 modules.builtin \
81 $(foreach arch,$(KDIR_ARCHES),$(addprefix arch/$(arch)/,$(KERNEL_FILES_ARCH)))
82
83 KERNEL_FILES := $(patsubst $(TOPDIR)/%,%,$(wildcard $(addprefix $(LINUX_DIR)/,$(KERNEL_FILES_BASE))))
84
85 all: compile
86
87 $(BIN_DIR)/$(SDK_NAME).tar.xz: clean
88 mkdir -p \
89 $(SDK_BUILD_DIR)/dl \
90 $(SDK_BUILD_DIR)/package \
91 $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TARGET)/include \
92 $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TARGET)/usr/include
93
94 $(CP) -L $(INCLUDE_DIR) $(SCRIPT_DIR) $(SDK_BUILD_DIR)/
95 $(TAR) -cf - -C $(TOPDIR) \
96 `cd $(TOPDIR); find $(KDIR_BASE)/ -name \*.ko` \
97 `cd $(TOPDIR); find $(KDIR_BASE)/firmware/ -newer $(KDIR_BASE)/firmware/Makefile \
98 -type f -name '*.bin' -or -name '*.cis' -or -name '*.csp' -or -name '*.dsp' -or -name '*.fw'` \
99 $(foreach exclude,$(EXCLUDE_DIRS),--exclude="$(exclude)") \
100 $(SDK_DIRS) $(KERNEL_FILES) | \
101 $(TAR) -xf - -C $(SDK_BUILD_DIR)
102
103 # Copy usbip sources, this is required for the usbip userspace packages to be buildable by the SDK.
104 $(TAR) -cf - -C $(TOPDIR) $(KDIR_BASE)/tools/usb/usbip/ | \
105 $(TAR) -xf - -C $(SDK_BUILD_DIR)
106
107 (cd $(SDK_BUILD_DIR); find $(STAGING_SUBDIR_HOST)/bin $(STAGING_SUBDIR_HOST)/usr/bin \
108 $(STAGING_SUBDIR_TOOLCHAIN)/bin $(STAGING_SUBDIR_TOOLCHAIN)/*/bin $(STAGING_SUBDIR_TOOLCHAIN)/libexec \
109 $(KDIR_BASE) \
110 -type f | $(BUNDLER_COMMAND))
111
112 @-( \
113 find \
114 $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/bin \
115 $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/usr/bin \
116 $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TOOLCHAIN)/bin \
117 $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TOOLCHAIN)/*/bin \
118 $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TOOLCHAIN)/libexec \
119 -type f; \
120 find \
121 $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/lib \
122 $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/usr/lib \
123 -type f -name \*.so\*; \
124 ) | xargs strip 2>/dev/null >/dev/null
125
126 mkdir -p $(SDK_BUILD_DIR)/target/linux
127 $(CP) $(GENERIC_PLATFORM_DIR) $(PLATFORM_DIR) $(SDK_BUILD_DIR)/target/linux/
128 rm -rf \
129 $(SDK_BUILD_DIR)/target/linux/*/files* \
130 $(SDK_BUILD_DIR)/target/linux/*/patches*
131 ./convert-config.pl $(TOPDIR)/.config > $(SDK_BUILD_DIR)/Config-build.in
132 $(CP) -L \
133 $(TOPDIR)/LICENSES \
134 $(TOPDIR)/COPYING \
135 $(TOPDIR)/rules.mk \
136 ./files/Config.in \
137 ./files/Makefile \
138 ./files/include/prepare.mk \
139 ./files/README.SDK \
140 $(SDK_BUILD_DIR)/
141 mkdir -p $(SDK_BUILD_DIR)/package/kernel
142 $(CP) \
143 $(TOPDIR)/package/Makefile \
144 $(TOPDIR)/package/libs/toolchain \
145 $(SDK_BUILD_DIR)/package/
146 $(CP) \
147 $(TOPDIR)/package/kernel/linux \
148 $(SDK_BUILD_DIR)/package/kernel/
149
150 -rm -rf $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/.prereq-build
151
152 -rm -f $(SDK_BUILD_DIR)/feeds.conf.default
153 $(if $(BASE_FEED),echo "$(BASE_FEED)" > $(SDK_BUILD_DIR)/feeds.conf.default)
154 if [ -f $(TOPDIR)/feeds.conf ]; then \
155 cat $(TOPDIR)/feeds.conf >> $(SDK_BUILD_DIR)/feeds.conf.default; \
156 else \
157 cat $(TOPDIR)/feeds.conf.default >> $(SDK_BUILD_DIR)/feeds.conf.default; \
158 fi
159 $(SED) 's,^# REVISION:=.*,REVISION:=$(REVISION),g' $(SDK_BUILD_DIR)/include/version.mk
160 $(SED) 's,^# SOURCE_DATE_EPOCH:=.*,SOURCE_DATE_EPOCH:=$(SOURCE_DATE_EPOCH),g' $(SDK_BUILD_DIR)/include/version.mk
161 $(SED) '/LINUX_VERMAGIC:=/ { s,unknown,$(LINUX_VERMAGIC),g }' $(SDK_BUILD_DIR)/include/kernel.mk
162 find $(SDK_BUILD_DIR) -name .git | $(XARGS) rm -rf
163 find $(SDK_BUILD_DIR) -name .svn | $(XARGS) rm -rf
164 find $(SDK_BUILD_DIR) -name CVS | $(XARGS) rm -rf
165 -make -C $(SDK_BUILD_DIR)/scripts/config clean
166 (cd $(BUILD_DIR); \
167 tar -I '$(STAGING_DIR_HOST)/bin/xz -7e -T$(if $(filter 1,$(NPROC)),2,0)' -cf $@ $(SDK_NAME) \
168 --mtime="$(shell date --date=@$(SOURCE_DATE_EPOCH))"; \
169 )
170
171 download:
172 prepare:
173 compile: $(BIN_DIR)/$(SDK_NAME).tar.xz
174 install: compile
175
176 clean:
177 rm -rf $(SDK_BUILD_DIR) $(BIN_DIR)/$(SDK_NAME).tar.xz