[imagebuilder]
[openwrt.git] / target / imagebuilder / files / Makefile
1 # Makefile for OpenWrt
2 #
3 # Copyright (C) 2007-2010 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 KBUILD_VERBOSE=99
14 all: help
15
16 include $(TOPDIR)/include/host.mk
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
46 endef
47 $(eval $(call shexport,Helptext))
48
49 help: FORCE
50 echo "$$$(call shvar,Helptext)"
51
52
53 # override variables from rules.mk
54 PACKAGE_DIR:=$(TOPDIR)/packages
55 OPKG:= \
56 IPKG_TMP="$(TOPDIR)/tmp/ipkgtmp" \
57 IPKG_INSTROOT="$(TARGET_DIR)" \
58 IPKG_CONF_DIR="$(TOPDIR)/tmp" \
59 IPKG_OFFLINE_ROOT="$(TARGET_DIR)" \
60 $(STAGING_DIR_HOST)/bin/opkg \
61 -f $(TOPDIR)/repositories.conf \
62 --force-depends \
63 --force-overwrite \
64 --force-postinstall \
65 --cache $(TOPDIR)/dl \
66 --offline-root $(TARGET_DIR) \
67 --add-dest root:/ \
68 --add-arch all:100 \
69 --add-arch $(ARCH_PACKAGES):200
70
71 define Profile
72 $(eval $(call Profile/Default))
73 $(eval $(call Profile/$(1)))
74 ifeq ($(USER_PROFILE),)
75 USER_PROFILE:=$(1)
76 endif
77 $(1)_NAME:=$(NAME)
78 $(1)_PACKAGES:=$(PACKAGES)
79 PROFILE_LIST += \
80 echo '$(1):'; [ -z '$(NAME)' ] || echo ' $(NAME)'; echo ' Packages: $(PACKAGES)';
81 endef
82
83 include $(INCLUDE_DIR)/target.mk
84
85 _call_info: FORCE
86 echo 'Current Target: "$(BOARD)$(if $(SUBTARGET), ($(BOARDNAME)))"'
87 echo 'Default Packages: $(DEFAULT_PACKAGES)'
88 echo 'Available Profiles:'
89 echo; $(PROFILE_LIST)
90
91 BUILD_PACKAGES:=$(sort $(DEFAULT_PACKAGES) $(USER_PACKAGES) $($(USER_PROFILE)_PACKAGES) kernel)
92 # "-pkgname" in the package list means remove "pkgname" from the package list
93 BUILD_PACKAGES:=$(filter-out $(filter -%,$(BUILD_PACKAGES)) $(patsubst -%,%,$(filter -%,$(BUILD_PACKAGES))),$(BUILD_PACKAGES))
94 PACKAGES:=
95
96 _call_image:
97 echo 'Building images for $(BOARD)$(if $($(USER_PROFILE)_NAME), - $($(USER_PROFILE)_NAME))'
98 echo 'Packages: $(BUILD_PACKAGES)'
99 echo
100 rm -rf $(TARGET_DIR)
101 mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR)
102 $(MAKE) package_index
103 $(MAKE) package_install
104 ifneq ($(USER_FILES),)
105 $(MAKE) copy_files
106 endif
107 $(MAKE) package_postinst
108 $(MAKE) build_image
109
110 package_index: FORCE
111 @echo
112 @echo Building package index...
113 @mkdir -p $(TOPDIR)/tmp $(TOPDIR)/dl $(TARGET_DIR)/tmp
114 (cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages && \
115 gzip -9c Packages > Packages.gz \
116 ) >/dev/null 2>/dev/null
117 $(OPKG) update
118
119 package_install: FORCE
120 @echo
121 @echo Installing packages...
122 $(OPKG) install $(BUILD_PACKAGES)
123
124 copy_files: FORCE
125 @echo
126 @echo Copying extra files
127 $(CP) $(USER_FILES)/* $(TARGET_DIR)/
128
129 package_postinst: FORCE
130 @echo
131 @echo Cleaning up
132 @rm -f $(TARGET_DIR)/tmp/opkg.lock
133 @echo
134 @echo Activating init scripts
135 @( \
136 cd $(TARGET_DIR); \
137 for script in ./etc/init.d/*; do \
138 grep '#!/bin/sh /etc/rc.common' $$script >/dev/null || continue; \
139 IPKG_INSTROOT=$(TARGET_DIR) $(which bash) ./etc/rc.common $$script enable; \
140 done || true; \
141 )
142
143 build_image: FORCE
144 @echo
145 @echo Building images...
146 $(NO_TRACE_MAKE) -C target/linux/$(BOARD)/image install TARGET_BUILD=1 IB=1
147
148 clean:
149 rm -rf $(TOPDIR)/tmp $(TOPDIR)/dl $(TARGET_DIR) $(BIN_DIR)
150
151
152 info:
153 (unset PROFILE FILES PACKAGES MAKEFLAGS; $(MAKE) -s _call_info)
154
155 image:
156 (unset PROFILE FILES PACKAGES MAKEFLAGS; \
157 $(MAKE) _call_image \
158 $(if $(PROFILE),USER_PROFILE="$(PROFILE)") \
159 $(if $(FILES),USER_FILES="$(FILES)") \
160 $(if $(PACKAGES),USER_PACKAGES="$(PACKAGES)"))
161
162 .SILENT: help info image
163
This page took 0.042975 seconds and 5 git commands to generate.