Issue
I made some spec files to build RPMs. I use some commands like cp or ln or chown. I thought macros would help, to use the specific version at the system, where the RPM is installed to, so I use things like %{__cp} %{__ln_s} etc. The RPM is build on a CentOS 7, but now I tried to installed it to a CentOS 6 and I get errors that cp and ln are not found in /usr/bin/ but they do exist in /bin
/var/tmp/rpm-tmp.ElF6f7: line 46: /usr/bin/chown: No such file or directory
/var/tmp/rpm-tmp.ElF6f7: line 49: /usr/bin/cp: No such file or directory
At the CentOS 7 they also exist in /bin as well as in /usr/bin
So now I wonder, why to use these macros, wouldn't it be easier to use cp and ln and chown just as they are? I think for my case that would be better as I don't wont my packages just for a specific Distribution, they should work many distributions.
Solution
You are right, sometime it is contraproductive to use macros at all cost.
Additionally if I apply the namespace logic from other programming languages, the macros with two undescores (e.g. %{__cp}
) are meant to be just internals. I.e. they are used in definition of other macros, but should not be used directly.
While there exist macros which are heavily used and from time to time overwritten (e.g %{_smp_mflags}
or various directory names) there exists macros which just confuse the reading e.g %{__mkdir_p}.
Others are rather meant so you can query them %{_buildshell}
. It is much saver to execute your shell script using /usr/bin/bash foo.sh
rather than %{_buildshell} foo.sh
.
Answered By - msuchy Answer Checked By - Willingham (WPSolving Volunteer)