merge imagebuilder change from r18117
[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 echo 'Building images for $(BOARD)$(if $($(PROFILE)_NAME), - $($(PROFILE)_NAME))'
92 echo 'Packages: $(BUILD_PACKAGES)'
93 echo
94 rm -rf $(TARGET_DIR)
95 mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR)
96 $(MAKE) package_index
97 $(MAKE) package_install
98 ifneq ($(FILES),)
99 $(MAKE) copy_files
100 endif
101 $(MAKE) package_postinst
102 $(MAKE) build_image
103
104 package_index: $(TOPDIR)/tmp/ipkg.conf FORCE
105 @echo
106 @echo Building package index...
107 (cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages && \
108 gzip -9c Packages > Packages.gz \
109 ) >/dev/null 2>/dev/null
110 $(IPKG) update
111
112 package_install: FORCE
113 @echo
114 @echo Installing packages...
115 $(IPKG) install $(BUILD_PACKAGES)
116
117 copy_files: FORCE
118 @echo
119 @echo Copying extra files
120 $(CP) $(FILES)/* $(TARGET_DIR)/
121
122 package_postinst: FORCE
123 @echo
124 @echo Activating init scripts
125 @( \
126 cd $(TARGET_DIR); \
127 for script in ./etc/init.d/*; do \
128 grep '#!/bin/sh /etc/rc.common' $$script >/dev/null || continue; \
129 IPKG_INSTROOT=$(TARGET_DIR) $(which bash) ./etc/rc.common $$script enable; \
130 done || true; \
131 )
132
133 build_image: FORCE
134 @echo
135 @echo Building images...
136 $(NO_TRACE_MAKE) -C target/linux/$(BOARD)/image install TARGET_BUILD=1 IB=1
137
138 clean:
139 rm -rf tmp $(TARGET_DIR) $(BIN_DIR)
140
141
142 .SILENT: help info image
143