a96f8618e839681774ea3a394bb3437084e5870f
[openwrt/openwrt.git] / target / imagebuilder / Makefile
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 include $(TOPDIR)/rules.mk
9 include $(INCLUDE_DIR)/kernel.mk
10 include $(INCLUDE_DIR)/version.mk
11 include $(INCLUDE_DIR)/feeds.mk
12
13 override MAKEFLAGS=
14
15 IB_NAME:=$(VERSION_DIST_SANITIZED)-imagebuilder-$(if $(CONFIG_VERSION_FILENAMES),$(VERSION_NUMBER)-)$(BOARD)$(if $(SUBTARGET),-$(SUBTARGET)).$(HOST_OS)-$(HOST_ARCH)
16 PKG_BUILD_DIR:=$(BUILD_DIR)/$(IB_NAME)
17 IB_KDIR:=$(patsubst $(TOPDIR)/%,$(PKG_BUILD_DIR)/%,$(KERNEL_BUILD_DIR))
18 IB_LDIR:=$(patsubst $(TOPDIR)/%,$(PKG_BUILD_DIR)/%,$(LINUX_DIR))
19 IB_DTSDIR:=$(patsubst $(TOPDIR)/%,$(PKG_BUILD_DIR)/%,$(LINUX_DIR))/arch/$(LINUX_KARCH)/boot/dts/
20 IB_IDIR:=$(patsubst $(TOPDIR)/%,$(PKG_BUILD_DIR)/%,$(STAGING_DIR_IMAGE))
21
22 all: compile
23
24 $(BIN_DIR)/$(IB_NAME).tar.xz: clean
25 rm -rf $(PKG_BUILD_DIR)
26 mkdir -p $(IB_KDIR) $(IB_LDIR) $(PKG_BUILD_DIR)/staging_dir/host/lib \
27 $(PKG_BUILD_DIR)/target $(PKG_BUILD_DIR)/scripts $(IB_DTSDIR)
28 -cp $(TOPDIR)/.config $(PKG_BUILD_DIR)/.config
29 $(CP) -L \
30 $(INCLUDE_DIR) $(SCRIPT_DIR) \
31 $(TOPDIR)/rules.mk \
32 ./files/Makefile \
33 ./files/repositories.conf \
34 $(TMP_DIR)/.targetinfo \
35 $(TMP_DIR)/.packageinfo \
36 $(PKG_BUILD_DIR)/
37
38 ifeq ($(CONFIG_IB_STANDALONE),)
39 echo '## Remote package repositories' >> $(PKG_BUILD_DIR)/repositories.conf
40 $(call FeedSourcesAppend,$(PKG_BUILD_DIR)/repositories.conf)
41 $(VERSION_SED_SCRIPT) $(PKG_BUILD_DIR)/repositories.conf
42 endif
43
44 ifeq ($(CONFIG_BUILDBOT),)
45 $(INSTALL_DIR) $(PKG_BUILD_DIR)/packages
46 echo '' >> $(PKG_BUILD_DIR)/repositories.conf
47 echo '## This is the local package repository, do not remove!' >> $(PKG_BUILD_DIR)/repositories.conf
48 echo 'src imagebuilder file:packages' >> $(PKG_BUILD_DIR)/repositories.conf
49
50 ifeq ($(CONFIG_IB_STANDALONE),)
51 $(FIND) $(call FeedPackageDir,libc) -type f \
52 \( -name 'libc_*.ipk' -or -name 'kernel_*.ipk' -or -name 'kmod-*.ipk' \) \
53 -exec $(CP) -t $(PKG_BUILD_DIR)/packages {} +
54 else
55 $(FIND) $(wildcard $(PACKAGE_SUBDIRS)) -type f -name '*.ipk' \
56 -exec $(CP) -t $(PKG_BUILD_DIR)/packages/ {} +
57 endif
58 else
59 $(FIND) $(call FeedPackageDir,libc) -type f \
60 \( -name 'libc_*.ipk' -or -name 'kernel_*.ipk' \) \
61 -exec $(CP) -t $(IB_LDIR)/ {} +
62 endif
63
64 ifneq ($(CONFIG_SIGNATURE_CHECK),)
65 echo '' >> $(PKG_BUILD_DIR)/repositories.conf
66 echo 'option check_signature' >> $(PKG_BUILD_DIR)/repositories.conf
67 $(INSTALL_DIR) $(PKG_BUILD_DIR)/keys
68 $(CP) -L $(STAGING_DIR_ROOT)/etc/opkg/keys/ $(PKG_BUILD_DIR)/
69 $(CP) -L $(STAGING_DIR_ROOT)/usr/sbin/opkg-key $(PKG_BUILD_DIR)/scripts/
70 endif
71
72 $(CP) $(TOPDIR)/target/linux $(PKG_BUILD_DIR)/target/
73 if [ -d $(TOPDIR)/staging_dir/host/lib/grub ]; then \
74 $(CP) $(TOPDIR)/staging_dir/host/lib/grub/ $(PKG_BUILD_DIR)/staging_dir/host/lib; \
75 fi
76 rm -rf \
77 $(PKG_BUILD_DIR)/target/linux/*/files{,-*} \
78 $(PKG_BUILD_DIR)/target/linux/*/patches{,-*} \
79 $(PKG_BUILD_DIR)/target/linux/generic/{pending,backport,hack}{,-*}
80 -cp $(KERNEL_BUILD_DIR)/* $(IB_KDIR)/ # don't copy subdirectories here
81 -cp $(LINUX_DIR)/.config $(IB_LDIR)/
82 rm -f $(IB_KDIR)/root.*
83 rm -f $(IB_KDIR)/vmlinux.debug
84 if [ -x $(LINUX_DIR)/scripts/dtc/dtc ]; then \
85 $(INSTALL_DIR) $(IB_LDIR)/scripts/dtc; \
86 $(INSTALL_BIN) $(LINUX_DIR)/scripts/dtc/dtc $(IB_LDIR)/scripts/dtc/dtc; \
87 fi
88 if [ -d $(LINUX_DIR)/arch/$(LINUX_KARCH)/boot/dts ]; then \
89 $(CP) -L $(LINUX_DIR)/arch/$(LINUX_KARCH)/boot/dts/* $(IB_DTSDIR); \
90 fi
91 $(SED) 's,^# REVISION:=.*,REVISION:=$(REVISION),g' $(PKG_BUILD_DIR)/include/version.mk
92 find $(PKG_BUILD_DIR) -name CVS -o -name .git -o -name .svn \
93 | $(XARGS) rm -rf
94 $(INSTALL_DIR) $(IB_IDIR)
95 -$(CP) $(STAGING_DIR_IMAGE)/* $(IB_IDIR)/
96 $(INSTALL_DIR) $(PKG_BUILD_DIR)/staging_dir/host/bin
97 $(CP) $(STAGING_DIR_HOST)/bin/* $(PKG_BUILD_DIR)/staging_dir/host/bin/
98 (cd $(PKG_BUILD_DIR); find staging_dir/host/bin/ $(IB_LDIR)/scripts/dtc/ -type f | \
99 $(XARGS) $(SCRIPT_DIR)/bundle-libraries.sh $(PKG_BUILD_DIR)/staging_dir/host)
100 $(CP) $(TOPDIR)/staging_dir/host/lib/libfakeroot* $(PKG_BUILD_DIR)/staging_dir/host/lib
101 STRIP=$(STAGING_DIR_HOST)/bin/sstrip $(SCRIPT_DIR)/rstrip.sh $(PKG_BUILD_DIR)/staging_dir/host/bin/
102 (cd $(BUILD_DIR); \
103 tar -I '$(STAGING_DIR_HOST)/bin/xz -7e -T$(if $(filter 1,$(NPROC)),2,0)' -cf $@ $(IB_NAME) \
104 --mtime="$(shell date --date=@$(SOURCE_DATE_EPOCH))"; \
105 )
106
107 download:
108 prepare:
109 compile: $(BIN_DIR)/$(IB_NAME).tar.xz
110 install: compile
111
112 clean: FORCE
113 rm -rf $(PKG_BUILD_DIR) $(BIN_DIR)/$(IB_NAME).tar.xz