Page 1 of 1

[SOLVED] how to add a flag to cc in a spec file?

PostPosted: Oct 9th, '20, 09:47
by john_gibbe
I'm on cauldron. I would like to modify a package that existed in Mageia4 as it it a dependency of prosody server, which is itself a dependency of jisti-meet server that I would like to install on my mageia computer. So I've downloaded mageia4 luaexpat source package and proceed it with rpmbuild --rebuild. I download also last version of luaexpat and put the tar.gz file in rpmbuild/SOURCES directory. No need to say I've never use rpmbuild and that quit difficult to understand what is written in the spec file but I modify the rpmbuild/SPECS/luaexpat.spec as follow:
Code: Select all
%define luaver 5.3
%define lualibdir %{_libdir}/lua/%{luaver}
%define luapkgdir %{_datadir}/lua/%{luaver}
%define oname luaexpat

Name:           lua-expat
Version:        1.3.0
Release:        %mkrel 1
Summary:        SAX XML parser based on expat, for lua
Group:          Development/Other
License:        MIT
URL:            https://matthewwild.co.uk/projects/luaexpat/
Source0:        https://matthewwild.co.uk/projects/luaexpat/%{oname}-%{version}.tar.gz
BuildRequires:  lua5.3
BuildRequires:  lua5.3-devel
BuildRequires:  expat-devel
Requires:       lua5.3
%description
SAX XML parser based on expat, for lua.

%prep
%setup -q -n %{oname}-%{version}


%build
perl -pi -e 's/(CFLAGS =)/$1 -fPIC/' config
echo 'LUA_VERSION_NUM=503"' >> config
%make_build

%install
rm -rf %{buildroot}
make install LUA_LIBDIR=$RPM_BUILD_ROOT%{lualibdir} LUA_DIR=$RPM_BUILD_ROOT%{luapkgdir}

%clean
rm -rf $RPM_BUILD_ROOT


%files
%defattr(-,root,root,-)
%doc README  doc/us/*
%{lualibdir}/*
%{luapkgdir}/*




%changelog
* Fri Oct 09 2020 john_gibbe <john_gibbe> 1.3.0-1.mga8
+ Revision: 1.3.0-1
- adaptation to bulid on Mageia 8

* Fri Oct 18 2013 umeabot <umeabot> 1.2.0-4.mga4
+ Revision: 507588
- Mageia 4 Mass Rebuild

* Sat Jan 12 2013 umeabot <umeabot> 1.2.0-3.mga3
+ Revision: 359045
- Mass Rebuild - https://wiki.mageia.org/en/Feature:Mageia3MassRebuild

* Sun Dec 23 2012 pterjan <pterjan> 1.2.0-2.mga3
+ Revision: 334420
- Force Lua 5.1

* Thu Sep 08 2011 tv <tv> 1.2.0-1.mga2
+ Revision: 141150
- new release (fixes CVE-2011-2188)

* Fri Apr 15 2011 shikamaru <shikamaru> 1.1-2.mga1
+ Revision: 85959
- Clean spec (buildroot, trailing space, one BR per line)
- imported package lua-expat


* Fri May 01 2009 Michael Scherer <misc@mandriva.org> 1.1-1mdv2010.0
+ Revision: 369965
- add missing BuildRequires
- import lua-expat



when I rebuild it with "rpmbuild -ba lua-expat.spec" gives:
Code: Select all
# LANGUAGE=en rpmbuild -ba lua-expat.spec
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.Cc3mBV
+ umask 022
+ cd /root/rpmbuild/BUILD
+ '[' 1 -eq 1 ']'
+ '[' 1 -eq 1 ']'
+ '[' 1 -eq 1 ']'
+ cd /root/rpmbuild/BUILD
+ rm -rf luaexpat-1.3.0
+ /usr/bin/gzip -dc /root/rpmbuild/SOURCES/luaexpat-1.3.0.tar.gz
+ /usr/bin/tar -xof -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd luaexpat-1.3.0
+ /usr/bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ RPM_EC=0
++ jobs -p
+ exit 0
Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.GLO3hW
+ umask 022
+ cd /root/rpmbuild/BUILD
+ cd luaexpat-1.3.0
+ '[' 1 -eq 1 ']'
+ '[' 1 -eq 1 ']'
+ perl -pi -e 's/(CFLAGS =)/$1 -fPIC/' config
Can't open config: No such file or directory.
+ echo 'LUA_VERSION_NUM=503"'
+ /usr/bin/make -O -j12 V=1 VERBOSE=1
export MACOSX_DEPLOYMENT_TARGET="10.3";
cc -I/usr/include/lua5.1 -I/usr/include -g -pedantic -Wall -O2 -fPIC -DPIC -ansi  -o src/lxp.so src/lxplib.c -shared -lexpat
In file included from /usr/include/lua.h:16,
                 from src/lxplib.c:14:
/usr/include/luaconf.h:584:2: error: #error "Compiler does not support 'long long'. Use option '-DLUA_32BITS'   or '-DLUA_C89_NUMBERS' (see file 'luaconf.h' for details)"
  584 | #error "Compiler does not support 'long long'. Use option '-DLUA_32BITS' \
      |  ^~~~~
In file included from src/lxplib.c:14:
/usr/include/lua.h:93:9: error: unknown type name 'LUA_INTEGER'
   93 | typedef LUA_INTEGER lua_Integer;
      |         ^~~~~~~~~~~
/usr/include/lua.h:96:22: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'lua_Unsigned'
   96 | typedef LUA_UNSIGNED lua_Unsigned;
      |                      ^~~~~~~~~~~~
make: *** [Makefile:27: src/lxp.so] Error 1
error: Bad exit status from /var/tmp/rpm-tmp.GLO3hW (%build)


RPM build errors:
    Bad exit status from /var/tmp/rpm-tmp.GLO3hW (%build


I tried it by hand and checked that effectively it lacks -DLUA_C89_NUMBER in cc flags. What is the spec command line to automatically add this flag?

Re: how to add a flag to cc in a spec file?

PostPosted: Oct 9th, '20, 15:34
by doktor5000
There's no specific command line, and this is also not related to the .spec file

You can do it the same way like -fPIC is already added to CFLAGS. Or just extend an environment variable for it:

CCFLAGS="$CCFLAGS -DLUA_C89_NUMBER"; export CCFLAGS

[SOLVED] Re: how to add a flag to cc in a spec file?

PostPosted: Oct 9th, '20, 17:31
by john_gibbe
Many thank's. I've put a line in the spec file and manage to make some change to the Makefile and the build gone through with this very dirty spec file:
Code: Select all
%define luaver 5.3
%define lualibdir %{_libdir}/lua/%{luaver}
%define luapkgdir %{_datadir}/lua/%{luaver}
%define oname luaexpat

Name:           lua-expat
Version:        1.3.0
Release:        %mkrel 1
Summary:        SAX XML parser based on expat, for lua
Group:          Development/Other
License:        MIT
URL:            https://matthewwild.co.uk/projects/luaexpat/
Source0:        https://matthewwild.co.uk/projects/luaexpat/%{oname}-%{version}.tar.gz
BuildRequires:  lua%{luaver}
BuildRequires:  lua%{luaver}-devel
BuildRequires:  expat-devel
Requires:       lua%{luaver}
%description
SAX XML parser based on expat, for lua.

%prep
%setup -q -n %{oname}-%{version}


%build
perl -pi -e 's/(CFLAGS =)/$1 -fPIC/' config
echo 'LUA_VERSION_NUM=503"' >> config
CFLAGS="$CFLAGS -DLUA_C89_NUMBERS"; export CFLAGS
%make_build

%install
rm -rf %{buildroot}/*
perl -pi -e 's/5.1/5.3/g' Makefile
perl -pi -e 's/\/usr\/lib\/lua/\/root\/rpmbuild\/BUILDROOT\/lua-expat-1.3.0-1.mga8.x86_64\/usr\/lib64\/lua/g' Makefile
perl -pi -e 's/\/usr\/share\/lua/\/root\/rpmbuild\/BUILDROOT\/lua-expat-1.3.0-1.mga8.x86_64\/usr\/share\/lua/g' Makefile
mkdir -p $RPM_BUILD_ROOT%{lualibdir}
make install LUA_LIBDIR=$RPM_BUILD_ROOT%{lualibdir} LUA_DIR=$RPM_BUILD_ROOT%{luapkgdir}

%clean
rm -rf $RPM_BUILD_ROOT


%files
%defattr(-,root,root,-)
%doc README  doc/us/*
%{lualibdir}/*
%{luapkgdir}/*




%changelog
* Fri Oct 09 2020 john_gibbe <john_gibbe> 1.3.0-1.mga8
+ Revision: 1.3.0-1
- adaptation to bulid on Mageia 8

* Fri Oct 18 2013 umeabot <umeabot> 1.2.0-4.mga4
+ Revision: 507588
- Mageia 4 Mass Rebuild

* Sat Jan 12 2013 umeabot <umeabot> 1.2.0-3.mga3
+ Revision: 359045
- Mass Rebuild - https://wiki.mageia.org/en/Feature:Mageia3MassRebuild

* Sun Dec 23 2012 pterjan <pterjan> 1.2.0-2.mga3
+ Revision: 334420
- Force Lua 5.1

* Thu Sep 08 2011 tv <tv> 1.2.0-1.mga2
+ Revision: 141150
- new release (fixes CVE-2011-2188)

* Fri Apr 15 2011 shikamaru <shikamaru> 1.1-2.mga1
+ Revision: 85959
- Clean spec (buildroot, trailing space, one BR per line)
- imported package lua-expat


* Fri May 01 2009 Michael Scherer <misc@mandriva.org> 1.1-1mdv2010.0
+ Revision: 369965
- add missing BuildRequires
- import lua-expat

I mark the problem as solved