f0e2bd12819de307bc635801a0d17df4c8becc2d
[openwrt/openwrt.git] / target / imagebuilder / files / Makefile
1 # Makefile for OpenWrt
2 #
3 # Copyright (C) 2007-2015 OpenWrt.org
4 #
5 # This is free software, licensed under the GNU General Public License v2.
6 # See /LICENSE for more information.
7 #
8
9 TOPDIR:=${CURDIR}
10 LC_ALL:=C
11 LANG:=C
12 export TOPDIR LC_ALL LANG
13 export OPENWRT_VERBOSE=s
14 all: help
15
16 export PATH:=$(TOPDIR)/staging_dir/host/bin:$(PATH)
17
18 ifneq ($(OPENWRT_BUILD),1)
19 override OPENWRT_BUILD=1
20 export OPENWRT_BUILD
21 endif
22
23 include rules.mk
24 include $(INCLUDE_DIR)/debug.mk
25 include $(INCLUDE_DIR)/depends.mk
26
27 include $(INCLUDE_DIR)/version.mk
28 export REVISION
29
30 define Helptext
31 Available Commands:
32 help: This help text
33 info: Show a list of available target profiles
34 clean: Remove images and temporary build files
35 image: Build an image (see below for more information).
36
37 Building images:
38 By default 'make image' will create an image with the default
39 target profile and package set. You can use the following parameters
40 to change that:
41
42 make image PROFILE="<profilename>" # override the default target profile
43 make image PACKAGES="<pkg1> [<pkg2> [<pkg3> ...]]" # include extra packages
44 make image FILES="<path>" # include extra files from <path>
45 make image BIN_DIR="<path>" # alternative output directory for the images
46 make image EXTRA_IMAGE_NAME="<string>" # Add this to the output image filename (sanitized)
47 endef
48 $(eval $(call shexport,Helptext))
49
50 help: FORCE
51 echo "$$$(call shvar,Helptext)"
52
53
54 # override variables from rules.mk
55 PACKAGE_DIR:=$(TOPDIR)/packages
56 LISTS_DIR:=$(subst $(space),/,$(patsubst %,..,$(subst /,$(space),$(TARGET_DIR))))$(DL_DIR)
57 OPKG:= \
58 IPKG_NO_SCRIPT=1 \
59 IPKG_INSTROOT="$(TARGET_DIR)" \
60 $(STAGING_DIR_HOST)/bin/opkg \
61 -f $(TOPDIR)/repositories.conf \
62 --force-depends \
63 --force-overwrite \
64 --force-postinstall \
65 --cache $(DL_DIR) \
66 --lists-dir $(LISTS_DIR) \
67 --offline-root $(TARGET_DIR) \
68 --add-dest root:/ \
69 --add-arch all:100 \
70 --add-arch $(ARCH_PACKAGES):200
71
72 include $(INCLUDE_DIR)/target.mk
73 -include .profiles.mk
74
75 USER_PROFILE ?= $(firstword $(PROFILE_NAMES))
76 PROFILE_LIST = $(foreach p,$(PROFILE_NAMES), \
77 echo '$(patsubst DEVICE_%,%,$(p)):'; $(if $($(p)_NAME),echo ' $(subst ','"'"',$($(p)_NAME))'; ) echo ' Packages: $($(p)_PACKAGES)'; \
78 )
79
80 .profiles.mk: .targetinfo
81 $(SCRIPT_DIR)/target-metadata.pl profile_mk $< '$(BOARD)$(if $(SUBTARGET),/$(SUBTARGET))' > $@
82
83 staging_dir/host/.prereq-build: include/prereq-build.mk
84 mkdir -p tmp
85 @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prereq-build.mk prereq 2>/dev/null || { \
86 echo "Prerequisite check failed. Use FORCE=1 to override."; \
87 false; \
88 }
89 ifneq ($(realpath $(TOPDIR)/include/prepare.mk),)
90 @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prepare.mk prepare 2>/dev/null || { \
91 echo "Preparation failed."; \
92 false; \
93 }
94 endif
95 touch $@
96
97 _call_info: FORCE
98 echo 'Current Target: "$(BOARD)$(if $(SUBTARGET), ($(BOARDNAME)))"'
99 echo 'Default Packages: $(DEFAULT_PACKAGES)'
100 echo 'Available Profiles:'
101 echo; $(PROFILE_LIST)
102
103 BUILD_PACKAGES:=$(USER_PACKAGES) $(sort $(DEFAULT_PACKAGES) $($(USER_PROFILE)_PACKAGES) kernel)
104 # "-pkgname" in the package list means remove "pkgname" from the package list
105 BUILD_PACKAGES:=$(filter-out $(filter -%,$(BUILD_PACKAGES)) $(patsubst -%,%,$(filter -%,$(BUILD_PACKAGES))),$(BUILD_PACKAGES))
106 PACKAGES:=
107
108 _call_image: staging_dir/host/.prereq-build
109 echo 'Building images for $(BOARD)$(if $($(USER_PROFILE)_NAME), - $($(USER_PROFILE)_NAME))'
110 echo 'Packages: $(BUILD_PACKAGES)'
111 echo
112 rm -rf $(TARGET_DIR)
113 mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR) $(DL_DIR)
114 if [ ! -f "$(PACKAGE_DIR)/Packages" ] || [ ! -f "$(PACKAGE_DIR)/Packages.gz" ] || [ "`find $(PACKAGE_DIR) -cnewer $(PACKAGE_DIR)/Packages.gz`" ]; then \
115 echo "Package list missing or not up-to-date, generating it.";\
116 $(MAKE) package_index; \
117 else \
118 mkdir -p $(TARGET_DIR)/tmp; \
119 $(OPKG) update || true; \
120 fi
121 $(MAKE) package_install
122 ifneq ($(USER_FILES),)
123 $(MAKE) copy_files
124 endif
125 $(MAKE) -s package_postinst
126 $(MAKE) -s build_image
127 $(MAKE) -s checksum
128
129 package_index: FORCE
130 @echo
131 @echo Building package index...
132 @mkdir -p $(TMP_DIR) $(TARGET_DIR)/tmp
133 (cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages && \
134 gzip -9nc Packages > Packages.gz \
135 ) >/dev/null 2>/dev/null
136 $(OPKG) update || true
137
138 package_install: FORCE
139 @echo
140 @echo Installing packages...
141 $(OPKG) install $(firstword $(wildcard $(PACKAGE_DIR)/libc_*.ipk $(PACKAGE_DIR)/base/libc_*.ipk))
142 $(OPKG) install $(firstword $(wildcard $(PACKAGE_DIR)/kernel_*.ipk $(PACKAGE_DIR)/base/kernel_*.ipk))
143 $(OPKG) install $(BUILD_PACKAGES)
144 rm -f $(TARGET_DIR)/usr/lib/opkg/lists/*
145
146 copy_files: FORCE
147 @echo
148 @echo Copying extra files
149 @$(call file_copy,$(USER_FILES)/*,$(TARGET_DIR)/)
150
151 package_postinst: FORCE
152 @echo
153 @echo Cleaning up
154 @rm -f $(TARGET_DIR)/tmp/opkg.lock
155 @echo
156 @echo Activating init scripts
157 @mkdir -p $(TARGET_DIR)/etc/rc.d
158 @( \
159 cd $(TARGET_DIR); \
160 for script in ./usr/lib/opkg/info/*.postinst; do \
161 IPKG_INSTROOT=$(TARGET_DIR) $$(which bash) $$script; \
162 done || true \
163 )
164 rm -f $(TARGET_DIR)/usr/lib/opkg/info/*.postinst
165 $(if $(CONFIG_CLEAN_IPKG),rm -rf $(TARGET_DIR)/usr/lib/opkg)
166
167 build_image: FORCE
168 @echo
169 @echo Building images...
170 $(NO_TRACE_MAKE) -C target/linux/$(BOARD)/image install TARGET_BUILD=1 IB=1 EXTRA_IMAGE_NAME="$(EXTRA_IMAGE_NAME)" \
171 $(if $(USER_PROFILE),PROFILE="$(USER_PROFILE)")
172
173 checksum: FORCE
174 @echo
175 @echo Calculating checksums...
176 @$(call sha256sums,$(BIN_DIR))
177
178 clean:
179 rm -rf $(TMP_DIR) $(DL_DIR) $(TARGET_DIR) $(BIN_DIR)
180
181
182 info:
183 (unset PROFILE FILES PACKAGES MAKEFLAGS; $(MAKE) -s _call_info)
184
185 PROFILE_FILTER = $(filter DEVICE_$(PROFILE) $(PROFILE),$(PROFILE_NAMES))
186
187 image:
188 ifneq ($(PROFILE),)
189 ifeq ($(PROFILE_FILTER),)
190 @echo 'Profile "$(PROFILE)" does not exist!'
191 @echo 'Use "make info" to get a list of available profile names.'
192 @exit 1
193 endif
194 endif
195 (unset PROFILE FILES PACKAGES MAKEFLAGS; \
196 $(MAKE) -s _call_image \
197 $(if $(PROFILE),USER_PROFILE="$(PROFILE_FILTER)") \
198 $(if $(FILES),USER_FILES="$(FILES)") \
199 $(if $(PACKAGES),USER_PACKAGES="$(PACKAGES)") \
200 $(if $(BIN_DIR),BIN_DIR="$(BIN_DIR)"))
201
202 .SILENT: help info image
203