8e6c6d746262fb617720aa23034e23963267f620
[openwrt/svn-archive/archive.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)/tmp/opkg.conf \
62 --force-depends \
63 --force-overwrite \
64 --force-run-hooks
65
66 define Profile
67 $(eval $(call Profile/Default))
68 $(eval $(call Profile/$(1)))
69 ifeq ($(USER_PROFILE),)
70 USER_PROFILE:=$(1)
71 endif
72 $(1)_NAME:=$(NAME)
73 $(1)_PACKAGES:=$(PACKAGES)
74 PROFILE_LIST += \
75 echo '$(1):'; [ -z '$(NAME)' ] || echo ' $(NAME)'; echo ' Packages: $(PACKAGES)';
76 endef
77
78 include $(INCLUDE_DIR)/target.mk
79
80 _call_info: FORCE
81 echo 'Current Target: "$(BOARD)$(if $(SUBTARGET), ($(BOARDNAME)))"'
82 echo 'Default Packages: $(DEFAULT_PACKAGES)'
83 echo 'Available Profiles:'
84 echo; $(PROFILE_LIST)
85
86 $(TOPDIR)/tmp/opkg.conf: FORCE
87 @mkdir -p $(TOPDIR)/tmp
88 @mkdir -p $(TARGET_DIR)/tmp
89 @echo 'dest root /' > $@
90 @echo 'src packages file:$(PACKAGE_DIR)' >> $@
91 @echo 'arch all 100' >> $@
92 ifneq ($(CONFIG_TARGET_adm5120),y)
93 @echo 'arch $(BOARD) 200' >> $@
94 else
95 @echo 'arch $(BOARD)_$(ARCH) 200' >> $@
96 endif
97 @echo 'option offline_root $(TARGET_DIR)' >> $@
98
99 BUILD_PACKAGES:=$(sort $(DEFAULT_PACKAGES) $(USER_PACKAGES) $($(USER_PROFILE)_PACKAGES) kernel)
100 # "-pkgname" in the package list means remove "pkgname" from the package list
101 BUILD_PACKAGES:=$(filter-out $(filter -%,$(BUILD_PACKAGES)) $(patsubst -%,%,$(filter -%,$(BUILD_PACKAGES))),$(BUILD_PACKAGES))
102
103 _call_image:
104 echo 'Building images for $(BOARD)$(if $($(USER_PROFILE)_NAME), - $($(USER_PROFILE)_NAME))'
105 echo 'Packages: $(BUILD_PACKAGES)'
106 echo
107 rm -rf $(TARGET_DIR)
108 mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR)
109 $(MAKE) package_index
110 $(MAKE) package_install
111 ifneq ($(USER_FILES),)
112 $(MAKE) copy_files
113 endif
114 $(MAKE) package_postinst
115 $(MAKE) build_image
116
117 package_index: $(TOPDIR)/tmp/opkg.conf FORCE
118 @echo
119 @echo Building package index...
120 (cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages && \
121 gzip -9c Packages > Packages.gz \
122 ) >/dev/null 2>/dev/null
123 $(OPKG) update
124
125 package_install: FORCE
126 @echo
127 @echo Installing packages...
128 $(OPKG) install $(BUILD_PACKAGES)
129
130 copy_files: FORCE
131 @echo
132 @echo Copying extra files
133 $(CP) $(USER_FILES)/* $(TARGET_DIR)/
134
135 package_postinst: FORCE
136 @echo
137 @echo Cleaning up
138 @rm -f $(TARGET_DIR)/tmp/opkg.lock
139 @echo
140 @echo Activating init scripts
141 @( \
142 cd $(TARGET_DIR); \
143 for script in ./etc/init.d/*; do \
144 grep '#!/bin/sh /etc/rc.common' $$script >/dev/null || continue; \
145 IPKG_INSTROOT=$(TARGET_DIR) $(which bash) ./etc/rc.common $$script enable; \
146 done || true; \
147 )
148
149 build_image: FORCE
150 @echo
151 @echo Building images...
152 $(NO_TRACE_MAKE) -C target/linux/$(BOARD)/image install TARGET_BUILD=1 IB=1
153
154 clean:
155 rm -rf tmp $(TARGET_DIR) $(BIN_DIR)
156
157
158 info:
159 (unset PROFILE FILES PACKAGES MAKEFLAGS; $(MAKE) -s _call_info)
160
161 image:
162 (unset PROFILE FILES PACKAGES MAKEFLAGS; \
163 $(MAKE) _call_image \
164 $(if $(PROFILE),USER_PROFILE="$(PROFILE)") \
165 $(if $(FILES),USER_FILES="$(FILES)") \
166 $(if $(PACKAGES),USER_PACKAGES="$(PACKAGES)"))
167
168 .SILENT: help info image
169