[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)/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         @$(TOPDIR)/scripts/opkg-generate-config.sh $(TARGET_DIR)
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: $(TOPDIR)/tmp/opkg.conf FORCE
111         @echo
112         @echo Building package index...
113         (cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages && \
114                 gzip -9c Packages > Packages.gz \
115         ) >/dev/null 2>/dev/null
116         $(OPKG) update
117
118 package_install: FORCE
119         @echo
120         @echo Installing packages...
121         $(OPKG) install $(BUILD_PACKAGES)
122
123 copy_files: FORCE
124         @echo
125         @echo Copying extra files
126         $(CP) $(USER_FILES)/* $(TARGET_DIR)/
127
128 package_postinst: FORCE
129         @echo
130         @echo Cleaning up
131         @rm -f $(TARGET_DIR)/tmp/opkg.lock
132         @echo
133         @echo Activating init scripts
134         @( \
135                 cd $(TARGET_DIR); \
136                 for script in ./etc/init.d/*; do \
137                         grep '#!/bin/sh /etc/rc.common' $$script >/dev/null || continue; \
138                         IPKG_INSTROOT=$(TARGET_DIR) $(which bash) ./etc/rc.common $$script enable; \
139                 done || true; \
140         )
141
142 build_image: FORCE
143         @echo
144         @echo Building images...
145         $(NO_TRACE_MAKE) -C target/linux/$(BOARD)/image install TARGET_BUILD=1 IB=1
146         
147 clean:
148         rm -rf tmp $(TARGET_DIR) $(BIN_DIR)
149
150
151 info:
152         (unset PROFILE FILES PACKAGES MAKEFLAGS; $(MAKE) -s _call_info)
153
154 image:
155         (unset PROFILE FILES PACKAGES MAKEFLAGS; \
156         $(MAKE) _call_image \
157                 $(if $(PROFILE),USER_PROFILE="$(PROFILE)") \
158                 $(if $(FILES),USER_FILES="$(FILES)") \
159                 $(if $(PACKAGES),USER_PACKAGES="$(PACKAGES)"))
160
161 .SILENT: help info image
162