package.mk 9.1 KB

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