source: trunk/include/package-ipkg.mk

Last change on this file was 45568, checked in by nbd, 13 months ago

package-ipkg.mk: fix typo (patch from #19540)

Signed-off-by: Felix Fietkau <nbd@…>

File size: 7.8 KB
Line 
1#
2# Copyright (C) 2006-2014 OpenWrt.org
3#
4# This is free software, licensed under the GNU General Public License v2.
5# See /LICENSE for more information.
6#
7
8include $(INCLUDE_DIR)/feeds.mk
9
10# invoke ipkg-build with some default options
11IPKG_BUILD:= \
12  $(SCRIPT_DIR)/ipkg-build -c -o 0 -g 0
13
14IPKG_STATE_DIR:=$(TARGET_DIR)/usr/lib/opkg
15
16# 1: package name
17# 2: variable name
18# 3: variable suffix
19# 4: file is a script
20define BuildIPKGVariable
21ifdef Package/$(1)/$(2)
22  $$(IPKG_$(1)) : VAR_$(2)$(3)=$$(Package/$(1)/$(2))
23  $(call shexport,Package/$(1)/$(2))
24  $(1)_COMMANDS += echo "$$$$$$$$$(call shvar,Package/$(1)/$(2))" > $(2)$(3); $(if $(4),chmod 0755 $(2)$(3);)
25endif
26endef
27
28PARENL :=(
29PARENR :=)
30
31dep_split=$(subst :,$(space),$(1))
32dep_rem=$(subst !,,$(subst $(strip $(PARENL)),,$(subst $(strip $(PARENR)),,$(word 1,$(call dep_split,$(1))))))
33dep_confvar=$(strip $(foreach cond,$(subst ||, ,$(call dep_rem,$(1))),$(CONFIG_$(cond))))
34dep_pos=$(if $(call dep_confvar,$(1)),$(call dep_val,$(1)))
35dep_neg=$(if $(call dep_confvar,$(1)),,$(call dep_val,$(1)))
36dep_if=$(if $(findstring !,$(1)),$(call dep_neg,$(1)),$(call dep_pos,$(1)))
37dep_val=$(word 2,$(call dep_split,$(1)))
38strip_deps=$(strip $(subst +,,$(filter-out @%,$(1))))
39filter_deps=$(foreach dep,$(call strip_deps,$(1)),$(if $(findstring :,$(dep)),$(call dep_if,$(dep)),$(dep)))
40
41define AddDependency
42  $$(if $(1),$$(if $(2),$$(foreach pkg,$(1),$$(IPKG_$$(pkg))): $$(foreach pkg,$(2),$$(IPKG_$$(pkg)))))
43endef
44
45define FixupReverseDependencies
46  DEPS := $$(filter %:$(1),$$(IDEPEND))
47  DEPS := $$(patsubst %:$(1),%,$$(DEPS))
48  DEPS := $$(filter $$(DEPS),$$(IPKGS))
49  $(call AddDependency,$$(DEPS),$(1))
50endef
51
52define FixupDependencies
53  DEPS := $$(filter $(1):%,$$(IDEPEND))
54  DEPS := $$(patsubst $(1):%,%,$$(DEPS))
55  DEPS := $$(filter $$(DEPS),$$(IPKGS))
56  $(call AddDependency,$(1),$$(DEPS))
57endef
58
59ifneq ($(PKG_NAME),toolchain)
60  define CheckDependencies
61        @( \
62                rm -f $(PKG_INFO_DIR)/$(1).missing; \
63                ( \
64                        export \
65                                READELF=$(TARGET_CROSS)readelf \
66                                OBJCOPY=$(TARGET_CROSS)objcopy \
67                                XARGS="$(XARGS)"; \
68                        $(SCRIPT_DIR)/gen-dependencies.sh "$$(IDIR_$(1))"; \
69                ) | while read FILE; do \
70                        grep -qxF "$$$$FILE" $(PKG_INFO_DIR)/$(1).provides || \
71                                echo "$$$$FILE" >> $(PKG_INFO_DIR)/$(1).missing; \
72                done; \
73                if [ -f "$(PKG_INFO_DIR)/$(1).missing" ]; then \
74                        echo "Package $(1) is missing dependencies for the following libraries:" >&2; \
75                        cat "$(PKG_INFO_DIR)/$(1).missing" >&2; \
76                        false; \
77                fi; \
78        )
79  endef
80endif
81
82_addsep=$(word 1,$(1))$(foreach w,$(wordlist 2,$(words $(1)),$(1)),$(strip $(2) $(w)))
83_cleansep=$(subst $(space)$(2)$(space),$(2)$(space),$(1))
84mergelist=$(call _cleansep,$(call _addsep,$(1),$(comma)),$(comma))
85addfield=$(if $(strip $(2)),$(1): $(2))
86_define=define
87_endef=endef
88
89ifeq ($(DUMP),)
90  define BuildTarget/ipkg
91    PDIR_$(1):=$(call FeedPackageDir,$(1))
92    IPKG_$(1):=$$(PDIR_$(1))/$(1)_$(VERSION)_$(PKGARCH).ipk
93    IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg-$(PKGARCH)/$(1)
94    KEEP_$(1):=$(strip $(call Package/$(1)/conffiles))
95
96    ifeq ($(BUILD_VARIANT),$$(if $$(VARIANT),$$(VARIANT),$(BUILD_VARIANT)))
97    ifdef Package/$(1)/install
98      ifneq ($(CONFIG_PACKAGE_$(1))$(DEVELOPER),)
99        IPKGS += $(1)
100        compile: $$(IPKG_$(1)) $(PKG_INFO_DIR)/$(1).provides $(STAGING_DIR_ROOT)/stamp/.$(1)_installed
101        ifneq ($(ABI_VERSION),)
102        compile: $(PKG_INFO_DIR)/$(1).version
103        endif
104
105        ifeq ($(CONFIG_PACKAGE_$(1)),y)
106          .PHONY: $(PKG_INSTALL_STAMP).$(1)
107          compile: $(PKG_INSTALL_STAMP).$(1)
108          $(PKG_INSTALL_STAMP).$(1):
109                        if [ -f $(PKG_INSTALL_STAMP).clean ]; then \
110                                rm -f \
111                                        $(PKG_INSTALL_STAMP) \
112                                        $(PKG_INSTALL_STAMP).clean; \
113                        fi; \
114                        echo "$(1)" >> $(PKG_INSTALL_STAMP)
115        endif
116      else
117        $(if $(CONFIG_PACKAGE_$(1)),$$(info WARNING: skipping $(1) -- package not selected))
118      endif
119    endif
120    endif
121
122    DEPENDS:=$(call PKG_FIXUP_DEPENDS,$(1),$(DEPENDS))
123    IDEPEND_$(1):=$$(call filter_deps,$$(DEPENDS))
124    IDEPEND += $$(patsubst %,$(1):%,$$(IDEPEND_$(1)))
125    $(FixupDependencies)
126    $(FixupReverseDependencies)
127
128    $(eval $(call BuildIPKGVariable,$(1),conffiles))
129    $(eval $(call BuildIPKGVariable,$(1),preinst,,1))
130    $(eval $(call BuildIPKGVariable,$(1),postinst,-pkg,1))
131    $(eval $(call BuildIPKGVariable,$(1),prerm,-pkg,1))
132    $(eval $(call BuildIPKGVariable,$(1),postrm,,1))
133
134    $(STAGING_DIR_ROOT)/stamp/.$(1)_installed: $(STAMP_BUILT)
135        rm -rf $(STAGING_DIR_ROOT)/tmp-$(1)
136        mkdir -p $(STAGING_DIR_ROOT)/stamp $(STAGING_DIR_ROOT)/tmp-$(1)
137        $(call Package/$(1)/install,$(STAGING_DIR_ROOT)/tmp-$(1))
138        $(call Package/$(1)/install_lib,$(STAGING_DIR_ROOT)/tmp-$(1))
139        $(call locked,$(CP) $(STAGING_DIR_ROOT)/tmp-$(1)/. $(STAGING_DIR_ROOT)/,root-copy)
140        rm -rf $(STAGING_DIR_ROOT)/tmp-$(1)
141        touch $$@
142
143    $(PKG_INFO_DIR)/$(1).version: $$(IPKG_$(1))
144        echo '$(ABI_VERSION)' | cmp -s - $$@ || \
145                echo '$(ABI_VERSION)' > $$@
146
147    Package/$(1)/DEPENDS := $$(call mergelist,$$(filter-out @%,$$(IDEPEND_$(1))))
148    ifneq ($$(EXTRA_DEPENDS),)
149      Package/$(1)/DEPENDS := $$(EXTRA_DEPENDS)$$(if $$(Package/$(1)/DEPENDS),$$(comma) $$(Package/$(1)/DEPENDS))
150    endif
151
152$(_define) Package/$(1)/CONTROL
153Package: $(1)
154Version: $(VERSION)
155$$(call addfield,Depends,$$(Package/$(1)/DEPENDS)
156)$$(call addfield,Conflicts,$$(call mergelist,$(CONFLICTS))
157)$$(call addfield,Provides,$(PROVIDES)
158)$$(call addfield,Source,$(SOURCE)
159)$$(call addfield,License,$$(PKG_LICENSE)
160)$$(call addfield,LicenseFiles,$$(PKG_LICENSE_FILES)
161)$$(call addfield,Section,$(SECTION)
162)$$(call addfield,Require-User,$(USERID)
163)$(if $(filter hold,$(PKG_FLAGS)),Status: unknown hold not-installed
164)$(if $(filter essential,$(PKG_FLAGS)),Essential: yes
165)$(if $(MAINTAINER),Maintainer: $(MAINTAINER)
166)Architecture: $(PKGARCH)
167Installed-Size: 0
168$(_endef)
169
170    $(PKG_INFO_DIR)/$(1).provides: $$(IPKG_$(1))
171    $$(IPKG_$(1)) : export CONTROL=$$(Package/$(1)/CONTROL)
172    $$(IPKG_$(1)) : export DESCRIPTION=$$(Package/$(1)/description)
173    $$(IPKG_$(1)): $(STAMP_BUILT) $(INCLUDE_DIR)/package-ipkg.mk
174        @rm -rf $$(PDIR_$(1))/$(1)_* $$(IDIR_$(1))
175        mkdir -p $(PACKAGE_DIR) $$(IDIR_$(1))/CONTROL $(PKG_INFO_DIR)
176        $(call Package/$(1)/install,$$(IDIR_$(1)))
177        -find $$(IDIR_$(1)) -name 'CVS' -o -name '.svn' -o -name '.#*' -o -name '*~'| $(XARGS) rm -rf
178        @( \
179                find $$(IDIR_$(1)) -name lib\*.so\* -or -name \*.ko | awk -F/ '{ print $$$$NF }'; \
180                for file in $$(patsubst %,$(PKG_INFO_DIR)/%.provides,$$(IDEPEND_$(1))); do \
181                        if [ -f "$$$$file" ]; then \
182                                cat $$$$file; \
183                        fi; \
184                done; $(Package/$(1)/extra_provides) \
185        ) | sort -u > $(PKG_INFO_DIR)/$(1).provides
186        $(if $(PROVIDES),@for pkg in $(PROVIDES); do cp $(PKG_INFO_DIR)/$(1).provides $(PKG_INFO_DIR)/$$$$pkg.provides; done)
187        $(CheckDependencies)
188
189        $(RSTRIP) $$(IDIR_$(1))
190        (cd $$(IDIR_$(1))/CONTROL; \
191                ( \
192                        echo "$$$$CONTROL"; \
193                        printf "Description: "; echo "$$$$DESCRIPTION" | sed -e 's,^[[:space:]]*, ,g'; \
194                ) > control; \
195                chmod 644 control; \
196                ( \
197                        echo "#!/bin/sh"; \
198                        echo "[ \"\$$$${IPKG_NO_SCRIPT}\" = \"1\" ] && exit 0"; \
199                        echo ". \$$$${IPKG_INSTROOT}/lib/functions.sh"; \
200                        echo "default_postinst \$$$$0 \$$$$@"; \
201                ) > postinst; \
202                ( \
203                        echo "#!/bin/sh"; \
204                        echo ". \$$$${IPKG_INSTROOT}/lib/functions.sh"; \
205                        echo "default_prerm \$$$$0 \$$$$@"; \
206                ) > prerm; \
207                chmod 0755 postinst prerm; \
208                $($(1)_COMMANDS) \
209        )
210
211    ifneq ($$(KEEP_$(1)),)
212                @( \
213                        keepfiles=""; \
214                        for x in $$(KEEP_$(1)); do \
215                                [ -f "$$(IDIR_$(1))/$$$$x" ] || keepfiles="$$$${keepfiles:+$$$$keepfiles }$$$$x"; \
216                        done; \
217                        [ -z "$$$$keepfiles" ] || { \
218                                mkdir -p $$(IDIR_$(1))/lib/upgrade/keep.d; \
219                                for x in $$$$keepfiles; do echo $$$$x >> $$(IDIR_$(1))/lib/upgrade/keep.d/$(1); done; \
220                        }; \
221                )
222    endif
223
224        $(INSTALL_DIR) $$(PDIR_$(1))
225        $(IPKG_BUILD) $$(IDIR_$(1)) $$(PDIR_$(1))
226        @[ -f $$(IPKG_$(1)) ]
227
228    $(1)-clean:
229        rm -f $$(PDIR_$(1))/$(1)_*
230
231    clean: $(1)-clean
232
233  endef
234endif
Note: See TracBrowser for help on using the repository browser.