Search code examples
rpmbuild

Spec rpm: how to enter in build directory without using tar files?


I want to build a project from git, and create the rpm,this is the spec,is incomplete, but the most interesting part is first one. I need to enter in build dir created by git,but fail This is the part of spec. file

%define build_timestamp %(date +"%Y%m%d")
#
Summary:        My git project
Name:           gitproject
Release:        1
Version:        %{build_timestamp}
License:        GPLv2+
Group:          Unspecified
URL:            https://mygitserver.com/myname/myproject
#-----------------------------------------------------
Requires:       openssl
BuildRequires:  compat-openssl10-devel
BuildRoot:      %{_tmppath}/%{name}-%{version}-buildroot
#-----------------------------------------------------
AutoReqProv: no

%description
Git personal project, is in testing

%prep
git clone  https://mygitserver.com/myname  %{name}
cd %{name}

The problem is..instead of enter in %{name} enter in BUILD..which of course contain a lot of dirs..but not the makefile.

+ umask 022
+ cd /home/user/rpmbuild/BUILD
+ make -j2
make: *** No targets specified and no makefile found.  Stop.

How can I enter %{name}?


Solution

  • I wouldn't skip the tgz part, but let git do the work for you. The way I solve this: use Source and %setup -q in your spec file:

    Source:         %{name}-%{version}.tgz
    
    %prep
    %setup -q
    

    now you can use git to create this tgz file for you:

    git archive --format=tgz --prefix=gitproject-1.2.3-1 <hash or tag> > /home/user/rpmbuild/SOURCES/gitproject-1.2.3.tgz
    

    note that the prefix ang filename need to match the %name-%version.tgz from the Source tag in your spec file. You can change those naming conventions of course.

    PS: I have write a whole convenience script around this; but with these commands you should get most of the way.