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