Rufeer
Rufeer

Reputation: 11

How can I modify .rpmmacros file to add an compilation option for a subset of RPM packages?

I want to build a group of rpm packages, and some of them need to have an additional compilation option (-my_own_option).

I tried this in ~/.rpmmacros, but the %{name} is not getting expanded while building the rpm

%if "%{name}" == "zip" \
%__global_compiler_flags -my_own_option \
%endif

Upvotes: 0

Views: 113

Answers (2)

Ichsan Dicki
Ichsan Dicki

Reputation: 1

The provided information suggests that modifying the .rpmmacros file might not be the most effective approach to add a compilation option for a subset of RPM packages. Here's why:

.rpmmacros is global: Changes made to this file affect all RPM builds on your system, not just a specific subset of packages. This can lead to unintended consequences if other packages rely on the default compilation flags.

Here are some alternative approaches you can consider:

Modify the spec file: Spec files are used to define how RPM packages are built. You can edit the spec file for each package that needs the additional compilation option and add the flag directly within the spec file. This is a more targeted approach that ensures the option is only applied to the desired packages.

Here's an example of how to add a compilation option (-my_own_option) to a specific package in its spec file:

%define _myopt -my_own_option

%build ... %{_build} %{_myopt}

%install ... %{_install} %{_myopt}

In this example, the _myopt macro is defined with the value -my_own_option. Then, the %build and %install sections reference this macro to include the compilation option during the build and installation stages.

Conditional compilation flags: Some build systems allow for conditional compilation based on macros or flags. You can explore this option if the build system used by your RPM packages supports it. This would allow you to define a macro or flag within the spec file and conditionally include the compilation option based on that flag.

By using either modifying the spec file or exploring conditional compilation flags within the build system, you can achieve the goal of adding a compilation option for a specific subset of RPM packages without modifying the global .rpmmacros file.

Upvotes: -2

Rufeer
Rufeer

Reputation: 11

it works:

addopt() %{lua: \
    local optArray = {"zip", "mysql", "perl"} \
    for _, v in ipairs(optArray) do \
        if rpm.expand("%{name}") == v then \
            print("-my_own_option") \
            break \
        end \
    end \
    print("")
}
%__global_compiler_flags %{addopt} -O2 ...

Upvotes: 1

Related Questions