Add initial version of the new Image Builder
[openwrt-10.03/.git] / target / imagebuilder / files / Makefile
1 # Makefile for the OpenWrt Image Builder
2 #
3 # Copyright (C) 2006-2007 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 export TOPDIR=${CURDIR}
10
11 all: help
12
13 include rules.mk
14 include .config
15
16 SHELL:=/usr/bin/env bash
17 export LC_ALL=C
18 export LANG=C
19 ifeq ($(KBUILD_VERBOSE),99)
20   MAKE:=3>/dev/null $(MAKE)
21 endif
22 export IS_TTY=$(shell tty -s && echo 1 || echo 0)
23
24 # override variables from rules.mk
25 PACKAGE_DIR:=$(TOPDIR)/packages
26 IPKG:= \
27   IPKG_TMP="$(TOPDIR)/tmp/ipkgtmp" \
28   IPKG_INSTROOT="$(TARGET_DIR)" \
29   IPKG_CONF_DIR="$(TOPDIR)/tmp" \
30   IPKG_OFFLINE_ROOT="$(TARGET_DIR)" \
31   $(SCRIPT_DIR)/ipkg -force-defaults
32
33
34 define Profile/Default
35   ID:=
36   NAME:=
37   PACKAGES:=
38 endef
39
40 define Profile
41   $(eval $(call Profile/Default))
42   $(eval $(call Profile/$(1)))
43   ifneq ($(ID),)
44     ifeq ($(PROFILE),)
45       PROFILE:=$(ID)
46     endif
47         $(ID)_NAME:=$(NAME)
48         $(ID)_PACKAGES:=$(PACKAGES)
49     PROFILE_LIST += \
50                 echo '$(ID):'; echo '   $(NAME)';
51   endif
52 endef
53
54 include .target.mk
55
56 define Helptext
57 Available Commands:
58         help:   This help text
59         info:   Show a list of available target profiles
60         clean:  Remove images and temporary build files
61         image:  Build an image (see below for more information).
62
63 Building images:
64         By default 'make image' will create an image with the default
65         target profile and package set. You can use the following parameters
66         to change that:
67         
68         make image PROFILE="<profilename>" # override the default target profile
69         make image PACKAGES="<pkg1> [<pkg2> [<pkg3> ...]]" # include extra packages
70         make image FILES="<path>" # include extra files from <path>
71
72 endef
73 $(eval $(call shexport,Helptext))
74
75 help: FORCE
76         echo "$$$(call shvar,Helptext)"
77
78 info: FORCE
79         echo 'Current Target: "$(BOARDNAME)"'
80         echo 'Available Profiles:'
81         echo; $(PROFILE_LIST)
82
83 $(TOPDIR)/tmp/ipkg.conf: FORCE
84         @mkdir -p $(TOPDIR)/tmp
85         @echo 'dest root /' > $@
86         @echo 'src packages file:$(TOPDIR)/packages' >> $@
87
88 BUILD_PACKAGES:=$(sort $(DEFAULT_PACKAGES) $(PACKAGES) $($(PROFILE)_PACKAGES) kernel)
89 BUILD_PACKAGES:=$(patsubst base-files,base-files-$(BOARD)-$(KERNEL),$(BUILD_PACKAGES))
90
91 image: $(TOPDIR)/tmp/ipkg.conf
92         if [ -z "$($(PROFILE)_NAME)" ]; then \
93                 echo Profile $(PROFILE) not found.; \
94                 echo 'Use "make info" to get a list of available target profiles'; \
95                 false; \
96         fi
97         echo 'Building images for $(BOARDNAME) - $($(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 ($(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         (cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages) >/dev/null 2>/dev/null
114         $(IPKG) update
115
116 package_install: FORCE
117         @echo
118         @echo Installing packages...
119         $(IPKG) install $(BUILD_PACKAGES)
120
121 copy_files: FORCE
122         @echo
123         @echo Copying extra files
124         $(CP) $(FILES)/* $(TARGET_DIR)/
125
126 package_postinst: FORCE
127         @echo
128         @echo Activating init scripts
129         ( \
130                 cd $(BUILD_DIR)/root; \
131                 for script in ./etc/init.d/*; do \
132                         grep '#!/bin/sh /etc/rc.common' $$script >/dev/null || continue; \
133                         IPKG_INSTROOT=$(BUILD_DIR)/root $(which bash) ./etc/rc.common $$script enable; \
134                 done; \
135         )
136
137 build_image: FORCE
138         @echo
139         @echo Building images...
140         $(NO_TRACE_MAKE) -C target/linux/$(BOARD)-$(KERNEL)/image install IB=1
141         
142 clean:
143         rm -rf tmp $(TARGET_DIR)
144
145 .PHONY: FORCE
146 .SILENT: help info image
147 %: ;