4fec516eed76182affd344bc0c9639317f71cd41
[openwrt/openwrt.git] / target / sdk / Makefile
1 #
2 # Copyright (C) 2006-2014 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 include $(TOPDIR)/rules.mk
9 include $(INCLUDE_DIR)/kernel.mk
10 include $(INCLUDE_DIR)/host.mk
11 include $(INCLUDE_DIR)/version.mk
12
13 override MAKEFLAGS=
14
15 SDK_NAME:=$(VERSION_DIST)-SDK-$(if $(CONFIG_VERSION_FILENAMES),$(VERSION_NUMBER)-)$(BOARD)$(if $(SUBTARGET),-$(SUBTARGET))$(if $(GCCV),_gcc-$(GCCV))$(DIR_SUFFIX).$(HOST_OS)-$(HOST_ARCH)
16 SDK_BUILD_DIR:=$(BUILD_DIR)/$(SDK_NAME)
17
18 STAGING_SUBDIR_HOST := staging_dir/host
19 STAGING_SUBDIR_TOOLCHAIN := staging_dir/toolchain-$(ARCH)$(ARCH_SUFFIX)_gcc-$(GCCV)_$(LIBC)-$(LIBCV)$(if $(CONFIG_arm),_eabi)
20
21 EXCLUDE_DIRS:=*/ccache \
22 */stamp \
23 */stampfiles \
24 */man \
25 */info \
26 */root-* \
27 initial \
28 *.install.clean \
29 *.install.flags \
30 *.install \
31 */doc
32
33 SDK_DIRS = \
34 $(STAGING_SUBDIR_HOST) \
35 $(STAGING_SUBDIR_TOOLCHAIN)
36
37 BASE_FEED:=$(shell git config --get remote.origin.url 2>/dev/null | sed -ne 's/^/src-git base /p')
38 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'))
39 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'))
40
41 KDIR_BASE = $(patsubst $(TOPDIR)/%,%,$(LINUX_DIR))
42
43 KERNEL_FILES_ARCH = \
44 Makefile* \
45 module.lds \
46 Kbuild.platforms \
47 */Platform \
48 include \
49 */include \
50 scripts \
51 kernel/asm-offsets.s
52
53 KERNEL_FILES_BASE := \
54 .config \
55 Makefile \
56 scripts \
57 include \
58 Module.symvers \
59 $(addprefix arch/$(LINUX_KARCH)/,$(KERNEL_FILES_ARCH))
60
61 KERNEL_FILES := $(patsubst $(TOPDIR)/%,%,$(wildcard $(addprefix $(LINUX_DIR)/,$(KERNEL_FILES_BASE))))
62
63 all: compile
64
65 $(BIN_DIR)/$(SDK_NAME).tar.bz2: clean
66 mkdir -p $(SDK_BUILD_DIR)/dl $(SDK_BUILD_DIR)/package
67 $(CP) $(INCLUDE_DIR) $(SCRIPT_DIR) $(TOPDIR)/docs $(SDK_BUILD_DIR)/
68 $(TAR) -cf - -C $(TOPDIR) \
69 `cd $(TOPDIR); find $(KDIR_BASE) -name \*.ko` \
70 $(foreach exclude,$(EXCLUDE_DIRS),--exclude="$(exclude)") \
71 $(SDK_DIRS) $(KERNEL_FILES) | \
72 $(TAR) -xf - -C $(SDK_BUILD_DIR)
73
74 @-( \
75 find \
76 $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/bin \
77 $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/usr/bin \
78 $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TOOLCHAIN)/bin \
79 $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TOOLCHAIN)/*/bin \
80 $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TOOLCHAIN)/libexec \
81 -type f; \
82 find \
83 $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/lib \
84 $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/usr/lib \
85 -type f -name \*.so\* -or -name \*.a; \
86 ) | xargs strip 2>/dev/null >/dev/null
87
88 mkdir -p $(SDK_BUILD_DIR)/target/linux
89 $(CP) $(GENERIC_PLATFORM_DIR) $(PLATFORM_DIR) $(SDK_BUILD_DIR)/target/linux/
90 rm -rf \
91 $(SDK_BUILD_DIR)/target/linux/*/files* \
92 $(SDK_BUILD_DIR)/target/linux/*/patches*
93 ./convert-config.pl $(TOPDIR)/.config > $(SDK_BUILD_DIR)/Config-build.in
94 $(CP) -L \
95 $(TOPDIR)/LICENSE \
96 $(TOPDIR)/rules.mk \
97 $(TOPDIR)/.config \
98 ./files/Config.in \
99 ./files/Makefile \
100 ./files/include/prepare.mk \
101 ./files/README.SDK \
102 $(SDK_BUILD_DIR)/
103 $(CP) \
104 $(TOPDIR)/package/Makefile \
105 $(SDK_BUILD_DIR)/package/
106
107 -rm -f $(SDK_BUILD_DIR)/feeds.conf.default
108 $(if $(BASE_FEED),echo "$(BASE_FEED)" > $(SDK_BUILD_DIR)/feeds.conf.default)
109 if [ -f $(TOPDIR)/feeds.conf ]; then \
110 cat $(TOPDIR)/feeds.conf >> $(SDK_BUILD_DIR)/feeds.conf.default; \
111 else \
112 cat $(TOPDIR)/feeds.conf.default >> $(SDK_BUILD_DIR)/feeds.conf.default; \
113 fi
114 $(SED) 's,^# REVISION:=.*,REVISION:=$(REVISION),g' $(SDK_BUILD_DIR)/include/version.mk
115 $(SED) '/LINUX_VERMAGIC:=/ { s,unknown,$(LINUX_VERMAGIC),g }' $(SDK_BUILD_DIR)/include/kernel.mk
116 find $(SDK_BUILD_DIR) -name .git | $(XARGS) rm -rf
117 find $(SDK_BUILD_DIR) -name .svn | $(XARGS) rm -rf
118 find $(SDK_BUILD_DIR) -name CVS | $(XARGS) rm -rf
119 (cd $(BUILD_DIR); \
120 tar cfj $@ $(SDK_NAME); \
121 )
122
123 download:
124 prepare:
125 compile: $(BIN_DIR)/$(SDK_NAME).tar.bz2
126 install: compile
127
128 clean:
129 rm -rf $(SDK_BUILD_DIR) $(BIN_DIR)/$(SDK_NAME).tar.bz2