move FORCE to toplevel rules.mk
[oweals/openwrt.git] / openwrt / package / rules.mk
1 ifneq ($(DUMP),)
2   all: dumpinfo
3 else
4   all: compile
5 endif
6
7 define Build/DefaultTargets
8   ifeq ($(shell $(SCRIPT_DIR)/timestamp.pl -p $(PKG_BUILD_DIR) .),.)
9     $(PKG_BUILD_DIR)/.prepared: package-clean
10   endif
11
12   ifneq ($(shell $(SCRIPT_DIR)/timestamp.pl -p -x ipkg $(IPKG_$(1)) $(PKG_BUILD_DIR)),$(IPKG_$(1)))
13     $(PKG_BUILD_DIR)/.built: package-rebuild
14   endif
15
16   $(PKG_BUILD_DIR)/.prepared: $(DL_DIR)/$(PKG_SOURCE)
17         @-rm -rf $(PKG_BUILD_DIR)
18         @mkdir -p $(PKG_BUILD_DIR)
19         $(call Build/Prepare)
20         touch $$@
21
22   $(PKG_BUILD_DIR)/.configured: $(PKG_BUILD_DIR)/.prepared
23         $(call Build/Configure)
24         touch $$@
25
26   $(PKG_BUILD_DIR)/.built: $(PKG_BUILD_DIR)/.configured
27         $(call Build/Compile)
28         touch $$@
29     
30   package-clean: FORCE
31         $(call Build/Clean)
32
33   package-rebuild: FORCE
34         @-rm $(PKG_BUILD_DIR)/.built
35
36   define Build/DefaultTargets
37   endef
38 endef
39
40 define Package/Default
41   CONFIGFILE:=
42   SECTION:=opt
43   CATEGORY:=Extra packages
44   DEPENDS:=
45   MAINTAINER:=OpenWrt Developers Team <openwrt-devel@openwrt.org>
46   SOURCE:=$(patsubst $(TOPDIR)/%,%,${shell pwd})
47   VERSION:=$(PKG_VERSION)-$(PKG_RELEASE)
48   PKGARCH:=$(ARCH)
49   PRIORITY:=optional
50   DEFAULT:=
51   MENU:=
52   TITLE:=
53   DESCRIPTION:=
54 endef
55
56 define BuildPackage
57   $(eval $(call Package/Default))
58   $(eval $(call Package/$(1)))
59
60   $(foreach FIELD, TITLE CATEGORY PRIORITY VERSION,
61     ifeq ($($(FIELD)),)
62       $$(error Package/$(1) is missing the $(FIELD) field)
63     endif
64   )
65
66   ifeq ($(PKGARCH),)
67     PKGARCH:=$(ARCH)
68   endif
69
70   ifeq ($(DESCRIPTION),)
71     $(eval DESCRIPTION:=$(TITLE))
72   endif
73
74   IPKG_$(1):=$(PACKAGE_DIR)/$(1)_$(VERSION)_$(PKGARCH).ipk
75   IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg/$(1)
76   INFO_$(1):=$(IPKG_STATE_DIR)/info/$(1).list
77
78   ifeq ($(CONFIG_PACKAGE_$(1)),y)
79     install-targets: $$(INFO_$(1))
80   endif
81
82   ifneq ($(CONFIG_PACKAGE_$(1))$(DEVELOPER),)
83     compile-targets: $$(IPKG_$(1))
84   endif
85
86   IDEPEND_$(1):=$$(strip $$(DEPENDS))
87
88   DUMPINFO += \
89         echo "Package: $(1)"; 
90
91   ifneq ($(MENU),)
92     DUMPINFO += \
93         echo "Menu: $(MENU)";
94   endif
95
96   ifneq ($(DEFAULT),)
97     DUMPINFO += \
98         echo "Default: $(DEFAULT)";
99   endif
100
101   DUMPINFO += \
102         echo "Version: $(VERSION)"; \
103         echo "Depends: $$(IDEPEND_$(1))"; \
104         echo "Category: $(CATEGORY)"; \
105         echo "Title: $(TITLE)"; \
106         echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n,g';
107
108   ifneq ($(URL),)
109     DUMPINFO += \
110         echo; \
111         echo "$(URL)";
112   endif
113
114   DUMPINFO += \
115         echo "@@";
116
117   $$(IDIR_$(1))/CONTROL/control: $(PKG_BUILD_DIR)/.prepared
118         mkdir -p $$(IDIR_$(1))/CONTROL
119         echo "Package: $(1)" > $$(IDIR_$(1))/CONTROL/control
120         echo "Version: $(VERSION)" >> $$(IDIR_$(1))/CONTROL/control
121         echo "Depends: $$(IDEPEND_$(1))" >> $$(IDIR_$(1))/CONTROL/control
122         echo "Source: $(SOURCE)" >> $$(IDIR_$(1))/CONTROL/control
123         echo "Section: $(SECTION)" >> $$(IDIR_$(1))/CONTROL/control
124         echo "Priority: $(PRIORITY)" >> $$(IDIR_$(1))/CONTROL/control
125         echo "Maintainer: $(MAINTAINER)" >> $$(IDIR_$(1))/CONTROL/control
126         echo "Architecture: $(PKGARCH)" >> $$(IDIR_$(1))/CONTROL/control
127         echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n ,g' >> $$(IDIR_$(1))/CONTROL/control
128         chmod 644 $$(IDIR_$(1))/CONTROL/control
129         for file in conffiles preinst postinst prerm postrm; do \
130                 [ -f ./ipkg/$(1).$$$$file ] && cp ./ipkg/$(1).$$$$file $$(IDIR_$(1))/CONTROL/$$$$file || true; \
131         done
132
133   $$(IPKG_$(1)): $$(IDIR_$(1))/CONTROL/control $(PKG_BUILD_DIR)/.built
134         $(call Package/$(1)/install,$$(IDIR_$(1)))
135         mkdir -p $(PACKAGE_DIR)
136         $(RSTRIP) $$(IDIR_$(1))
137         $(IPKG_BUILD) $$(IDIR_$(1)) $(PACKAGE_DIR)
138
139   $$(INFO_$(1)): $$(IPKG_$(1))
140         $(IPKG) install $$(IPKG_$(1))
141
142   $(1)-clean:
143         rm -f $(PACKAGE_DIR)/$(1)_*
144
145   clean: $(1)-clean
146
147   $$(eval $$(call Build/DefaultTargets,$(1)))
148
149 endef
150
151 ifneq ($(strip $(PKG_SOURCE)),)
152   $(DL_DIR)/$(PKG_SOURCE):
153         $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(PKG_SOURCE)" "$(PKG_MD5SUM)" $(PKG_SOURCE_URL)
154 endif
155
156 ifneq ($(strip $(PKG_CAT)),)
157   define Build/Prepare/Default
158         @if [ "$(PKG_CAT)" = "unzip" ]; then \
159                 unzip -d $(PKG_BUILD_DIR) $(DL_DIR)/$(PKG_SOURCE) ; \
160         else \
161                 $(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | tar -C $(PKG_BUILD_DIR)/.. $(TAR_OPTIONS) - ; \
162         fi                                                
163         @if [ -d ./patches ]; then \
164                 $(PATCH) $(PKG_BUILD_DIR) ./patches ; \
165         fi
166   endef
167 endif
168
169 define Build/Prepare
170   $(call Build/Prepare/Default)
171 endef
172
173 define Build/Configure/Default
174         @(cd $(PKG_BUILD_DIR); \
175         [ -x configure ] && \
176                 $(TARGET_CONFIGURE_OPTS) \
177                 CFLAGS="$(TARGET_CFLAGS)" \
178                 ./configure \
179                 --target=$(GNU_TARGET_NAME) \
180                 --host=$(GNU_TARGET_NAME) \
181                 --build=$(GNU_HOST_NAME) \
182                 --prefix=/usr \
183                 --exec-prefix=/usr \
184                 --bindir=/usr/bin \
185                 --sbindir=/usr/sbin \
186                 --libexecdir=/usr/lib \
187                 --sysconfdir=/etc \
188                 --datadir=/usr/share \
189                 --localstatedir=/var \
190                 --mandir=/usr/man \
191                 --infodir=/usr/info \
192                 $(DISABLE_NLS) \
193                 $(1); \
194         )
195 endef
196
197 define Build/Configure
198   $(call Build/Configure/Default,)
199 endef
200
201 define Build/Compile/Default
202         $(MAKE) -C $(PKG_BUILD_DIR) \
203                 CC=$(TARGET_CC) \
204                 CROSS="$(TARGET_CROSS)" \
205                 PREFIX="$$(IDIR_$(1))" \
206                 EXTRA_CFLAGS="$(TARGET_CFLAGS)" \
207                 ARCH="$(ARCH)" \
208                 DESTDIR="$$(IDIR_$(1))"
209 endef
210
211 define Build/Compile
212   $(call Build/Compile/Default)
213 endef
214
215 define Build/Clean
216         $(MAKE) clean
217 endef
218
219 ifneq ($(DUMP),)
220   dumpinfo:
221         $(DUMPINFO)
222 else
223                 
224   $(PACKAGE_DIR):
225         mkdir -p $@
226
227   source: $(DL_DIR)/$(PKG_SOURCE)
228   prepare: $(PKG_BUILD_DIR)/.prepared
229   configure: $(PKG_BUILD_DIR)/.configured
230
231   compile-targets:
232   compile: compile-targets
233
234   install-targets:
235   install: install-targets
236
237   clean-targets:
238   clean: FORCE
239         @$(MAKE) clean-targets
240         rm -rf $(PKG_BUILD_DIR)
241 endif