openpkg/rpmmacros

Mon, 28 Jan 2013 17:37:18 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Mon, 28 Jan 2013 17:37:18 +0100
changeset 758
a2c6460cfb16
parent 427
71503088f51b
permissions
-rw-r--r--

Correct socket error reporting improvement with IPv6 portable code,
after helpful recommendation by Saúl Ibarra Corretgé on OSips devlist.

michael@13 1 ##
michael@13 2 ## rpmmacros -- OpenPKG RPM Macros
michael@428 3 ## Copyright (c) 2000-2012 OpenPKG GmbH <http://openpkg.com/>
michael@13 4 ##
michael@428 5 ## This software is property of the OpenPKG GmbH, DE MUC HRB 160208.
michael@428 6 ## All rights reserved. Licenses which grant limited permission to use,
michael@428 7 ## copy, modify and distribute this software are available from the
michael@428 8 ## OpenPKG GmbH.
michael@13 9 ##
michael@428 10 ## THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
michael@13 11 ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
michael@13 12 ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
michael@13 13 ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
michael@13 14 ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
michael@13 15 ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
michael@13 16 ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
michael@13 17 ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
michael@13 18 ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
michael@13 19 ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
michael@13 20 ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
michael@13 21 ## SUCH DAMAGE.
michael@13 22 ##
michael@428 23
michael@428 24 ##
michael@13 25 ## The purpose of this macro set is to override the default
michael@13 26 ## macros in the OpenPKG RPM installation for the @l_prefix@ hierarchy.
michael@13 27 ##
michael@13 28
michael@428 29 # utility macro for "delayed one-time expansion" of macro bodies
michael@428 30 # (works by redefining a macro in-place to its expanded body on its first usage)
michael@428 31 %l_once() %{expand:%%global %{*}}%{expand:%%{%{1}}}
michael@428 32
michael@13 33 # the OpenPKG release identification (for the current package or as a fallback for the bootstrap package)
michael@428 34 %l_openpkg_release(F:) %(%{l_prefix}/libexec/openpkg/release \\\
michael@428 35 --release="%{?release}%{!?release:%(%{l_rpm} -q --qf '%{release}' openpkg)}" \\\
michael@428 36 %{?-F:-F "%{-F*}"}%{!?-F:-F "OpenPKG-%%t"})
michael@13 37
michael@13 38 # the OpenPKG OIDs (root is officially registered at IANA)
michael@13 39 %l_openpkg_oid 1.3.6.1.4.1.18749
michael@13 40 %l_openpkg_oid_bootstrap %{l_openpkg_oid}.4.1
michael@13 41 %l_openpkg_oid_instance %{l_openpkg_oid_bootstrap}.1
michael@13 42 %l_openpkg_oid_platform %{l_openpkg_oid_bootstrap}.2
michael@13 43 %l_openpkg_oid_tagfmtopt %{l_openpkg_oid_bootstrap}.3
michael@13 44
michael@13 45 # the OpenPKG package tagging
michael@13 46 %l_tag_fmt @TAG@
michael@428 47 %l_tag_fmt_compat %(prefix="%{l_prefix_static}"; \
michael@428 48 if [ ".`expr $prefix : '/[^/][^/]*$'`" != .0 ]; then \
michael@428 49 loc=`echo $prefix | cut -c2-4`; \
michael@428 50 else \
michael@428 51 loc=`echo $prefix | sed -e 's;/\\(.\\)[^/]*;\\1;g' | cut -c1-3`; \
michael@428 52 fi; \
michael@428 53 echo $loc)
michael@428 54 %l_tag_fmt_loc %(echo "%{l_prefix_static}" | \\\
michael@428 55 sed -e 's;^/\\([^/]\\)[^/]*/\\([^/]\\)[^/]*/\\([^/]\\).*;\\1\\2\\3;' \\\
michael@428 56 -e 's;^/\\([^/]\\)[^/]*/\\([^/][^/]\\).*;\\1\\2;' \\\
michael@428 57 -e 's;^/\\([^/][^/]\\)[^/]*/\\([^/]\\).*;\\1\\2;' \\\
michael@428 58 -e 's;^/\\([^/]\\)[^/]*/\\([^/]\\).*;\\1\\2;' \\\
michael@428 59 -e 's;^/\\([^/][^/][^/]\\).*;\\1;' \\\
michael@428 60 -e 's;^/\\([^/][^/]\\).*;\\1;' \\\
michael@428 61 -e 's;^/\\([^/]\\).*;\\1;' \\\
michael@428 62 )
michael@428 63 %l_tag_fmt_opt %(uuid_ns="`%{l_uuid} -v3 ns:OID %{l_openpkg_oid_tagfmtopt}`"; \
michael@428 64 %{l_uuid} -v3 $uuid_ns '%{?_options}')
michael@13 65 %l_tag_fmt_uuid %(%{l_uuid} -v1)
michael@13 66 %l_tag_fmt_time %(date '+%%Y%%m%%d%%H%%M%%S')
michael@13 67 %l_tag_fmt_user %(%{l_shtool} echo -e '%%u')
michael@13 68 %l_tag_fmt_host %(%{l_shtool} echo -e '%%h%%d')
michael@428 69 %l_tag_gen %{expand:%(echo '%{l_tag_fmt}' | \\\
michael@428 70 sed -e 's/<\\([a-zA-Z][_a-zA-Z0-9]*\\)>/%%{l_tag_fmt_\\1}/g')}
michael@428 71 %l_tag %{l_once l_tag %(echo "%{l_tag_gen}" | sed -e 's;-;;g')}
michael@13 72
michael@13 73 # the OpenPKG instance location (backward compatibility only)
michael@13 74 %l_location %{l_tag}
michael@13 75
michael@13 76 # standard RPM host platform identification
michael@13 77 # (defaults via "shtool platform" and uname(3); used internally)
michael@13 78 #%_host_cpu ...USE INTERNAL DEFAULT...
michael@13 79 #%_host_vendor ...USE INTERNAL DEFAULT...
michael@13 80 #%_host_os ...USE INTERNAL DEFAULT...
michael@13 81 %_host_alias %{nil}
michael@13 82 %_host %{_host_cpu}-%{_host_os}
michael@13 83
michael@13 84 # standard RPM build platform identification
michael@13 85 # (defaults via %{_host*} macros; not used internally AFAIK)
michael@13 86 %_build_cpu %{_host_cpu}
michael@13 87 %_build_vendor %{_host_vendor}
michael@13 88 %_build_os %{_host_os}
michael@13 89 %_build_alias %{_host_alias}
michael@13 90 %_build %{_host}
michael@13 91
michael@13 92 # standard RPM target platform identification
michael@13 93 # (defaults via %{_host*} macros; used internally for %ifarch/%ifnarch)
michael@13 94 %_target_cpu %{_host_cpu}
michael@13 95 %_target_vendor %{_host_vendor}
michael@13 96 %_target_os %{_host_os}
michael@13 97 %_target_alias %{_host_alias}
michael@13 98 %_target %{_host}
michael@13 99
michael@13 100 # legacy RPM platform macros
michael@13 101 # (defaults via config.guess/config.sub under RPM build-time)
michael@13 102 %_arch %{_host_cpu}
michael@13 103 %_vendor %{_host_vendor}
michael@13 104 %_os %{_host_os}
michael@13 105
michael@13 106 # legacy RPM platform macros
michael@13 107 # (defaults via various other macros; partly used internally)
michael@13 108 %_build_arch %{_arch}
michael@13 109 %_target_platform %{_target_cpu}-%{_target_vendor}-%{_target_os}
michael@13 110 %_gnu %{nil}
michael@13 111
michael@13 112 # official OpenPKG host platform identification
michael@13 113 %l_host_arch %{_host_cpu}
michael@13 114 %l_host_vendor %{_host_vendor}
michael@13 115 %l_host_os %{_host_os}
michael@13 116 %l_host %{_host_cpu}-%{_host_os}
michael@13 117
michael@428 118 # host name or FQDN identification
michael@428 119 %l_hostname(f) %(%{l_shtool} echo -n -e '%%h%{?-f:%%d}')
michael@428 120
michael@13 121 # new OpenPKG platform identification
michael@428 122 %l_platform(cptF:) %(if [ ".%{?-F}" != . ]; then \
michael@428 123 fmt="%{-F*}"; \
michael@428 124 else \
michael@428 125 T="%{?-c:c}%{?-p:p}%{?-t:t}"; \
michael@428 126 [ ".$T" = . ] && T="p"; \
michael@428 127 fmt="%%<a$T>-%%<s$T>"; \
michael@428 128 fi; \
michael@428 129 %{l_shtool} platform -n -L -S "" -C "+" -F "$fmt")
michael@13 130
michael@13 131 # old OpenPKG platform identification
michael@13 132 %l_target %{l_platform -t}
michael@13 133
michael@428 134 # UID/GID lookup
michael@428 135 %l_xuid_lookup() %(( getent passwd '%1'; \
michael@428 136 grep '^%1:' /etc/passwd; \
michael@428 137 ypmatch '%1' passwd; \
michael@428 138 nismatch '%1' passwd; \
michael@428 139 nidump passwd . | grep '^%1:' \
michael@428 140 ) 2>/dev/null | \
michael@428 141 sed -e 'q' | \\\
michael@428 142 awk -F: '{ print $3; }' \
michael@428 143 )
michael@428 144 %l_xgid_lookup() %(( getent group '%2'; \
michael@428 145 grep '^%2:' /etc/group; \
michael@428 146 ypmatch '%2' group; \
michael@428 147 nismatch '%2' group; \
michael@428 148 nidump group . | grep '^%1:' \
michael@428 149 ) 2>/dev/null | \
michael@428 150 sed -e 'q' | \\\
michael@428 151 awk -F: '{ print $3; }' \
michael@428 152 )
michael@428 153
michael@13 154 # the *S*uper-user user/group name/id pair
michael@13 155 %l_susr @SUSR@
michael@13 156 %l_sgrp @SGRP@
michael@428 157 %l_suid %{expand:%%{l_xuid_lookup %{l_susr} %{l_sgrp}}}
michael@428 158 %l_sgid %{expand:%%{l_xgid_lookup %{l_susr} %{l_sgrp}}}
michael@13 159
michael@13 160 # the *M*anagement user/group name/id pair
michael@13 161 %l_musr @MUSR@
michael@13 162 %l_mgrp @MGRP@
michael@428 163 %l_muid %{expand:%%{l_xuid_lookup %{l_musr} %{l_mgrp}}}
michael@428 164 %l_mgid %{expand:%%{l_xgid_lookup %{l_musr} %{l_mgrp}}}
michael@13 165
michael@13 166 # the *R*restricted user/group name/id pair
michael@13 167 %l_rusr @RUSR@
michael@13 168 %l_rgrp @RGRP@
michael@428 169 %l_ruid %{expand:%%{l_xuid_lookup %{l_rusr} %{l_rgrp}}}
michael@428 170 %l_rgid %{expand:%%{l_xgid_lookup %{l_rusr} %{l_rgrp}}}
michael@13 171
michael@13 172 # the *N*on-privileged user/group name/id pair
michael@13 173 %l_nusr @NUSR@
michael@13 174 %l_ngrp @NGRP@
michael@428 175 %l_nuid %{expand:%%{l_xuid_lookup %{l_nusr} %{l_ngrp}}}
michael@428 176 %l_ngid %{expand:%%{l_xgid_lookup %{l_nusr} %{l_ngrp}}}
michael@13 177
michael@13 178 # backward compatibility (openpkg < 20020204)
michael@13 179 %l_fsusr %{l_musr}
michael@13 180 %l_fsgrp %{l_mgrp}
michael@13 181 %l_npuid %{l_nuid}
michael@13 182 %l_npgid %{l_ngid}
michael@13 183
michael@428 184 # whether we are intended to operate in an environment where
michael@428 185 # only a single unprivileged user account can be used
michael@428 186 %l_unprivileged @l_unprivileged@
michael@428 187
michael@13 188 # define the installation hierarchy (used parts)
michael@13 189 %l_prefix @l_prefix@
michael@13 190 %l_prefix_static @l_prefix_static@
michael@13 191
michael@13 192 # define the installation hierarchy (unused parts)
michael@13 193 %l_exec_prefix %{l_prefix}
michael@13 194 %l_bindir %{l_prefix}/bin
michael@13 195 %l_sbindir %{l_prefix}/sbin
michael@13 196 %l_libexecdir %{l_prefix}/libexec
michael@13 197 %l_datadir %{l_prefix}/share
michael@13 198 %l_sysconfdir %{l_prefix}/etc
michael@13 199 %l_sharedstatedir %{l_prefix}/com
michael@13 200 %l_localstatedir %{l_prefix}/var
michael@13 201 %l_libdir %{l_prefix}/lib
michael@13 202 %l_includedir %{l_prefix}/include
michael@13 203 %l_infodir %{l_prefix}/info
michael@13 204 %l_mandir %{l_prefix}/man
michael@13 205 %l_docdir %{l_prefix}/doc
michael@13 206
michael@13 207 # provide killer macro "%{l_value -s|-b|-c (l_xxx ...|-a|-A)}" which
michael@13 208 # expands to the values of previous l_xxx variables in this file. With
michael@13 209 # option "-s" it expands into a chain of "-e 's;<name>;<value>;g'"
michael@13 210 # constructs for used with Stream Editor sed(1), with option "-b" it
michael@13 211 # expands into a chain of "<name>='<value>';" constructs for use with
michael@13 212 # Bourne-Shell sh(1), with option "-c" it expands into a chain of "set
michael@13 213 # <name> = '<value>';" constructs for use with C-Shell csh(1). But
michael@13 214 # be careful, <value> currently (for expansion speed reasons) is not
michael@13 215 # escaped, so make sure the values of the above macros do not contain
michael@13 216 # ";" for "-s" and ";" for "-b" and "-c". You can either specify one
michael@13 217 # or more names of variables to expand or use "-a" for mostly all
michael@13 218 # variables and "-A" for really all variables.
michael@428 219 %l_value(sbcaA) %{expand:%(\
michael@428 220 l=""; \
michael@428 221 for x in \\\
michael@428 222 `if [ ".%*" != . ]; then \
michael@428 223 echo "%* "; \
michael@428 224 else \
michael@428 225 p=""; \
michael@428 226 if [ ".%{-a:yes}" = .yes ]; then \
michael@428 227 p="^%%l_(prefix|[smrn](usr|grp|uid|gid))"; \
michael@428 228 elif [ ".%{-A:yes}" = .yes ]; then \
michael@428 229 p="^%%l_"; \
michael@428 230 fi; \
michael@428 231 if [ ".$p" != . ]; then \
michael@428 232 egrep "$p" %{l_prefix}/etc/openpkg/rpmmacros |\\\
michael@428 233 sed -e '/^%%l_value/,$d' \\\
michael@428 234 -e 's;^%%\\(l_[a-z1-9_]*\\).*;\\1;'; \
michael@428 235 fi; \
michael@428 236 fi`; do \
michael@428 237 e=""; \
michael@428 238 if [ ".%{-s:yes}" = .yes ]; then \
michael@428 239 e="-e 's;@$x@;%%{$x};g'"; \
michael@428 240 elif [ ".%{-b:yes}" = .yes ]; then \
michael@428 241 e="$x='%%{$x}';"; \
michael@428 242 elif [ ".%{-c:yes}" = .yes ]; then \
michael@428 243 e="set $x = '%%{$x}';"; \
michael@428 244 else \
michael@428 245 e="%%{$x}"; \
michael@428 246 fi; \
michael@428 247 if [ ".$l" = . ]; then \
michael@428 248 l="$e"; \
michael@428 249 else \
michael@428 250 l="$l $e"; \
michael@428 251 fi; \
michael@428 252 done; \
michael@428 253 echo "$l" \
michael@428 254 )}
michael@13 255
michael@13 256 # local version of the empty macro
michael@13 257 %l_nil %{nil}
michael@13 258
michael@428 259 # local version of the tab character
michael@428 260 %l_tab %{lua: print "\t" }
michael@428 261
michael@13 262 # override the internal RPM hierarchy variables
michael@13 263 %_usr %{nil}
michael@13 264 %_var %{nil}
michael@13 265 %_usrsrc %{nil}
michael@13 266 %_topdir %{nil}
michael@13 267 %_dbpath %{l_prefix}/RPM/DB
michael@13 268 %_builddir %{l_prefix}/RPM/TMP
michael@13 269 %_tmppath %{l_prefix}/RPM/TMP
michael@13 270 %_sourcedir %{l_prefix}/RPM/SRC/%{name}
michael@13 271 %_specdir %{l_prefix}/RPM/SRC/%{name}
michael@13 272 %_rpmdir %{l_prefix}/RPM/PKG
michael@13 273 %_srcrpmdir %{l_prefix}/RPM/PKG
michael@428 274 %_repackage_dir %{l_prefix}/RPM/TR
michael@428 275 %_cache_dbpath %{l_prefix}/RPM/CACHE
michael@428 276 %_solve_dbpath %{l_prefix}/RPM/CACHE
michael@428 277 %_solve_pkgsdir %{l_prefix}/RPM/CACHE
michael@13 278 %_defaultdocdir %{l_docdir}
michael@13 279
michael@13 280 # complement the %{SOURCE<n>} and %{PATCH<n>} with %{SOURCE <file>} and %{PATCH <file>}
michael@428 281 %_SOURCE_PATCH() %{lua: \
michael@428 282 local source1 = rpm.expand("%{_specdir}/%1") \
michael@428 283 local source2 = rpm.expand("%{_sourcedir}/%1") \
michael@428 284 if posix.stat(source1) ~= nil then \
michael@428 285 print(source1) \
michael@428 286 else \
michael@428 287 print(source2) \
michael@428 288 end }
michael@428 289 %SOURCE() %{expand:%%{_SOURCE_PATCH %1}}
michael@428 290 %PATCH() %{expand:%%{_SOURCE_PATCH %1}}
michael@13 291
michael@13 292 # override RPM's absolute tool paths with relative ones
michael@13 293 # (because if you upgrade RPM it would hard-code tools in own hierarchy, too)
michael@13 294 %__awk awk
michael@13 295 %__bzip2 %{_bzip2bin}
michael@13 296 %__cat cat
michael@13 297 %__chgrp chgrp
michael@13 298 %__chmod chmod
michael@13 299 %__chown chown
michael@13 300 %__cp cp
michael@13 301 %__grep grep
michael@13 302 %__gzip %{_gzipbin}
michael@13 303 %__id id
michael@13 304 %__install install
michael@13 305 %__ln_s ln -s
michael@13 306 %__make make
michael@13 307 %__mkdir mkdir
michael@13 308 %__mkdir_p %{l_shtool} mkdir -p
michael@13 309 %__mv mv
michael@13 310 %__patch %{_patchbin}
michael@13 311 %__perl perl
michael@13 312 %__pgp %{_pgpbin}
michael@13 313 %__rm rm
michael@13 314 %__rsh rsh
michael@13 315 %__sed sed
michael@13 316 %__ssh ssh
michael@13 317 %__tar %{_tarbin}
michael@428 318 %__xz %{_xzbin}
michael@13 319
michael@13 320 # override some more RPM macros where the default value is not acceptable
michael@428 321 %_dbapi %{l_once _dbapi %(if [ -f "%{_dbpath}/VERSION" ]; then \
michael@428 322 . "%{_dbpath}/VERSION"; \
michael@428 323 fi; \
michael@428 324 echo "${DBAPI:-3}")}
michael@428 325 %__dbi_other %{?_tmppath:tmpdir=%{_tmppath}} %{?__dbi_cdb} %{?__dbi_private:private}
michael@428 326 %__file_context_path %{nil}
michael@428 327 %__check_files %{nil}
michael@428 328 %_patch_suffix -b --suffix .orig
michael@428 329 %_excludedocs 1
michael@13 330 %_dependency_whiteout %{nil}
michael@13 331 %__debug_install_post %{nil}
michael@13 332 %_unpackaged_files_terminate_build 0
michael@13 333
michael@13 334 # provide fixed paths to tools (standard)
michael@13 335 %_gzipbin %{l_prefix}/lib/openpkg/gzip
michael@13 336 %_bzip2bin %{l_prefix}/lib/openpkg/bzip2
michael@428 337 %_xzbin %{l_prefix}/lib/openpkg/xz
michael@13 338 %_patchbin %{l_prefix}/lib/openpkg/patch
michael@13 339 %_tarbin %{l_prefix}/lib/openpkg/tar
michael@428 340 %__bsdtar %{l_prefix}/lib/openpkg/bsdtar
michael@428 341 %__cpio %{l_prefix}/lib/openpkg/bsdcpio
michael@428 342 %__unzip %{__bsdtar}
michael@13 343
michael@13 344 # provide path to platform identification file
michael@13 345 %__platform %{l_prefix}/etc/openpkg/platform
michael@13 346
michael@13 347 # provide fixed paths to tools (additional)
michael@428 348 %l_rc %{l_prefix}/bin/openpkg --keep-privileges rc
michael@13 349 %l_rpm %{l_prefix}/libexec/openpkg/rpm
michael@13 350 %l_rpm2cpio %{l_prefix}/libexec/openpkg/rpm2cpio
michael@13 351 %l_rpm_config %{l_prefix}/libexec/openpkg/rpm-config
michael@13 352 %l_lsync %{l_prefix}/libexec/openpkg/lsync
michael@13 353 %l_rpmtool %{l_prefix}/lib/openpkg/rpmtool
michael@13 354 %l_shtool %{l_prefix}/lib/openpkg/shtool
michael@13 355 %l_curl %{l_prefix}/lib/openpkg/curl
michael@13 356 %l_bash %{l_prefix}/lib/openpkg/bash
michael@13 357 %l_uuid %{l_prefix}/lib/openpkg/uuid
michael@13 358
michael@13 359 # provide smart paths to tools
michael@428 360 %l_tool_locate() %{lua: \
michael@428 361 if rpm.expand("%{expand:%%{?use_%1}}") ~= "" then \
michael@428 362 print(rpm.expand("%{expand:%%{use_%1}}")) \
michael@428 363 elseif posix.stat(rpm.expand("%{l_prefix}/bin/%2")) ~= nil then \
michael@428 364 print(rpm.expand("%{l_prefix}/bin/%2")) \
michael@428 365 elseif posix.stat(rpm.expand("%{l_prefix}/lib/openpkg/%2")) ~= nil then \
michael@428 366 print(rpm.expand("%{l_prefix}/lib/openpkg/%2")) \
michael@428 367 else \
michael@428 368 print(rpm.expand("%2")) \
michael@428 369 end }
michael@428 370 %l_gzip %{l_once l_gzip %{l_tool_locate gzip gzip}}
michael@428 371 %l_bzip2 %{l_once l_bzip2 %{l_tool_locate bzip2 bzip2}}
michael@428 372 %l_xz %{l_once l_xz %{l_tool_locate xz xz}}
michael@428 373 %l_tar %{l_once l_tar %{l_tool_locate tar tar}}
michael@428 374 %l_make %{l_once l_make %{l_tool_locate make make}}
michael@428 375 %l_cc %{l_once l_cc %{l_tool_locate cc cc}}
michael@428 376 %l_ar %{l_once l_ar %{l_tool_locate ar ar}}
michael@428 377 %l_ld %{l_once l_ld %{l_tool_locate ld ld}}
michael@428 378 %l_as %{l_once l_as %{l_tool_locate as as}}
michael@428 379 %l_strip %{l_once l_strip %{l_tool_locate strip strip}}
michael@428 380 %l_cxx %{l_once l_cxx %{l_tool_locate cxx c++}}
michael@428 381 %l_patch %{l_once l_patch %{l_tool_locate patch patch}}
michael@428 382 %l_sed %{l_once l_sed %{l_tool_locate sed sed}}
michael@428 383 %l_grep %{l_once l_grep %{l_tool_locate grep grep}}
michael@428 384 %l_awk %{l_once l_awk %{l_tool_locate awk awk}}
michael@428 385 %l_autoconf %{l_once l_autoconf %{l_tool_locate autoconf autoconf}}
michael@428 386 %l_automake %{l_once l_automake %{l_tool_locate automake automake}}
michael@428 387 %l_libtool %{l_once l_libtool %{l_tool_locate libtool libtool}}
michael@428 388 %l_flex %{l_once l_flex %{l_tool_locate flex flex}}
michael@428 389 %l_bison %{l_once l_bison %{l_tool_locate bison bison}}
michael@428 390 %l_perl %{l_once l_perl %{l_tool_locate perl perl}}
michael@428 391 %l_miniperl %{l_once l_miniperl %{l_tool_locate miniperl miniperl}}
michael@428 392 %l_openssl %{l_once l_openssl %{l_tool_locate openssl openssl}}
michael@428 393 %l_xmkmf %{l_once l_xmkmf %{l_tool_locate xmkmf xmkmf}}
michael@428 394 %l_vcheck %{l_once l_vcheck %{l_tool_locate vcheck vcheck}}
michael@13 395
michael@13 396 # tool options
michael@13 397 %l_mflags(O) %(%{l_sane_env}; %{l_rpmtool} mflags %{-O:-O} "%{l_make}")
michael@13 398 %l_cflags(O) %(%{l_sane_env}; %{l_rpmtool} cflags %{-O:-O} "%{l_cc}")
michael@13 399 %l_cxxflags(O) %(%{l_sane_env}; %{l_rpmtool} cflags %{-O:-O} "%{l_cxx}")
michael@13 400 %l_cppflags(i) %(%{l_sane_env}; %{l_rpmtool} cppflags -p%{l_prefix} %{-i:-i} -- %*)
michael@13 401 %l_ldflags() %(%{l_sane_env}; %{l_rpmtool} ldflags -p%{l_prefix} -- %*)
michael@13 402
michael@13 403 # OSSP fake syslog library
michael@428 404 %l_fsl_ldflags() %(if [ ".%{with_fsl}" = ".yes" ]; then \
michael@428 405 flags=`(%{l_prefix}/bin/fsl-config --all --ldflags) 2>/dev/null`; \
michael@428 406 else \
michael@428 407 flags=''; \
michael@428 408 fi; \
michael@428 409 echo $flags)
michael@428 410 %l_fsl_libs() %(if [ ".%{with_fsl}" = ".yes" ]; then \
michael@428 411 flags=`(%{l_prefix}/bin/fsl-config --all --libs) 2>/dev/null`; \
michael@428 412 else \
michael@428 413 flags=''; \
michael@428 414 fi; \
michael@428 415 echo $flags)
michael@13 416
michael@13 417 # determine the current username
michael@428 418 %l_whoami %{l_once l_whoami %((id -un) 2>/dev/null || \\\
michael@428 419 (whoami) 2>/dev/null || \\\
michael@428 420 (who am i | cut "-d " -f1) 2>/dev/null || \\\
michael@428 421 echo $LOGNAME)}
michael@13 422
michael@13 423 # macros for dynamically generating a %files list
michael@13 424 %l_files_defattr '%%defattr(-,%{l_musr},%{l_mgrp})'
michael@13 425 %l_files_all '%{l_prefix}'
michael@13 426 %l_files_noshared '%%not %%dir {%{l_prefix},%{l_prefix}/*,%{l_prefix}/etc/rc.d,%{l_prefix}/man/*}'
michael@13 427 %l_files_std() %l_files_defattr %l_files_all %l_files_noshared
michael@13 428
michael@428 429 # default %defattr when rolling SRPMS
michael@428 430 %_srcdefattr (-,openpkg,openpkg)
michael@428 431
michael@13 432 # path to local build root
michael@428 433 %l_buildroot %{_tmppath}/%{name}-%{version}-%{release}-buildroot
michael@427 434 %buildroot %{l_buildroot}
michael@13 435
michael@13 436 # path to local temporary location
michael@13 437 %l_tmpdir() %{_tmppath}
michael@13 438 %l_tmpfile() %{l_tmpdir}/%{name}-%{version}-%{release}-tmp%{?1:-%1}
michael@13 439
michael@13 440 # executable path for %post/%pre
michael@13 441 %_install_script_path %{l_prefix}/bin:%{l_prefix}/sbin:/bin:/sbin:/usr/bin:/usr/sbin
michael@13 442
michael@13 443 # names of RPM files
michael@13 444 %l_srcrpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.src.rpm
michael@13 445 %l_binrpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}-%%{OS}-%{l_tag}.rpm
michael@13 446
michael@13 447 # override the name scheme for RPM files
michael@13 448 %_rpmfilename %{l_binrpmfilename}
michael@13 449 %_build_name_fmt %{l_binrpmfilename}
michael@13 450 %_repackage_name_fmt %{l_binrpmfilename}
michael@428 451 %_solve_name_fmt %{?_solve_pkgsdir}/%{l_binrpmfilename}
michael@428 452 %_query_all_fmt %%{NAME}-%%{VERSION}-%%{RELEASE}
michael@428 453 %___NVRA %%{NAME}-%%{VERSION}-%%{RELEASE}
michael@428 454
michael@428 455 # do not repackage automatically
michael@428 456 %_repackage_all_erasures 0
michael@13 457
michael@13 458 # override the payload compression for the CPIO parts of an RPM
michael@13 459 # (we use the equivalent of "bzip2 -9")
michael@13 460 %_source_payload w9.bzdio
michael@13 461 %_binary_payload w9.bzdio
michael@13 462
michael@13 463 # package signature type is OpenPGP via GnuPG
michael@428 464 %__gpg %{l_tool_locate gpg gpg}
michael@13 465 %_signature gpg
michael@13 466
michael@13 467 # two macro-processor add-ons (should be part of forthcoming RPM releases)
michael@13 468 %ifdef() %if %{expand:%%{?%{1}:1}%%{!?%{1}:0}}
michael@13 469 %ifndef() %if %{expand:%%{?%{1}:0}%%{!?%{1}:1}}
michael@13 470
michael@13 471 # macro for package option configuration
michael@428 472 %option() %{lua: \
michael@428 473 local package_name = rpm.expand("%{name}") \
michael@428 474 local option_name = rpm.expand("%1") \
michael@428 475 if rpm.expand("%{?" .. option_name .. ":defined}") ~= "defined" then \
michael@428 476 rpm.expand("%global " .. rpm.expand("%*")) \
michael@428 477 end \
michael@428 478 local option_value = rpm.expand("%{" .. option_name .. "}") \
michael@428 479 option_value = util.rsubst(option_value, "(?s)%", "%%%%") \
michael@428 480 option_value = util.rsubst(option_value, "(?s) ", "%%20") \
michael@428 481 option_value = util.rsubst(option_value, "(?s)\\t", "%%09") \
michael@428 482 rpm.expand("%global _options %{?_options:%{_options}:}" .. option_name .. "=" .. option_value) \
michael@428 483 print(string.format("Provides: %s::%s = %s\\n", package_name, option_name, option_value)) \
michael@428 484 }
michael@13 485
michael@13 486 # macros for NoSource/NoPatch (distribution restriction) integrity handling
michael@428 487 %NoSource() %(if [ ".%{?restriction}" != ".no" ]; then \
michael@428 488 echo "NoSource: %1"; \
michael@428 489 fi) \
michael@428 490 %{expand:%%global _restricted %{?_restricted:%{_restricted}} %%{SOURCEURL%1}}
michael@428 491 %NoPatch() %(if [ ".%{?restriction}" != ".no" ]; then \
michael@428 492 echo "NoPatch: %1"; fi) \
michael@428 493 %{expand:%%global _restricted %{?_restricted:%{_restricted}} %%{PATCHURL%1}}
michael@13 494 %integrity() %{l_check_nosource}
michael@13 495
michael@13 496 # macros for checking build environment
michael@428 497 %l_check_nosource() %(%{l_sane_env}; checkok=1; \
michael@428 498 checkinfo=`echo "Sorry, this OpenPKG package contains a DISTRIBUTION RESTRICTED source file."; \\\
michael@428 499 echo "Before you can proceed building this package, fetch missing files MANUALLY:"`; \
michael@428 500 for url in . %{?_restricted}; do \
michael@428 501 [ ".$url" = .. ] && continue; \
michael@428 502 eval `echo "$url" | \\\
michael@428 503 sed -e 's!^\\(.*\\)::/\\([^/][^/]*\\)$!;url=\\"\\1\\"; file=\\"\\2\\"!' \\\
michael@428 504 -e 's!^\\([^:;][^:]*://.*/\\)\\([^/][^/]*\\)$!;url=\\"\\1\\"; file=\\"\\2\\"!' \\\
michael@428 505 -e 's:^\\([^;].*\\)$:;url="(unknown location) "; file="\\1":' \\\
michael@428 506 -e 's:^;::'`; \
michael@428 507 if [ ! -f "%{_specdir}/$file" ] && [ ! -f "%{_sourcedir}/$file" ]; then \\\
michael@428 508 checkok=0; \
michael@428 509 checkinfo=`echo "${checkinfo}"; \\\
michael@428 510 echo ""; \\\
michael@428 511 echo "from ${url}"; \\\
michael@428 512 echo "file ${file}"; \\\
michael@428 513 echo "here %{_sourcedir}/$file"`; \
michael@428 514 fi; \
michael@428 515 done; \
michael@428 516 if [ $checkok -ne 1 ]; then \
michael@428 517 echo "set +x"; \
michael@428 518 echo "$checkinfo" | \\\
michael@428 519 %{l_rpmtool} msg -b -t error | \\\
michael@428 520 sed -e 's;^;echo ";' -e 's;$;";'; \
michael@428 521 echo "exit 1"; \
michael@428 522 fi)
michael@428 523 %l_check_class() %(%{l_sane_env}; \
michael@428 524 class=`echo "@:%{?class}:%{?distribution}" | \\\
michael@428 525 sed -e 's;^@:\\([^:][^:]*\\):.*$;\\1;' \\\
michael@428 526 -e 's;^@:.*\\[\\(.*\\)\\].*$;\\1;' \\\
michael@428 527 -e 's;^@:.*$;JUNK;'`; \
michael@428 528 %{l_rpmtool} check-class "$class")
michael@13 529 %prep %%prep\
michael@13 530 %{l_check_nosource} \
michael@13 531 %{l_check_class} \
michael@13 532 %{nil}
michael@13 533
michael@13 534 # macro-processor add-on for testing external conditions
michael@428 535 %l_test(pfd) %(if [ ".%{?-p:yes}" = .yes ]; then \
michael@428 536 %{l_rpm} -q %1 >/dev/null 2>&1; rc=$?; \
michael@428 537 elif [ ".%{?-f:yes}" = .yes ]; then \
michael@428 538 test -f %1; rc=$?; \
michael@428 539 elif [ ".%{?-d:yes}" = .yes ]; then \
michael@428 540 test -d %1; rc=$?; \
michael@428 541 fi; \
michael@428 542 if [ ".$rc" = .0 ]; then \
michael@428 543 echo "yes"; \
michael@428 544 else \
michael@428 545 echo "no"; \
michael@428 546 fi)
michael@13 547
michael@13 548 # sane build environment setup
michael@428 549 %l_build_path %{l_once l_build_path %(if [ -d %{l_prefix}/lib/openpkg/override ]; then \
michael@428 550 echo "%{l_prefix}/lib/openpkg/override:"; \
michael@428 551 fi)%{l_prefix}/bin:%{l_prefix}/sbin:@l_build_path@%(\
michael@428 552 if [ -d %{l_prefix}/lib/openpkg/fallback ]; then \
michael@428 553 echo ":%{l_prefix}/lib/openpkg/fallback"; \
michael@428 554 fi)}
michael@13 555 %l_build_ldlp %{l_prefix}/lib:@l_build_ldlp@
michael@13 556 %l_build_ulim @l_build_ulim@
michael@13 557 %l_build_shell_cmd %{l_prefix}/lib/openpkg/bash
michael@13 558 %l_build_shell_opt --norc --noprofile --posix
michael@13 559
michael@13 560 # sane build environment for manual usage in macros (currently just $PATH)
michael@428 561 %l_sane_env PATH="%{l_build_path}"; \
michael@428 562 export PATH; \
michael@428 563 LD_LIBRARY_PATH="%{l_build_ldlp}"; \
michael@428 564 export LD_LIBRARY_PATH
michael@13 565
michael@13 566 # sane build environment for %prep/%build/%install
michael@13 567 %_buildshell env -i %{l_build_shell_cmd} %{l_build_shell_opt}
michael@428 568 %___build_pre HOME="%{l_prefix}"\
michael@428 569 SHELL="%{l_build_shell_cmd}"\
michael@428 570 TERM="%{getenv:TERM}"\
michael@428 571 TMPDIR="%{_tmppath}"\
michael@428 572 USER="%{getenv:USER}"\
michael@428 573 LOGNAME="%{getenv:LOGNAME}"\
michael@428 574 PATH="%{l_build_path}"\
michael@428 575 LD_LIBRARY_PATH="%{l_build_ldlp}"\
michael@428 576 export HOME SHELL TMPDIR USER LOGNAME PATH LD_LIBRARY_PATH\
michael@428 577 RPM_SOURCE_DIR=\"%{u2p:%{_sourcedir}}\"\
michael@428 578 RPM_BUILD_DIR=\"%{u2p:%{_builddir}}\"\
michael@428 579 RPM_OPT_FLAGS=\"%{optflags}\"\
michael@428 580 RPM_ARCH=\"%{l_host_arch}\"\
michael@428 581 RPM_OS=\"%{l_host_os}\"\
michael@428 582 RPM_DOC_DIR=\"%{_docdir}\"\
michael@428 583 RPM_PACKAGE_NAME=\"%{name}\"\
michael@428 584 RPM_PACKAGE_VERSION=\"%{version}\"\
michael@428 585 RPM_PACKAGE_RELEASE=\"%{release}\"\
michael@428 586 export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_ARCH RPM_OS RPM_DOC_DIR\
michael@428 587 export RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_RELEASE\
michael@428 588 %{?buildroot:RPM_BUILD_ROOT=\"%{u2p:%{buildroot}}\"\
michael@428 589 export RPM_BUILD_ROOT}\
michael@428 590 %{l_build_ulim}\
michael@428 591 umask 022\
michael@428 592 %{verbose:set -x}%{!verbose:exec >/dev/null}\
michael@428 593 cd %{u2p:%{_builddir}}
michael@428 594
michael@428 595 # improved %patch macro
michael@428 596 %patch(b:p:P:REz:F:d:e:m:) %{lua: \
michael@428 597 local subst = "" \
michael@428 598 local options = rpm.expand("%**") \
michael@428 599 local regex = "-e\\\\s*('[^']*'|\\"[^\\"]*\\"|\\\\S+)" \
michael@428 600 local pcre = rex_pcre.new(regex) \
michael@428 601 local n = 0 \
michael@428 602 while true do \
michael@428 603 local s, e, t = pcre:tfind(options, n) \
michael@428 604 if s == nil then break end \
michael@428 605 subst = subst .. " -e " .. t[1] \
michael@428 606 n = e + 1 \
michael@428 607 end \
michael@428 608 local regex = "-m\\\\s*('[^']*'|\\"[^\\"]*\\"|\\\\S+)" \
michael@428 609 local pcre = rex_pcre.new(regex) \
michael@428 610 local n = 0 \
michael@428 611 while true do \
michael@428 612 local s, e, t = pcre:tfind(options, n) \
michael@428 613 if s == nil then break end \
michael@428 614 subst = subst .. " -e 's;@" .. t[1] .. "@;%{" .. t[1] .. "};g'" \
michael@428 615 n = e + 1 \
michael@428 616 end \
michael@428 617 if subst ~= "" then \
michael@428 618 subst = "| sed" .. subst \
michael@428 619 rpm.define("__patch_subst " .. subst) \
michael@428 620 else \
michael@428 621 rpm.define("__patch_subst %{nil}") \
michael@428 622 end \
michael@428 623 }%{shrink: \
michael@428 624 %define __patch_number %{-P:%{-P*}}%{!-P:0} \
michael@428 625 %define __patch_file %{P:%{__patch_number}} \
michael@428 626 %define __patch_suffix %{-b:-b --suffix %{-b*}}%{!-b:-b --suffix .orig} %{-z:--suffix %{-z*}} \
michael@428 627 %define __patch_options -s %{-p:-p%{-p*}} %{-F:-F%{-F*}} %{-d:-d%{-d*}} %{-R} %{-E} %{__patch_suffix} \
michael@428 628 echo "Patch #%{__patch_number} (%{basename:%{__patch_file}}):"; \
michael@428 629 %{uncompress:%{__patch_file}} %{__patch_subst} | %{__patch} %{__patch_options}}\
michael@428 630 %{nil}
michael@13 631
michael@13 632 # special %track section support
michael@428 633 %__spec_track_pre\
michael@428 634 VCFILE="%{_tmppath}/%{name}-%{version}-%{release}.track.vc"\
michael@13 635 rm -f $VCFILE\
michael@13 636 set -o noclobber\
michael@13 637 sed -e 's;^ *#.*$;;' -e 's;^ ;;' >$VCFILE <<'EOF'\
michael@13 638 %{nil}
michael@13 639 %__spec_track_post EOF\
michael@13 640 if [ ".%{?___track_dump}" = .yes ]; then\
michael@13 641 cat $VCFILE\
michael@13 642 else\
michael@13 643 if [ ! -f "%{l_vcheck}" ]; then\
michael@13 644 echo "rpm:ERROR: Vendor source tracking functionality currently not available because"\
michael@13 645 echo "rpm:ERROR: URL tracking tool vcheck(1) not found under \\"%{l_vcheck}\\"."\
michael@13 646 echo "rpm:ERROR: You have to install the OpenPKG \\"vcheck\\" package first or set"\
michael@13 647 echo "rpm:ERROR: the RPM macro \\"%%{l_vcheck}\\" to the path of your vcheck(1) tool."\
michael@13 648 exit 0\
michael@13 649 fi\
michael@13 650 ( echo "config = {"\
michael@13 651 echo "}"\
michael@13 652 ) >>$VCFILE\
michael@428 653 %{l_vcheck} %{verbose:--verbose}%{!verbose:--noverbose} -f $VCFILE || true\
michael@13 654 fi\
michael@13 655 rm -f $VCFILE\
michael@13 656 %{nil}
michael@13 657
michael@428 658 # support additional .spec tags
michael@428 659 %_arbitrary_tags Class:Track:TrackProg:BuildDependency:BuildEnvironment:My*:Local*
michael@428 660
michael@428 661 # disable /bin/sh dependency (which doesn't fit into OpenPKG's environment)
michael@428 662 %_disable_shell_interpreter_deps 1
michael@428 663
michael@428 664 # support downloading files via cURL (instead of internal RPMIO)
michael@428 665 # and optionally also from global and local mirror and backup location(s)
michael@428 666 %__urlgetfile_urls_mirror() \
michael@428 667 %{nil}
michael@428 668 %__urlgetfile_urls_backup() %{lua: \
michael@428 669 local url = rpm.expand("%1") \
michael@428 670 local name = rpm.expand("%{name}") \
michael@428 671 if name ~= "" and url ~= "" then \
michael@428 672 local cache = "http://download.openpkg.org/components/cache/" .. name .. "/" \
michael@428 673 url = util.rsubst(url, "^.+/([^/]+)$", cache .. "%1") \
michael@428 674 print(url) \
michael@428 675 end \
michael@428 676 }
michael@428 677 %__urlgetfile_urls() \
michael@428 678 %{?__urlgetfile_urls_mirror %1} %1 %{?__urlgetfile_urls_backup %1}
michael@428 679 %__urlgetfile() %{lua: \
michael@428 680 local url_orig = rpm.expand("%1") \
michael@428 681 local file = rpm.expand("%2") \
michael@428 682 local urls = util.rsplit(rpm.expand("%{?__urlgetfile_urls " .. url_orig .. "}"), "\\\\s+") \
michael@428 683 local result = "ERROR" \
michael@428 684 local type = "mirror" \
michael@428 685 for i, url in ipairs(urls) do \
michael@428 686 if url ~= "" then
michael@428 687 if url == url_orig then \
michael@428 688 type = "original" \
michael@428 689 elseif type == "original" then \
michael@428 690 type = "backup" \
michael@428 691 end \
michael@428 692 io.stdout:write(string.format("Fetching(%s): %s\\n", type, url)) \
michael@428 693 local rc = rpm.expand( \
michael@428 694 "%(%{l_prefix}/bin/openpkg curl '-#' -L -R -k " .. \
michael@428 695 "-o '" .. file .. "'" .. " '" .. url .. "' 1>&2; echo $?)" \
michael@428 696 ) \
michael@428 697 if rc == "0" then \
michael@428 698 result = "OK" \
michael@428 699 break \
michael@428 700 end \
michael@428 701 end
michael@428 702 end \
michael@428 703 print(result) \
michael@428 704 }
michael@428 705
michael@428 706 # increase size of line buffer for .spec file parsing
michael@428 707 # from 10KB to 4MB to support rather large BuildEnvironment tags
michael@428 708 %_spec_line_buffer_size 4000000
michael@428 709
michael@428 710 # configure auto-generation of OpenPKG "BuildDependency" and "BuildEnvironment" tags
michael@428 711 %__autogen_builddependency 0
michael@428 712 %__autogen_buildenvironment 0
michael@428 713
michael@428 714 # hook into %description
michael@428 715 %description\
michael@428 716 %{?__hook_description_1}\
michael@428 717 %{?__hook_description_2}\
michael@428 718 %{?__hook_description_3}\
michael@428 719 %{?__hook_description_4}\
michael@428 720 %{?__hook_description_5}\
michael@428 721 %{?__hook_description_6}\
michael@428 722 %{?__hook_description_7}\
michael@428 723 %{?__hook_description_8}\
michael@428 724 %{?__hook_description_9}\
michael@428 725 %%description
michael@428 726
michael@428 727 # magically provide additional tags which are required but are always the same
michael@427 728 %__hook_description_1 %{lua: \
michael@427 729 local prefix = rpm.expand("%{l_prefix_static}") \
michael@427 730 if rpm.expand("%{?prefix}") ~= prefix then \
michael@427 731 print(string.format("Prefix: %s\\n", prefix)) \
michael@427 732 end \
michael@427 733 print("AutoReq: no\\n") \
michael@427 734 print("AutoReqProv: no\\n") \
michael@427 735 }
michael@427 736
michael@428 737 # auto-generate arbitrary tag "Marker" (via "rpm --marker <marker>")
michael@428 738 %__hook_description_2 %{?__marker:Marker: %{__marker}}\
michael@428 739 %{nil}
michael@428 740
michael@428 741 # auto-generate arbitrary tag "BuildDependency" from the standard tag(s) "BuildPreReq"
michael@428 742 # in order to forward-carry this build-time information to the binary RPM and to the RPMDB.
michael@428 743 %__hook_description_3 %{?__autogen_builddependency:%{?buildprereq:BuildDependency: %{@buildprereq:, }}}\
michael@428 744 %{nil}
michael@428 745
michael@428 746 # magically pickup all patched packaging source files (.orig/.rej)
michael@428 747 %__hook_description_4 %{lua: \
michael@428 748 -- assemble RPM's information about SourceN and PatchN \
michael@428 749 local sources = {} \
michael@428 750 local macros = rpm.macros() \
michael@428 751 for name, value in pairs(macros) do \
michael@428 752 local s, _, m = util.rmatch(name, "^(?i)(SOURCE|PATCH)((?:URL)?)(\\\\d+)$") \
michael@428 753 if s ~= nil and value["body"] ~= nil then \
michael@428 754 local n = string.upper(string.sub(m[1], 1, 1)) .. string.lower(string.sub(m[1], 2)) .. m[3] \
michael@428 755 if sources[n] == nil then \
michael@428 756 sources[n] = { url = "", file = "" } \
michael@428 757 end \
michael@428 758 if m[2] ~= nil and m[2] ~= "" then \
michael@428 759 sources[n].url = value["body"] \
michael@428 760 else \
michael@428 761 sources[n].file = value["body"] \
michael@428 762 end \
michael@428 763 end \
michael@428 764 end \
michael@428 765 \
michael@428 766 -- add implicit .spec source file \
michael@428 767 sources["Source999"] = { \
michael@428 768 url = rpm.expand("%{name}.spec"), \
michael@428 769 file = rpm.expand("%{_specdir}/%{name}.spec") \
michael@428 770 } \
michael@428 771 \
michael@428 772 -- auto-generate tags for local SourceN and PatchN files \
michael@428 773 -- where any corresponding .orig/.rej files exists \
michael@428 774 for id, s in pairs(sources) do \
michael@428 775 if util.rmatch(s.url, "^(?:ftp|https?)://.+") == nil then \
michael@428 776 for i, ext in ipairs({ ".orig", ".rej" }) do \
michael@428 777 if posix.access(s.file .. ext, "r") == 0 then \
michael@428 778 local _, _, m = util.rmatch(id, "^(?i)(Source|Patch)(\\\\d+)$") \
michael@428 779 local tag = string.format("%s%d: %s\\n", m[1], 10000 * i + m[2], s.url .. ext) \
michael@428 780 print(tag) \
michael@428 781 end \
michael@428 782 end \
michael@428 783 end \
michael@428 784 end \
michael@428 785 }
michael@428 786
michael@428 787 # recursive package environment tracking configuration
michael@428 788 %__environment_delete_nve_regex ^gpg-pubkey-[^-]+-[^-]+$
michael@428 789 %__environment_prune_nve_regex ^%{name}-[^-]+-[^-]+$
michael@428 790 %__environment_prune_depth_number 3
michael@428 791 %__environment_debug 0
michael@428 792
michael@428 793 # recursive package environment implementation
michael@428 794 %__hook_description_5 %{nil}
michael@428 795 %__hook_description_5_orig %{?__autogen_buildenvironment:%{lua: \
michael@428 796 -- determine current debug status quo
michael@428 797 local debug = tonumber(rpm.expand("%{?__environment_debug}%{!?__environment_debug:0}")) \
michael@428 798 \
michael@428 799 -- determine current environment in serialized format \
michael@428 800 -- (which actually is the Lua table constructor syntax) \
michael@428 801 local result = {} \
michael@428 802 for _, line in ipairs(rpm.query( \
michael@428 803 "Q:\\\\[\\"%{name}-%{version}-%{release}\\"\\\\]=" .. \
michael@428 804 "%|buildenvironment?{%{buildenvironment}}:{\\\\{\\\\}}|,", \
michael@428 805 true, "*")) do \
michael@428 806 local s, _, m = util.rmatch(line, "(?s)^Q:(.+)$") \
michael@428 807 if s ~= nil then \
michael@428 808 table.insert(result, m[1]) \
michael@428 809 end \
michael@428 810 end \
michael@428 811 local constructor = "{" .. table.concat(result , "") .. "}" \
michael@428 812 \
michael@428 813 -- parse current environment \
michael@428 814 -- (by evaluating the constructor as a Lua script) \
michael@428 815 local environment = {} \
michael@428 816 local f = loadstring("return " .. constructor) \
michael@428 817 if f ~= nil then \
michael@428 818 environment = f() \
michael@428 819 else \
michael@428 820 io.stderr:write("rpm: WARNING: failed to parse Lua table constructor: " .. constructor .. "\\n") \
michael@428 821 end \
michael@428 822 if debug > 0 then \
michael@428 823 io.stdout:write("BuildEnvironment(original): " .. util.dump_object(environment, false) .. "\\n") \
michael@428 824 end
michael@428 825 \
michael@428 826 -- prune environment according to configuration \
michael@428 827 function prune_environment (environment, depth) \
michael@428 828 local delete_nve_regex = tostring(rpm.expand("%{?__environment_delete_nve_regex}")) \
michael@428 829 local prune_nve_regex = tostring(rpm.expand("%{?__environment_prune_nve_regex}")) \
michael@428 830 local prune_depth_number = tonumber(rpm.expand("%{?__environment_prune_depth_number}")) \
michael@428 831 if type(environment) == "table" then \
michael@428 832 for nve, _ in pairs(environment) do \
michael@428 833 if (prune_depth_number ~= nil and prune_depth_number > 0 and depth > prune_depth_number) or \
michael@428 834 (delete_nve_regex ~= "" and util.rmatch(nve, delete_nve_regex) ~= nil) then \
michael@428 835 environment[nve] = nil \
michael@428 836 elseif prune_nve_regex ~= nil and util.rmatch(nve, prune_nve_regex) ~= nil then \
michael@428 837 environment[nve] = {} \
michael@428 838 else \
michael@428 839 prune_environment(environment[nve], depth + 1) \
michael@428 840 end \
michael@428 841 end \
michael@428 842 end \
michael@428 843 end \
michael@428 844 prune_environment(environment, 1) \
michael@428 845 if debug > 0 then \
michael@428 846 io.stdout:write("BuildEnvironment(pruned): " .. util.dump_object(environment, false) .. "\\n") \
michael@428 847 end \
michael@428 848 \
michael@428 849 -- export serialized environment as an RPM tag \
michael@428 850 if type(environment) == "table" then \
michael@428 851 local tag = "BuildEnvironment: " .. util.dump_object(environment, true) .. "\\n" \
michael@428 852 print(tag) \
michael@428 853 if debug > 0 then \
michael@428 854 io.stdout:write(tag) \
michael@428 855 end \
michael@428 856 end \
michael@428 857 }}
michael@428 858
michael@428 859 # recursive package environment XML query support
michael@428 860 %__environment_to_xml %{lua: \
michael@428 861 local lua = io.stdin:read("*all") \
michael@428 862 local f = loadstring("return " .. lua) \
michael@428 863 local xml = ""
michael@428 864 if f ~= nil then \
michael@428 865 xml = xml .. "<?xml version=\\"1.0\\" encoding=\\"ISO-8859-1\\" standalone=\\"no\\"?>\\n" \
michael@428 866 xml = xml .. "<!DOCTYPE environment\\n" \
michael@428 867 xml = xml .. " PUBLIC \\"-//rpm5.org//DTD BuildEnvironment 1.0//EN\\"\\n" \
michael@428 868 xml = xml .. " \\"http://rpm5.org/dtd/environment-1.0.dtd\\">\\n" \
michael@428 869 function genxml (environment, prefix) \
michael@428 870 local xml = prefix .. "<environment>\\n" \
michael@428 871 for id, e in pairs(environment) do \
michael@428 872 xml = xml .. prefix .. " <package>\\n" \
michael@428 873 xml = xml .. prefix .. " <id>" .. id .. "</id>\\n" \
michael@428 874 if e ~= nil and next(e) ~= nil then \
michael@428 875 xml = xml .. genxml(e, prefix .. " ") \
michael@428 876 end \
michael@428 877 xml = xml .. prefix .. " </package>\\n" \
michael@428 878 end \
michael@428 879 xml = xml .. prefix .. "</environment>\\n" \
michael@428 880 return xml
michael@428 881 end \
michael@428 882 local environment = f() \
michael@428 883 xml = xml .. genxml(environment, "") \
michael@428 884 end \
michael@428 885 print(xml)
michael@428 886 }
michael@428 887
michael@428 888 # PGP public key information
michael@428 889 %l_pgpkey(n:F:) %{lua: \
michael@428 890 local name = rpm.expand("%{?-n:%{-n*}}%{!?-n:openpkg.org}") \
michael@428 891 local format = rpm.expand("%{?-F:%{-F*}}%{!?-F:%%f:%%i}") \
michael@428 892 local fn = "?" \
michael@428 893 local id = "?" \
michael@428 894 if name == "openpkg.com" then \
michael@428 895 fn = rpm.expand("%{l_prefix}/etc/openpkg/openpkg.com.pgp") \
michael@428 896 id = "7D121A8FC05DC18A4329E9EF67042EC961B7AE34" \
michael@428 897 elseif name == "openpkg.net" then \
michael@428 898 fn = rpm.expand("%{l_prefix}/etc/openpkg/openpkg.net.pgp") \
michael@428 899 id = "3BD10E1171B22598D7708C48AEBE764552197903" \
michael@428 900 elseif name == "openpkg.org" then \
michael@428 901 fn = rpm.expand("%{l_prefix}/etc/openpkg/openpkg.org.pgp") \
michael@428 902 id = "6D96EFCFCF75328810DB40C2807593E063C4CB9F" \
michael@428 903 end \
michael@428 904 local result = util.rsubst(format, "%([nfi])", { ["n"] = name, ["f"] = fn, ["i"] = id }) \
michael@428 905 print(result) \
michael@428 906 }
michael@428 907
michael@428 908 # integrity checking configuration
michael@428 909 %_integrity_spec_cfg_idx %{l_prefix}/etc/openpkg/license
michael@428 910 %_integrity_spec_cfg_dir %{l_prefix}/etc/openpkg/license.d
michael@428 911 %_integrity_spec_cfg %{lua: \
michael@428 912 local idx = rpm.slurp(rpm.expand("%{_integrity_spec_cfg_idx}")) \
michael@428 913 idx = util.rsubst(idx, "(?s)\\\\s*(.+?)\\\\s*$", "%1") \
michael@428 914 local cfg = rpm.expand("%{_integrity_spec_cfg_dir}") .. "/" .. idx \
michael@428 915 print(cfg) \
michael@428 916 }
michael@428 917 %_integrity_proc_lua %{l_prefix}/lib/openpkg/license.lua
michael@428 918 %_integrity_pkey_pgp %{l_prefix}/etc/openpkg/openpkg.com.pgp
michael@428 919
michael@428 920 ##
michael@428 921 ## Support for OpenPKG Flexible Filesystem Layout
michael@428 922 ##
michael@428 923
michael@428 924 # layout definition: RPM to OpenPKG variable mapping
michael@428 925 %_specdir %{expand:%%global _specdir %%{__openpkg_layout variable=specdir %{?openpkg_layout_specdir} %{!?openpkg_layout_specdir: %{openpkg_layout}}}}%{_specdir}
michael@428 926 %_sourcedir %{expand:%%global _sourcedir %%{__openpkg_layout variable=sourcedir %{?openpkg_layout_sourcedir}%{!?openpkg_layout_sourcedir:%{openpkg_layout}}}}%{_sourcedir}
michael@428 927 %_builddir %{expand:%%global _builddir %%{__openpkg_layout variable=builddir %{?openpkg_layout_builddir} %{!?openpkg_layout_builddir: %{openpkg_layout}}}}%{_builddir}
michael@428 928 %_tmppath %{expand:%%global _tmppath %%{__openpkg_layout variable=tmppath %{?openpkg_layout_tmppath} %{!?openpkg_layout_tmppath: %{openpkg_layout}}}}%{_tmppath}
michael@428 929 %_rpmdir %{expand:%%global _rpmdir %%{__openpkg_layout variable=rpmdir %{?openpkg_layout_rpmdir} %{!?openpkg_layout_rpmdir: %{openpkg_layout}}}}%{_rpmdir}
michael@428 930 %_srcrpmdir %{expand:%%global _srcrpmdir %%{__openpkg_layout variable=srcrpmdir %{?openpkg_layout_srcrpmdir}%{!?openpkg_layout_srcrpmdir:%{openpkg_layout}}}}%{_srcrpmdir}
michael@428 931
michael@428 932 # default OpenPKG filesystem layout
michael@428 933 %openpkg_layout macrosfile=%{macrosfile} layout=global
michael@428 934
michael@428 935 # layout determination: RPM macro to RPM Lua entry point
michael@428 936 %__openpkg_layout() %{lua: print(openpkg.layout(rpm.expand("%*"))) }
michael@428 937
michael@428 938 # calculated base directory (placeholder definition only)
michael@428 939 %__openpkg_basedir %{l_prefix}
michael@428 940
michael@428 941 # temporary path determination
michael@428 942 %__openpkg_tmpdir %{lua: print(openpkg.tmpdir()) }
michael@428 943
michael@428 944 # shared environment (SE) support
michael@428 945 %__openpkg_SE_id %{l_hostname}-%{l_platform}-%{l_tag}
michael@428 946 %__openpkg_SE_subdir %{?__openpkg_shared:/%{__openpkg_SE_id}}
michael@428 947
michael@428 948 # layout definition: GLOBAL filesystem layout
michael@428 949 %__openpkg_layout_global_specdir() %{l_prefix}/RPM/SRC/%{?name}
michael@428 950 %__openpkg_layout_global_sourcedir() %{l_prefix}/RPM/SRC/%{?name}
michael@428 951 %__openpkg_layout_global_builddir() %{l_prefix}/RPM/TMP
michael@428 952 %__openpkg_layout_global_tmppath() %{l_prefix}/RPM/TMP
michael@428 953 %__openpkg_layout_global_rpmdir() %{l_prefix}/RPM/PKG
michael@428 954 %__openpkg_layout_global_srcrpmdir() %{l_prefix}/RPM/PKG
michael@428 955
michael@428 956 # layout definition: LOCAL filesystem layout
michael@428 957 %__openpkg_layout_local_specdir() %{__openpkg_basedir}
michael@428 958 %__openpkg_layout_local_sourcedir() %{__openpkg_basedir}
michael@428 959 %__openpkg_layout_local_builddir() %{__openpkg_basedir}/.openpkg-tmp:+%{__openpkg_SE_subdir}
michael@428 960 %__openpkg_layout_local_tmppath() %{__openpkg_basedir}/.openpkg-tmp:+%{__openpkg_SE_subdir}
michael@428 961 %__openpkg_layout_local_rpmdir() %{__openpkg_basedir}
michael@428 962 %__openpkg_layout_local_srcrpmdir() %{__openpkg_basedir}
michael@428 963
michael@428 964 # layout definition: SIMPLE local filesystem layout
michael@428 965 %__openpkg_layout_simple_specdir() %{__openpkg_basedir}
michael@428 966 %__openpkg_layout_simple_sourcedir() %{__openpkg_basedir}
michael@428 967 %__openpkg_layout_simple_builddir() %{__openpkg_tmpdir}:+%{__openpkg_SE_subdir}
michael@428 968 %__openpkg_layout_simple_tmppath() %{__openpkg_tmpdir}:+%{__openpkg_SE_subdir}
michael@428 969 %__openpkg_layout_simple_rpmdir() %{realpath:%{__openpkg_basedir}/..}
michael@428 970 %__openpkg_layout_simple_srcrpmdir() %{realpath:%{__openpkg_basedir}/..}
michael@428 971
michael@428 972 # layout definition: STRUCTURED local filesystem layout
michael@428 973 %__openpkg_layout_structured_specdir() %{__openpkg_basedir}/src
michael@428 974 %__openpkg_layout_structured_sourcedir() %{__openpkg_basedir}/dst %{__openpkg_basedir}/src
michael@428 975 %__openpkg_layout_structured_builddir() %{__openpkg_basedir}/tmp:+%{__openpkg_SE_subdir} %{__openpkg_tmpdir}:+%{__openpkg_SE_subdir}
michael@428 976 %__openpkg_layout_structured_tmppath() %{__openpkg_basedir}/tmp:+%{__openpkg_SE_subdir} %{__openpkg_tmpdir}:+%{__openpkg_SE_subdir}
michael@428 977 %__openpkg_layout_structured_rpmdir() %{__openpkg_basedir}/pkg/bin %{__openpkg_basedir}/pkg %{__openpkg_basedir}
michael@428 978 %__openpkg_layout_structured_srcrpmdir() %{__openpkg_basedir}/pkg/src %{__openpkg_basedir}/pkg %{__openpkg_basedir}
michael@428 979
michael@428 980 # layout definition: DISTRIBUTED local filesystem layout
michael@428 981 %__openpkg_layout_distributed_specdir() %{__openpkg_basedir}/src/%{?name}
michael@428 982 %__openpkg_layout_distributed_sourcedir() %{__openpkg_basedir}/dst/%{?name} %{__openpkg_basedir}/src/%{?name}
michael@428 983 %__openpkg_layout_distributed_builddir() %{__openpkg_basedir}/tmp:+%{__openpkg_SE_subdir} %{__openpkg_tmpdir}:+%{__openpkg_SE_subdir}
michael@428 984 %__openpkg_layout_distributed_tmppath() %{__openpkg_basedir}/tmp:+%{__openpkg_SE_subdir} %{__openpkg_tmpdir}:+%{__openpkg_SE_subdir}
michael@428 985 %__openpkg_layout_distributed_rpmdir() %{__openpkg_basedir}/pkg/bin %{__openpkg_basedir}/pkg %{__openpkg_basedir}
michael@428 986 %__openpkg_layout_distributed_srcrpmdir() %{__openpkg_basedir}/pkg/src %{__openpkg_basedir}/pkg %{__openpkg_basedir}
michael@428 987

mercurial