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