]> git.pld-linux.org Git - packages/rpm.git/blobdiff - rpm.macros
- it uses bash syntax, maybe should be rewritten
[packages/rpm.git] / rpm.macros
index 232925dd76fb8e4cff2c8f7a01675c3216fe1b72..40e37005d8e553f49999d0adbb829bb1a94ee4c3 100644 (file)
         };
 }')
 
+#-----------------------------------------------------------------
+#
+#  Generate a command which cleans environment, leaving only the
+# most important variables.
+#  If any spec requires any additional environment it should
+# redefine %_preserve_env in following manner:
+#
+#      # ADDITIONAL_VAR is required because [a good reason here]
+#      %{expand:%%define _preserve_env %_preserve_env ADDITIONAL_VAR}
+
+%_preserve_env PATH HOME TMP TMPDIR
+
+%_clean_env            env -i %(awk -vq="'" -vqq="\\"'\\"" -vq2q="'\\"'" 'BEGIN {
+       split("%{?_preserve_env:%_preserve_env}", P);
+       for (i in P) {
+               p = P[i];
+               if (ENVIRON[p]) {
+                       split( ENVIRON[p], V, "" );
+                       val = p "=";
+                       for ( j = 1; j in V; j++ ) {
+                               v = V[j];
+                               if ( v == q )
+                                       v = qq;
+                               else if ( v == "\\"" )
+                                       v = q2q;
+                               else if ( v == "\\\\" )
+                                       v = "\\\\\\\\";
+                               else
+                                       gsub( "[^a-zA-Z0-9/:._-]", "\\"&\\"", v );
+                               val = val "" v;
+                       }
+                       printf( val " " );
+               }
+       }
+}')
+
 #-----------------------------------------------------------------
 %configure2_13 { \
  if [ -n "$LINGUAS" ]; then unset LINGUAS; fi; \
@@ -263,7 +299,7 @@ CXXFLAGS="%{rpmcxxflags}" \
 %__unsermake /usr/share/unsermake/unsermake
 
 # Current date
-%date          %(LC_ALL="C" date +"%a %b %d %Y")
+%date          %(LC_ALL=C date +"%a %b %d %Y")
 
 # Example files, programs, scripts...
 %_examplesdir  /usr/src/examples
@@ -278,7 +314,7 @@ CXXFLAGS="%{rpmcxxflags}" \
 %_rpmfilename          %%{NAME}-%%{VERSION}-%%{RELEASE}%{?debug:dbg}.%%{ARCH}.rpm
 
 # Requires name = version-release
-%requires_releq()              %(echo '%*' | LC_ALL="C" xargs -r rpm -q --qf 'Requires: %{N} = %|E?{%{E}:}|%{V}-%{R}\\n' | grep -v 'is not')
+%requires_releq()              %(Z=$(echo '%*' | LC_ALL=C xargs -r rpm -q --qf 'Requires: %{N} = %|E?{%{E}:}|%{V}-%{R}\\n'); if echo "$Z" | ! grep -v '^Requires:'; then echo "$Z"; fi)
 
 %releq_kernel                  %{expand:%%global releq_kernel %(R=$(LC_ALL=C rpm -q --qf '%{N} = %|E?{%{E}:}|%{V}-%{R}' -f %{_kernelsrcdir}/include/linux/version.h 2>/dev/null | grep -v 'is not' | sed -e 's:-headers::;s:-config::'); echo ${R:-ERROR})}%releq_kernel
 %releq_kernel_up               %{expand:%%global releq_kernel_up %(R=$(LC_ALL=C rpm -q --qf '%{N}-up = %|E?{%{E}:}|%{V}-%{R}' -f %{_kernelsrcdir}/include/linux/version.h 2>/dev/null | grep -v 'is not' | sed -e 's:-headers::;s:-config::'); echo ${R:-ERROR})}%releq_kernel_up
@@ -287,9 +323,10 @@ CXXFLAGS="%{rpmcxxflags}" \
 %requires_releq_kernel_up(s:)  Requires%{-s:(%{-s*})}: %releq_kernel_up
 %requires_releq_kernel_smp(s:) Requires%{-s:(%{-s*})}: %releq_kernel_smp
 
-# XXX: why epoch 0 is stripped?
-%requires_eq()         %(echo '%*' | LC_ALL="C" xargs -r rpm -q --qf 'Requires: %{N} = %|E?{%{E}:}|%{V}\\n' | sed -e 's/ 0:/ /' | grep -v 'is not')
-%requires_eq_to() %(LC_ALL="C" rpm -q --qf 'Requires: %1 = %|E?{%{E}:}|%{V}' %2 | grep -v "is not")
+# Requires: name = version
+%requires_eq()         %(Z=$(echo '%*' | LC_ALL=C xargs -r rpm -q --qf 'Requires: %{N} = %|E?{%{E}:}|%{V}\\n'); if echo "$Z" | ! grep -v '^Requires:'; then echo "$Z"; fi)
+# Requires: name = version (version based on querying package %2)
+%requires_eq_to() %(%{!?2:echo "ERROR: missing param 2 to %%requires_eq_to"}%{?2:Z=$(LC_ALL=C rpm -q --qf 'Requires: %1 = %|E?{%{E}:}|%{V}' %2 | grep -v "is not"); echo ${Z:-[%%requires_eq_to %1 %2] expanded to nothing}})
 
 %apache_modules_api %{expand:%%global apache_modules_api %(awk '/#define MODULE_MAGIC_NUMBER_MAJOR/ {print $3}' /usr/include/apache/ap_mmn.h 2>/dev/null || echo ERROR)}%apache_modules_api
 
@@ -487,6 +524,21 @@ if [ -d "$RPM_BUILD_ROOT" ]; then \
        fi; \
 fi; }; __spec_install_post_chrpath } } }
 
+#-----------------------------------------------------------------
+# Find all shared object files with unresolved symbols. Warn
+# and terminate if any found (termination can be turned off by define).
+#%no_install_post_check_so 1
+%__spec_install_post_check_so { \
+ __spec_install_post_check_so() { \
+    fail=0; \
+    printf "Searching for shared objects with unresolved symbols..."; \
+    for f in $(find $RPM_BUILD_ROOT -type f -name '*.so.*' -print); do \
+        LC_ALL=C objdump -T $f 2> /dev/null | LC_ALL=C awk -v "file=$f" 'BEGIN { found=0; skip["program_name"]=1; symbols = "" } /^[0-9a-z]+ +D +\*UND\*/ { if ($NF in skip) { next; }; found = 1; symbols = symbols "\n\t" $NF } END { if (found) { print "\nUnresolved symbols found in: " file symbols; exit(1); } } ' || fail=1 ; \
+    done ; \
+    echo " DONE"; \
+    %{!?no_install_post_check_so:[ $fail -eq 1 ] && : || :;} \
+}; __spec_install_post_check_so }}
+
 #-----------------------------------------------------------------
 # Find and gzip all kernel modules
 #
@@ -757,19 +809,25 @@ fi \
 %pyrequires_eq() Requires:     %1
 
 # Hardlink binary identical .pyc and .pyo files
-# (idea by glen <at> pld-linux <dot> org)
 %__spec_install_post_py_hardlink {\
 %{!?no_install_post_py_hardlink: __spec_install_post_py_hardlink() { \
-[ ! -d "$RPM_BUILD_ROOT" ] || find "$RPM_BUILD_ROOT" -name '*.pyc' | while read a; do \
-       b="${a%.pyc}.pyo"; \
-       if cmp -s "$a" "$b"; then \
-               ln -f "$a" "$b"; \
-       fi; \
-done \
+local a b c=0 t=0; \
+if [ -d "$RPM_BUILD_ROOT" ]; then \
+       find "$RPM_BUILD_ROOT" -name '*.pyc' > __rpm_pyc; \
+       while read a; do \
+               b="${a%.pyc}.pyo"; \
+               if cmp -s "$a" "$b"; then \
+                       ln -f "$a" "$b"; \
+                       c=$((c + 1)); \
+               fi; \
+               t=$((t + 1)); \
+       done < __rpm_pyc; \
+       [ $t -gt 0 ] && printf "Hardlink Python files: %d/%d files hardlinked\n" $c $t; \
+       rm -f __rpm_pyc; \
+fi; \
 }; __spec_install_post_py_hardlink } }
 
 # remove python sources, so that check-files won't complain
-# (idea by glen <at> pld-linux <dot> org)
 %py_postclean() \
 for d in %{py_sitescriptdir} %{py_sitedir} %*; do \
  [ ! -d "$RPM_BUILD_ROOT$d" ] || find "$RPM_BUILD_ROOT$d" -name '*.py' -print0 | xargs -0r -l512 rm;\
@@ -1324,6 +1382,7 @@ for cfg in ${cfgs:-dist}; do                                        \
        %else                                                                                                                   \
                install -d o/include/config                                                                     \
                touch o/include/config/MARKER                                                           \
+               ln -sf %{_kernelsrcdir}/include/config/auto-$cfg.conf o/include/config/auto.conf        \
                ln -sf %{_kernelsrcdir}/scripts o/scripts                                       \
        %endif                                                                                                                  \
                                                                                                                                        \
@@ -1370,6 +1429,7 @@ compile %{*}\
 %define KernelD $RPM_BUILD_ROOT/lib/modules/%{_kernel_ver}                     \
 %define ModprobeD $RPM_BUILD_ROOT%{_sysconfdir}/modprobe.d/%{_kernel_ver} \
                                                                                                                                        \
+__install_kernel_modules() {                                                                           \
 local cfgs='%{?with_dist_kernel:%{?with_smp: smp}%{?with_up: up}}%{!?with_dist_kernel: nondist}' \
                                                                                                                                        \
 for MODULE in {%{-m*},}; do                                                                                    \
@@ -1384,6 +1444,8 @@ for MODULE in {%{-m*},}; do                                                                                       \
                        >> %{ModprobeD}$suf/%{-n*}.conf}                                                \
        done                                                                                                                    \
 done                                                                                                                           \
+}                                                                                                                                      \
+__install_kernel_modules                                                                                       \
 %{nil}
 
 # patchset macros
This page took 0.045239 seconds and 4 git commands to generate.