You are not logged in.

#1 2015-12-27 17:36:08

needs
Member
Registered: 2013-05-29
Posts: 4

[SOLVED] Build package with sources in the current directory

Hi,

The title pretty much say everything.  Let's say I have cloned a git repo with a PKGBUILD at the root of the repo.  Let's say for the sake of the example that we use make to compile and make install to install.  I am in the cloned repo and I want to use the PKGBUILD to build a package.  Is there a proper way to handle this case?

I've tried the following PKGBUILD, but I cannot get $srcdir to point to the current directory instead of ./src/.  I could use something like cd $srcdir/.. but it seems like a hack.

pkgname=my-program
pkgver=$(git describe --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g')
pkgrel=1
arch=('i686' 'x86_64')
license=("GPL3")
source=()

build() {
	cd "$srcdir"
	make
}

package() {
	make prefix="$pkgdir/" install
}

I know I can put a git repo in the source variable and use the function pkgver() to "properly" set the version, but I will then clone the repo again, rather than use the already cloned repo.

Last edited by needs (2015-12-27 22:21:04)

Offline

#2 2015-12-27 19:03:11

pypi
Wiki Maintainer
Registered: 2014-04-22
Posts: 250

Re: [SOLVED] Build package with sources in the current directory

Why not utilize symbolic links to 'pre-install' the source, or copy the PKGBUILD to a separate location and move the git repo into the makepkg source cache?
Or; what's wrong with cloning? You could point the PKGBUILD at your local repo instead of remote?

$srcdir/..

is not defined to be the original package dir - for instance, I normally build packages in /tmp/makepkg, which would not work in this example.

Offline

#3 2015-12-27 19:46:56

needs
Member
Registered: 2013-05-29
Posts: 4

Re: [SOLVED] Build package with sources in the current directory

pypi wrote:

Why not utilize symbolic links to 'pre-install' the source

If I understand, it means linking the cloned repo into the directory where the source should have been extracted?  Like /tmp/makepkg/my-program/src if I use makepkg -e BUILDDIR=/tmp/makepkg?  I've looked into the documentation on how to achieve this but I didn't get it.  Setting the source variable to something like:

source=(".")

doesn't work.

pypi wrote:

or copy the PKGBUILD to a separate location and move the git repo into the makepkg source cache?

I would like to only have to type more or less makepkg at the root of my repo and get the package ready to be installed.

pypi wrote:

You could point the PKGBUILD at your local repo instead of remote?

That's what I'm trying to achieve, but I couldn't find a way that doesn't require an absolute path.  Or am I missing something?

Offline

#4 2015-12-27 22:17:25

needs
Member
Registered: 2013-05-29
Posts: 4

Re: [SOLVED] Build package with sources in the current directory

Got it!  $startdir was the key!  As pypi suggested I just had to make a symbolic link in the directory where the source had to be extracted.

pkgname=my-program
pkgver=$(git describe --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g')
pkgrel=1
arch=('i686' 'x86_64')
source=()

prepare() {
	ln -snf "$startdir" "$srcdir/$pkgname"
}

build() {
	cd "$pkgname"
	make
}

package() {
	cd "$pkgname"
	make DESTDIR="$pkgdir" install
}

It works with makepkg BUILDDIR=/tmp/makepkg

Last edited by needs (2015-12-27 22:20:24)

Offline

#5 2015-12-27 22:28:11

Scimmia
Fellow
Registered: 2012-09-01
Posts: 11,559

Re: [SOLVED] Build package with sources in the current directory

So many things wrong with that, I don't know where to start.

Offline

#6 2015-12-28 00:53:41

needs
Member
Registered: 2013-05-29
Posts: 4

Re: [SOLVED] Build package with sources in the current directory

This is not intented to be uploaded in AUR, nor in any repository.  It is just for my project and provide an easy way of installing the program on your archlinux from the git repo.  It is a substitute to the classic sudo make install for those who run on archlinux.  I'm not going to maintain a separate git repo with only a PKGBUILD in it.

Offline

#7 2015-12-28 06:28:16

pypi
Wiki Maintainer
Registered: 2014-04-22
Posts: 250

Re: [SOLVED] Build package with sources in the current directory

Hmm... I'm with Scimmia; I believe that avoiding $startdir is best practice. As such, I'm not sure whether or not you can achieve what you wanted.

You understood what I meant by "pre-install". As makepkg would be run with '-e', the $source variable could point at anything. However, that is not what you wanted, as it would involve user effort - the symlinking would not be automatic.

Offline

#8 2016-10-26 10:59:58

Hi-Angel
Member
Registered: 2016-07-16
Posts: 43

Re: [SOLVED] Build package with sources in the current directory

Okay, it's kinda FAQ, and I tired of figuring out the details every time I'm appearing here, so here's a sum-up for getting it to work:

1. makepkg executes build() (and some other functions) in $srcdir which is not your current directory. So, you just have to enter the directory you want before build() executes (in general before packaging functions), like cd $startdir. I.e. OPs code have to be:


pkgname=my-program
pkgver=$(git describe --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g')
pkgrel=1
arch=('i686' 'x86_64')
source=()

build() {
	cd "$startdir" # here you go
	make
}

package() {
	make DESTDIR="$pkgdir" install
}

2. If the reader modifies someone else's PKGBUILD (e.g. for a debug build, or to not recompile every object file of a big project), make sure: α) $srcdir is replaced everywhere with $startdir, β) to remove everything that previously referred the source code, like urls, md5, etc.

Offline

#9 2016-10-26 11:52:24

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,860
Website

Re: [SOLVED] Build package with sources in the current directory

Thanks for sharing, Hi-Angel, however, this is an old thread, and marked as solved, so I'm going to go ahead and close it now.

Closing.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

Board footer

Powered by FluxBB