[8.09] fix ImageBuilder
[openwrt/svn-archive/archive.git] / target / imagebuilder / files / Makefile
1 # Makefile for OpenWrt
2 #
3 # Copyright (C) 2007-2009 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 include $(INCLUDE_DIR)/version.mk
27
28 define Helptext
29 Available Commands:
30 help: This help text
31 info: Show a list of available target profiles
32 clean: Remove images and temporary build files
33 image: Build an image (see below for more information).
34
35 Building images:
36 By default 'make image' will create an image with the default
37 target profile and package set. You can use the following parameters
38 to change that:
39
40 make image PROFILE="<profilename>" # override the default target profile
41 make image PACKAGES="<pkg1> [<pkg2> [<pkg3> ...]]" # include extra packages
42 make image FILES="<path>" # include extra files from <path>
43
44 endef
45 $(eval $(call shexport,Helptext))
46
47 help: FORCE
48 echo "$$$(call shvar,Helptext)"
49
50
51 # override variables from rules.mk
52 PACKAGE_DIR:=$(TOPDIR)/packages
53 IPKG:= \
54 IPKG_TMP="$(TOPDIR)/tmp/ipkgtmp" \
55 IPKG_INSTROOT="$(TARGET_DIR)" \
56 IPKG_CONF_DIR="$(TOPDIR)/tmp" \
57 IPKG_OFFLINE_ROOT="$(TARGET_DIR)" \
58 $(SCRIPT_DIR)/ipkg -force-defaults
59
60 define Profile
61 $(eval $(call Profile/Default))
62 $(eval $(call Profile/$(1)))
63 ifeq ($(PROFILE),)
64 PROFILE:=$(1)
65 endif
66 $(1)_NAME:=$(NAME)
67 $(1)_PACKAGES:=$(PACKAGES)
68 PROFILE_LIST += \
69 echo '$(1):'; [ -z '$(NAME)' ] || echo ' $(NAME)'; echo ' Packages: $(PACKAGES)';
70 endef
71
72 include $(INCLUDE_DIR)/target.mk
73
74 info: FORCE
75 echo 'Current Target: "$(BOARD)$(if $(SUBTARGET), ($(BOARDNAME)))"'
76 echo 'Default Packages: $(DEFAULT_PACKAGES)'
77 echo 'Available Profiles:'
78 echo; $(PROFILE_LIST)
79
80 $(TOPDIR)/tmp/ipkg.conf: FORCE
81 @mkdir -p $(TOPDIR)/tmp
82 @echo 'dest root /' > $@
83 @echo 'src packages file:$(PACKAGE_DIR)' >> $@
84
85 BUILD_PACKAGES:=$(sort $(DEFAULT_PACKAGES) $(PACKAGES) $($(PROFILE)_PACKAGES) kernel)
86 BUILD_PACKAGES:=$(patsubst base-files,base-files-$(BOARD),$(BUILD_PACKAGES))
87 # "-pkgname" in the package list means remove "pkgname" from the package list
88 BUILD_PACKAGES:=$(filter-out $(filter -%,$(BUILD_PACKAGES)) $(patsubst -%,%,$(filter -%,$(BUILD_PACKAGES))),$(BUILD_PACKAGES))
89
90 image:
91 if [ -z "$($(PROFILE)_NAME)" ]; then \
92 echo Profile $(PROFILE) not found.; \
93 echo 'Use "make info" to get a list of available target profiles'; \
94 false; \
95 fi
96 echo 'Building images for $(BOARD) - $($(PROFILE)_NAME)'
97 echo 'Packages: $(BUILD_PACKAGES)'
98 echo
99 rm -rf $(TARGET_DIR)
100 mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR)
101 $(MAKE) package_index
102 $(MAKE) package_install
103 ifneq ($(FILES),)
104 $(MAKE) copy_files
105 endif
106 $(MAKE) package_postinst
107 $(MAKE) build_image
108
109 package_index: $(TOPDIR)/tmp/ipkg.conf FORCE
110 @echo
111 @echo Building package index...
112 (cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages && \
113 gzip -9c Packages > Packages.gz \
114 ) >/dev/null 2>/dev/null
115 $(IPKG) update
116
117 package_install: FORCE
118 @echo
119 @echo Installing packages...
120 $(IPKG) install $(BUILD_PACKAGES)
121
122 copy_files: FORCE
123 @echo
124 @echo Copying extra files
125 $(CP) $(FILES)/* $(TARGET_DIR)/
126
127 package_postinst: FORCE
128 @echo
129 @echo Activating init scripts
130 @( \
131 cd $(TARGET_DIR); \
132 for script in ./etc/init.d/*; do \
133 grep '#!/bin/sh /etc/rc.common' $$script >/dev/null || continue; \
134 IPKG_INSTROOT=$(TARGET_DIR) $(which bash) ./etc/rc.common $$script enable; \
135 done || true; \
136 )
137
138 build_image: FORCE
139 @echo
140 @echo Building images...
141 $(NO_TRACE_MAKE) -C target/linux/$(BOARD)/image install TARGET_BUILD=1 IB=1
142
143 clean:
144 rm -rf tmp $(TARGET_DIR) $(BIN_DIR)
145
146
147 .SILENT: help info image
148