Preventing hardcode path in RPM SPEC file - redhat

I am creating rpm for apc. While writing spec file, I realized that some commands may have path which can keep on changing which are required during the compilation time. For eg. these commands are required to be executed during the building time.
$ /usr/local/php/bin/phpize
$ ./configure --with-php-config=/usr/local/php/bin/php-config
But the complete path of phpize and php-config file may change. So how can i prevent this dependencies so that i should not hard-code these path in my spec file.

Because these commands are used at building time, the ideal solution to this problem is here:
Find packages on distribution which provide these commands or paths e.g php-config is provided by php-devel package on Fedora operating system. In fedora you can find it using yum whatprovides "*/php-config" or if they are already installed on system then using rpm -qf /path/to/command.
Once you know the packages add them as BuildRequire tag in spec file. Step 2 will make sure that paths are always present whenever you build the package from spec file even if you use hard coded paths (which isn't ofcourse best way to do it).
In place of /usr/ you can use %{_prefix}, it depends entirely on macros available on distribution you are building this rpm on. Check macro files for path macros. One link which has common macro definitions is here.

Related

How can I configure rpmbuild to use lib64/perl5 as an install path?

I am running CentOS7 (RHEL7) and I am trying to build a Perl module with rpmbuild. I have generated the SPEC file and it builds all the way until it installs, which fails.
error: File not found by glob: /home/user/rpm/BUILDROOT/perl-Data-Dumper-2.167_02-1.el7.centos.x86_64/usr/lib64/perl5/vendor_perl/auto/*
I see that in the .spec file, it is looking for %{perl_vendorarch}/auto/* so it's looking in the right place (same place that yum installs pre-built rpms for perl modules.)
HOWEVER, when doing the install phase, it seems rpmbuild is trying to use (via the MakeMaker generated Makefile) my PERL5LIB /home/user/perl5/lib/perl5. I can change the INSTALL_DIR via the spec to /usr, however, I can't figure out how to change the suffix to lib/perl5
Is there anyway to tell MakeMaker to use a different suffix?

Swift toolchain location on Linux

I'm looking into running Swift on a Ubuntu 16.04 server. However I want to be certain about where I should install the toolchain.
From swift.org:
If you installed the Swift toolchain on Linux to a directory other than the system root, you will need to run the following command, using the actual path of your Swift installation...
Then from Kitura's Setting Up instructions:
After extracting the .tar.gz file, update your PATH environment variable so that it includes the extracted tools:
$ export PATH=<path to uncompressed tar contents>/usr/bin:$PATH
Where is the best place to install these type of things? In the past I would rely on apt-get or installation scripts provided by maintainers but this doesn't seem to be the case with Swift.
Are there any benefits or disadvantages to not installing it at the system root?
Note: This question borders on "best practices", which I believe is frowned upon here. I'm sorry about that; I've googled around and this seems to be something that people know implicitly. However, I don't yet and need some guidance
The versions of the software in your system root - in /usr/bin, /usr/share, /usr/lib, etc. - are carefully coordinated by the maintainers of your distribution to handle all reasonable dependencies. The maintainers also keep the software up-to-date with bug fixes.
When you need to install software that isn't supplied by your distribution, it's best to install it in a separate directory, such as /opt (in your case, one possibility is /opt/swift-3.1.1). This will avoid overwriting existing installed software (in your case, /usr/bin/lldb and /usr/lib/lldb) with something that's possibly incompatible with other software. And it will make it easy to uninstall (just rm -r /opt/swift-3.1.1 rather than having to get a list of files from the original tarball that are potentially strewn all over /usr).
There is some extra effort: you'll need to add /opt/swift-3.1.1/usr/bin to your PATH1. With some software, you'll need to add the directory containing dynamic library files to LD_LIBRARY_PATH. The software's installation instructions typically explains what you need to do.
[1]An alternative to changing PATH is to add a symlink to each new executable, in a directory that's already in your PATH. GNU Stow can help you do this.

How would I make "read" command work in RPM spec file?

I wrote a SPEC file to build RPM package. I need to let end user to determine the value of an variable in the %pre section. So I use "read < my_variable >" command in the %pre section. But, when installing, the "read" command seems ignored by system, because the system didn't wait for me to enter the value. Why? and Is there any good method to do the above thing?
Rather than embed the read within your package, RPM has a conditional mechanism which can be used via command-line parameters. Most usage of conditionals in RPMs tests constants defined in the system's RPM macros or making simple filesystem checks. You should investigate those first, because it allows your package to install without help from the person doing the install.
Here are some useful pages discussing RPM conditionals:
Passing conditional parameters into a rpm build (rpm.org)
PackagerDocs/ConditionalBuilds (rpm.org)
Conditionals (Maximum RPM: Taking the Red Hat Package Manager to the Limit)
openSUSE:RPM conditional builds
As one can see from the suggested reading, these are build-time rather than install-time features. You cannot make an "interactive" RPM install. To read more about that, see these pages:
Is it possible to get user's input during installation of rpm?
RPM - Install time parameters
The latter is clear that this is intentional on the part of the developers. As an aside, one response mentions the --relocate option, implying that this solves the problem. However, it is actually different. Read more about that here:
Relocatable packages
Chapter 15. Making a Relocatable Package (Maximum RPM)

cmake which package name to pass to find_package

I am trying to link against the libconfig++ library using cmake. I installed the library
using apt-get so I am assuming it will have a .cmake file so I can use find_package. Problem is I don't know what package name to use. I tried libconfig, config, config++ as the package name to no avail.
As a general question, how does one find out which package is associated with a library.
I know that find_package looks into CMAKE_MODULE_PATH to see if there is a .cmake script. How to I find out what is the value of CMAKE_MODULE_PATH on my system. It's not an environment variable. I am running ubuntu 12.04.
Any help is appreciated.
To use find_package you need to have corresponding Find or Config cmake file. But library may not to provide it, seems with your library is such a case. You can use find_library for finding libraries and find_path to find include directories. With these commands you can even write FindXXX.cmake yourself.
CMAKE_MODULE_PATH is not an environment variable, it is CMake's one. This variable is intended for you to set, if you have additional directories with modules, by default it's empty. This is used in the "Module" mode. In this mode CMake searches FindXXX.cmake in the CMAKE_MODULE_PATH (your modules) or in modules shipped with CMake and if it's found, it then used to find library and it's headers.
If that module wasn't found, it then switches into "Config" mode. On Unix it searches for ConfigXXX.cmake in the following directories:
<prefix>/(lib/<arch>|lib|share)/cmake/<name>*/
<prefix>/(lib/<arch>|lib|share)/<name>*/
<prefix>/(lib/<arch>|lib|share)/<name>*/(cmake|CMake)/
This files is shipped with the library, so there is no need to find anything, they contain all information, where library and includes located, etc.
About naming scheme, there is no standard one. You can look at Standard CMake modules. Modules found in internet for your library named FindLibConfig.cmake
For your case, library ships without corresponding cmake file, so you should write it your self (or find already written) and add directory with that file to CMAKE_MODULE_PATH.
I suggest you to read how find_package command works and how to write FindXXX.cmake files.

I'm confused about installing WWW::Curl for Perl in Cygwin

I have already installed Perl and libcurl using Cygwin's package manager. Now, I'm trying to install WWW::Curl. I have to specify the cURL include directory in WWW::Curl's Makefile.PL, but I have no idea where to look for this. Thanks for your time.
It will try to guess automatically. If it does not work, see the README.
P.S. LWP is more convenient to use.
edit: Using your package managers own packages is often preferred when using your system perl, cygwin has a package for perl-WWW-Curl, install this package rather than building your own.
Most likely I think you are missing the libcurl-devel package. Although you mention that libcurl is installed, please ensure that libcurl-devel is installed via the cygwin package management application, and try again if required.
WWW:Curl will search for the correct include path, looking for curl/curl.h, if it cannot find the file then it might be looking in the wrong places, you'll have to do a manual install:
download and unpack the package from cpan
read the included README file to understand this process
search your cygwin installation for a file called curl/curl.h note the directory that it is in.
modify the Makefile.PL so that #includes has the directory noted above included.
run perl Makefile.PL
run make && make install
This process is essentially the same problem as the process for a native Win32/strawberry perl install, in that it doesnt know where libcurl is located. you can check the README.Win32 file for similar instructions.
The libcurl-devel package installs the curl/curl.h file to usr/include/ which is a path that is already searched by Makefile.PL.
To however you say you have no idea where to look, locate the curl.h you can do the following:
find / -name curl.h
But be warned this could take a long time, you could try specific locations such as /usr
find /usr -name curl.h
Or even better you can look at the package contents to find the file location:
https://cygwin.com/cgi-bin2/package-cat.cgi?file=x86%2Flibcurl-devel%2Flibcurl-devel-7.41.0-1&grep=libcurl
To echo Alexandr's answer, LWP is more convenient to use cross platform, while covering the same features, it can also do a lot more.