§2023-09-22

This is a tutorial of writing ebuild script to install hello.c in gentoo.

#include <stdio.h>
int main(void)
{
   printf("Hello World!\n");
   return 0;
}

Deployments of Gentoo Linux should already have eselect installed, as the app-admin/eselect package is part of the system set.

¶1. install [emerge -a app-eselect/eselect-repository](https://wiki.gentoo.org/wiki/Eselect/Repository)

eselect-repository is an eselect module for configuring ebuild repositories for Portage. Ebuild repository configuration files are stored in /etc/portage/repos.conf.

¶2. create local_depository eselect repository create local

(chroot) hc4Gentoo / # eselect repository create local
--2023-09-22 04:49:54--  https://qa-reports.gentoo.org/output/repos/repositories.xml
Resolving qa-reports.gentoo.org... 199.232.45.91, 2a04:4e42:48::347
Connecting to qa-reports.gentoo.org|199.232.45.91|:443... connected.
HTTP request sent, awaiting response... 304 Not Modified
File ‘/root/.cache/eselect-repo/repositories.xml’ not modified on server. Omitting download.

Adding local to /etc/portage/repos.conf/eselect-repo.conf ...
Repository local created and added

(chroot) hc4Gentoo / # cat /etc/portage/repos.conf/eselect-repo.conf 
# created by eselect-repo

[example_repository]
location = /var/db/repos/example_repository


[local]
location = /var/db/repos/local

(chroot) hc4Gentoo / # ls -l /var/db/repos/
total 12
drwxr-xr-x   5 root    root    4096 Sep 22 02:03 example_repository
drwxr-xr-x 174 portage portage 4096 Sep 21 11:29 gentoo
drwxr-xr-x   4 root    root    4096 Sep 22 05:00 local

(chroot) hc4Gentoo / # ls -l /var/db/repos/local/
total 8
drwxr-xr-x 2 root root 4096 Sep 22 05:00 metadata
drwxr-xr-x 2 root root 4096 Sep 22 05:00 profiles

(chroot) hc4Gentoo / # cat /var/db/repos/local/metadata/layout.conf 
masters = gentoo
thin-manifests = true
sign-manifests = false

(chroot) hc4Gentoo / # cat /var/db/repos/local/profiles/repo_name 
local

¶directory structures,

(chroot) hc4Gentoo / # tree /var/db/repos/example_repository
/var/db/repos/local
├── dev-util
│   └── hello-world
│       ├── files
│       │   └── hello.c
│       └── hello-world-1.0.ebuild
├── metadata
│   └── layout.conf
└── profiles
    └── repo_name

6 directories, 4 files
EAPI=7

DESCRIPTION="A simple Hello World program"
HOMEPAGE=""
# SRC_URI="file:///var/db/repos/example_repository/dev-util/hello-world/files/hello.c"

LICENSE="MIT"

SLOT="0"
KEYWORDS="~aarch64"
IUSE=""

MY_SRC="${FILESDIR}/hello.c"

src_unpack() {
    # Create the source directory
    mkdir -p "${S}"
    cp "${MY_SRC}" "${S}/hello.c"
}

src_compile() {
    emake hello
}

src_install() {
    # Install the binary manually
    dobin "${S}/hello"
}
#include <stdio.h>
int main(void)
{
   printf("Hello World!\n");
   return 0;
}