diff options
author | eug-vs <eugene@eug-vs.xyz> | 2022-04-24 20:18:54 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2022-04-24 20:29:51 +0300 |
commit | 6efbc747e3b8b0b7524a7584b84740230c6c58f3 (patch) | |
tree | 25994c4807c8433f0a4e8f73a23942051ff36f83 | |
parent | 9a38fed5f259db004e93746e432cd8cb7885e1ea (diff) | |
download | eug-vs-xyz-6efbc747e3b8b0b7524a7584b84740230c6c58f3.tar.gz |
blog: creating gentoo ebuilds is easy as fuck
-rw-r--r-- | config.mk | 4 | ||||
-rw-r--r-- | src/blog/2022-04-24.md | 82 | ||||
-rw-r--r-- | src/blog/index.md | 1 |
3 files changed, 87 insertions, 0 deletions
diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..a4039ea --- /dev/null +++ b/config.mk @@ -0,0 +1,4 @@ +WEBSITE_TITLE=Eugene's Space +WEBSITE_URL=https://eug-vs.xyz +CONVERT=pandoc --from=gfm+emoji --to=html --section-divs --shift-heading-level-by=1 +BLOG_PREVIEW_MARKER=Recent blog posts diff --git a/src/blog/2022-04-24.md b/src/blog/2022-04-24.md new file mode 100644 index 0000000..b0d6d2f --- /dev/null +++ b/src/blog/2022-04-24.md @@ -0,0 +1,82 @@ +# Creating Gentoo :gentoo: ebuilds is easy as fuck! +Ah shit... Here we go again manually downloading binary version of `libspotify` from [archive on GitHub](https://github.com/mopidy/libspotify-archive/). But wait :thinking:, don't we have package manager already? Let's fix that right now! + +# What is ebuild anyway? +According to [Gentoo wiki](https://wiki.gentoo.org/wiki/Ebuild): +> An ebuild file is a text file, usually stored in a repository, which identifies a specific software package and tells the Gentoo package manager how to handle it. Ebuilds use a bash-like syntax style and are standardized through the Package Manager Specification, by adhering to a specific EAPI version. + +Basically it's just a file which contains a set of instructions to [Portage](https://wiki.gentoo.org/wiki/Portage) on how to work with your package. If you are trying to install a non-standard package (e.g not from the official Gentoo tree), chances are there's already an ebuild for it in someone's overlay (= ebuild repository) on the internet. + +# Creating your own overlay +There are multiple reasons for creating your own overlay with custom ebuilds, here are some of them: + - You want Portage to manage installation of your custom packages + - You want to share package across your machines + - You want to distribute a package for your own program + +The process of creating an overlay is as easy as initializing a git repo and is [well documented on the wiki](https://wiki.gentoo.org/wiki/Basic_guide_to_write_Gentoo_Ebuilds). +Here's an example ebuild for [raylib](https://github.com/raysan5/raylib), which is *a simple and easy-to-use library to enjoy videogames programming*, that I'm using for my [Carcassonne game engine](https://git.eug-vs.xyz/carcassonne/carcassonne-engine-c/): +```bash +DESCRIPTION="simple and easy-to-use library to enjoy videogames programming" + +HOMEPAGE="http://www.raylib.com/" + +SRC_URI="https://github.com/raysan5/raylib/archive/refs/tags/4.0.0.tar.gz" + +S="${WORKDIR}/${P}/src" + +LICENSE="zlib" + +SLOT="0" + +KEYWORDS="~amd64" + +src_compile() { + emake PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=SHARED +} + +src_install() { + emake install RAYLIB_LIBTYPE=SHARED RAYLIB_INSTALL_PATH=${D}/usr/lib64 RAYLIB_H_INSTALL_PATH=${D}/usr/include +} +``` + +I'm often switching machines when developing my program, so I want to make sure that all dependencies are easily installable. Since I've recently [switched my last workstation to Gentoo](./2022-04-17.md), sharing packages can't be easier for me! As you can see, I'm just passing a link to a release tarball, specifying stuff like license and keywords and some metadata. All magic is of course happening inside the functions, which are as easy as calling `make install` with some environmental overrides. There's also a default implementation for these functions, and in many cases you don't even need to override them. Now I can install my package as usual `emerge -av media-libs/raylib`, and Portage will do the job. Everything's as it should be - a *package manager* is *managing a package*. + +Another example would be `libspotify`, which is a *proprietary program* that enables other programs to use Spotify API: + +```bash +EAPI=8 + +HOMEPAGE="https://github.com/mopidy/libspotify-archive" + +SRC_URI="https://github.com/mopidy/libspotify-archive/raw/master/${P}-Linux-x86_64-release.tar.gz" + +S="${WORKDIR}/${P}-Linux-x86_64-release" + +SLOT="0" + +KEYWORDS="amd64" + +PATCHES=( + "${FILESDIR}/destdir.patch" +) + +src_compile() { + true +} + +src_install() { + emake install DESTDIR=${D}/usr LIB=lib64 +} + +src_uninstall() { + emake install DESTDIR=${D}/usr LIB=lib64 +} +``` + +It's a bit trickier: we don't need to compile it, so we explicitly say that we are doing nothing in `src_compile` function. We also [apply a patch](./2022-04-18.md) so that we can more precisely specify destination directory. It's also important to match the keywords - since this binary is precompiled for `amd64` architecture I specify the corresponding keyword and install it under `/usr/lib64`. Now I can stream my Spotify playlists from my `mopidy` server! + +These examples are not perfect, and they are not trying to be! I've created them for personal use, but they can give you an idea about the whole process. But you can of course get them from [my overlay](https://git.eug-vs.xyz/eug-vs/ebuild-repository/). There's also a package for [openring](https://git.sr.ht/~sircmpwn/openring) and my own build of `dwmblocks`. + +# Footnotes +If you are planning to be maintainer of a public overlay, you should of course pay more attention to the ebuild writing guidelines, perform some quality assurance, probably create some patches, and test multiple versions. + diff --git a/src/blog/index.md b/src/blog/index.md index d9c72fe..b4e6c32 100644 --- a/src/blog/index.md +++ b/src/blog/index.md @@ -4,6 +4,7 @@ ### April +- [Creating Gentoo :gentoo: ebuilds is easy as fuck!](2022-04-24.md) - [Patching Gentoo :gentoo: packages in the wild](2022-04-18.md) - [Running Gentoo :gentoo: on multiple workstations](2022-04-17.md) - [DWM - useless gaps are useless!](2022-04-02.md) |