Skip to content

Commit

Permalink
app-emulation/x48ng: new package, HP48 emulator
Browse files Browse the repository at this point in the history
Signed-off-by: Istvan Szenasi <[email protected]>
  • Loading branch information
szeist committed Aug 10, 2024
1 parent 81b6f5c commit ffc7513
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 0 deletions.
1 change: 1 addition & 0 deletions app-emulation/x48ng/Manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DIST x48ng-0_pre20240613.tar.gz 2636798 BLAKE2B f80ef1a89fbf6dcf157ec56f4be521fcb99655996bfc3b0b34de6885c82d47a037a8bbccce4992e8f5f5091b02561946428affc5856537be3f40483d9b73f909 SHA512 52cae6be049a0bb59ab5cf744cecdda9659c9ccb04ecf65a403a3a045bbafe95589d9dc75290849f1b8198032d8f4d7976275a3fcd9d99cd9c2766952eda7526
13 changes: 13 additions & 0 deletions app-emulation/x48ng/files/x48ng-0_pre20240613-cflags.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Keep original CFLAGS

--- a/Makefile
+++ b/Makefile
@@ -31,7 +31,7 @@ WITH_SDL ?= yes

OPTIM ?= 2

-CFLAGS = -std=c11 -g -O$(OPTIM) -I./src/ -D_GNU_SOURCE=1 -DVERSION_MAJOR=$(VERSION_MAJOR) -DVERSION_MINOR=$(VERSION_MINOR) -DPATCHLEVEL=$(PATCHLEVEL)
+CFLAGS += -std=c11 -g -O$(OPTIM) -I./src/ -D_GNU_SOURCE=1 -DVERSION_MAJOR=$(VERSION_MAJOR) -DVERSION_MINOR=$(VERSION_MINOR) -DPATCHLEVEL=$(PATCHLEVEL)

This comment has been minimized.

Copy link
@antecrescent

antecrescent Aug 10, 2024

Contributor

Please remove the -O$(OPTIM) flag. This compiler flag should be controlled by the user.

LIBS = -lm

### lua
15 changes: 15 additions & 0 deletions app-emulation/x48ng/files/x48ng-0_pre20240613-luajit.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Use luajit to avoid lua version specific pkg-config

--- a/Makefile
+++ b/Makefile
@@ -35,8 +35,8 @@ CFLAGS = -std=c11 -g -O$(OPTIM) -I./src/ -D_GNU_SOURCE=1 -DVERSION_MAJOR=$(VERSI
LIBS = -lm

### lua
-CFLAGS += $(shell pkg-config --cflags lua)
-LIBS += $(shell pkg-config --libs lua)
+CFLAGS += $(shell pkg-config --cflags luajit)
+LIBS += $(shell pkg-config --libs luajit)

### debugger
CFLAGS += $(shell pkg-config --cflags readline)
12 changes: 12 additions & 0 deletions app-emulation/x48ng/files/x48ng-0_pre20240613-manpages.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Don't zip man pages

--- a/Makefile
+++ b/Makefile
@@ -180,7 +180,6 @@ install: all get-roms dist/config.lua

install -m 755 -d -- $(DESTDIR)$(MANDIR)/man1
sed "s|@VERSION@|$(VERSION_MAJOR).$(VERSION_MINOR).$(PATCHLEVEL)|g" dist/x48ng.man.1 > $(DESTDIR)$(MANDIR)/man1/x48ng.1
- gzip -9 $(DESTDIR)$(MANDIR)/man1/x48ng.1

install -m 755 -d -- $(DESTDIR)$(DOCDIR)
cp -R AUTHORS LICENSE README* doc* romdump/ $(DESTDIR)$(DOCDIR)
19 changes: 19 additions & 0 deletions app-emulation/x48ng/files/x48ng-0_pre20240613-setupscript.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Replace the PREFIX placeholder to the /usr dir instead of the image dir

--- a/Makefile
+++ b/Makefile
@@ -175,7 +175,7 @@ install: all get-roms dist/config.lua
install -c -m 755 dist/checkrom $(DESTDIR)$(PREFIX)/share/x48ng/checkrom
install -c -m 644 dist/hplogo.png $(DESTDIR)$(PREFIX)/share/x48ng/hplogo.png
cp -R dist/ROMs/ $(DESTDIR)$(PREFIX)/share/x48ng/
- sed "s|@PREFIX@|$(PREFIX)|g" dist/setup-x48ng-home.sh > $(DESTDIR)$(PREFIX)/share/x48ng/setup-x48ng-home.sh
+ sed "s|@PREFIX@|/usr|g" dist/setup-x48ng-home.sh > $(DESTDIR)$(PREFIX)/share/x48ng/setup-x48ng-home.sh

This comment has been minimized.

Copy link
@antecrescent

antecrescent Aug 10, 2024

Contributor

This is not necessary when calling emake install with the correct args as listed below :)

chmod 755 $(DESTDIR)$(PREFIX)/share/x48ng/setup-x48ng-home.sh

install -m 755 -d -- $(DESTDIR)$(MANDIR)/man1
@@ -187,4 +187,4 @@ install: all get-roms dist/config.lua
install -c -m 644 dist/config.lua $(DESTDIR)$(DOCDIR)/config.lua

install -m 755 -d -- $(DESTDIR)$(PREFIX)/share/applications
- sed "s|@PREFIX@|$(PREFIX)|g" dist/x48ng.desktop > $(DESTDIR)$(PREFIX)/share/applications/x48ng.desktop
+ sed "s|@PREFIX@|/usr|g" dist/x48ng.desktop > $(DESTDIR)$(PREFIX)/share/applications/x48ng.desktop

This comment has been minimized.

Copy link
@antecrescent

antecrescent Aug 10, 2024

Contributor

Ditto.

27 changes: 27 additions & 0 deletions app-emulation/x48ng/metadata.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE pkgmetadata SYSTEM "https://www.gentoo.org/dtd/metadata.dtd">
<pkgmetadata>
<maintainer type="person">
<email>[email protected]</email>
</maintainer>
<longdescription>
This emulator is capable of providing a faithful replication of the
HP48. In order to do so, it requires a copy of the ROM software
from YOUR calculator. In order to avoid breaking copyright laws,
and upsetting HP, you MUST BE THE PROUD OWNER OF AN HP48 before
running this program. Of course you can run this program without a
copy of the ROM software in order to write trivial machine code
programs but you will not be able to access any of the calculator
functionality.

Instructions on how to download a copy of the ROM are provided
later in this document.
</longdescription>
<use>
<flag name="X">X11 frontend</flag>
<flag name="sdl">SDL fronted</flag>
</use>
<upstream>
<remote-id type="github">gwenhael-le-moine/x48ng</remote-id>
</upstream>
</pkgmetadata>
64 changes: 64 additions & 0 deletions app-emulation/x48ng/x48ng-0_pre20240613.ebuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright 1999-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

DESCRIPTION="HP48 emulator"

HOMEPAGE="https://github.com/gwenhael-le-moine/x48ng"

GIT_COMMIT="c72a393498887f8628006d8a64fad31d23abd0d5"
SRC_URI="https://github.com/gwenhael-le-moine/x48ng/archive/${GIT_COMMIT}.tar.gz -> ${P}.tar.gz"
S="${WORKDIR}/${PN}-${GIT_COMMIT}"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64"
IUSE="X sdl"

RDEPEND="sys-libs/ncurses
dev-lang/luajit
sys-libs/readline
X? (
x11-libs/libX11
x11-libs/libXext
)
sdl? (
=media-libs/libsdl-1.2*
media-libs/sdl-gfx
)
"
DEPEND="${RDEPEND}"

This comment has been minimized.

Copy link
@antecrescent

antecrescent Aug 10, 2024

Contributor

Missing BDEPEND="virtual/pkgconfig"

PATCHES=(
"${FILESDIR}/x48ng-${PVR}-cflags.patch"
"${FILESDIR}/x48ng-${PVR}-luajit.patch"
"${FILESDIR}/x48ng-${PVR}-setupscript.patch"
"${FILESDIR}/x48ng-${PVR}-manpages.patch"
)

src_compile() {
local conf

if use X; then
conf+=" WITH_X11=yes"
else
conf+=" WITH_X11=no"
fi

if use sdl; then
conf+=" WITH_SDL=yes"
else
conf+=" WITH_SDL=no"
fi

emake ${conf}

This comment has been minimized.

Copy link
@antecrescent

antecrescent Aug 10, 2024

Contributor

You need to inherit inherit the toolchain-funcs eclass to override CC ?= gcc with the target-prefixed version. You can use tc-export CC or emake CC="$(tc-getCC)" ${conf}.
Usage of pkg-config also needs to be replaced with $(tc-getPKG_CONFIG).
This is necessary to not get in trouble when cross-compiling this package or when /usr/bin/gcc is unavailable:
https://wiki.gentoo.org/wiki/Project:Toolchain/use_native_symlinks

You also need to add export CFLAGS LDFLAGS for make to pick them up reliably, since the PMS doesn't guarantee that these flags are actually exported to the environment.

}

src_install() {
emake install PREFIX="${D}/usr" MANDIR="${D}/usr/share/man" DOCDIR="${D}/usr/share/doc/${P}"

This comment has been minimized.

Copy link
@antecrescent

antecrescent Aug 10, 2024

Contributor

This should be emake install DESTDIR="${D}" PREFIX="${EPREFIX}/usr" MANDIR="${EPREFIX}/usr/share/man" DOCDIR="${EPREFIX}/usr/share/doc/${PF}".

You can find an overview of Gentoo's expected directory structure at https://devmanual.gentoo.org/ebuild-writing/functions/src_configure/configuring/index.html#econf-options.

This comment has been minimized.

Copy link
@antecrescent

antecrescent Aug 11, 2024

Contributor

The package shouldn't install LICENSE. We use our ebuild variable for that.

}

This comment has been minimized.

Copy link
@antecrescent

antecrescent Aug 10, 2024

Contributor

To support prefixed Gentoo installations, you need to prefix absolute paths in "${ED}/usr/share/x48ng/setup-x48ng-home.sh with "${EPREFIX}" after installation. To do that, you could use hprefixify from the prefix eclass.


pkg_postinst() {
elog "Run /usr/share/x48ng/setup-x48ng-home.sh to setup your ~/.x48ng/. It sets up a HP 48GX with a 128KB card in port 1 and a 4MB card in port 2"

This comment has been minimized.

Copy link
@antecrescent

antecrescent Aug 10, 2024

Contributor

Maybe add a warning that the script rm -rf's the user's config dir ~/.x48ng/ when it exists...

https://github.com/gwenhael-le-moine/x48ng/blob/c72a393498887f8628006d8a64fad31d23abd0d5/dist/setup-x48ng-home.sh#L7

You could also use the greadme eclass to only show this message on first install.

}

2 comments on commit ffc7513

@antecrescent
Copy link
Contributor

@antecrescent antecrescent commented on ffc7513 Aug 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to patch the Makefile to support user LDFLAGS when linking the binaries.

@antecrescent
Copy link
Contributor

@antecrescent antecrescent commented on ffc7513 Aug 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Patch Makefile NOT to auto-download the ROMs. These must be manually downloaded by the user.

Edit: I just realized that upstream contains these ROMs already. I'm removing this package due to their questionable legal status until upstream remedies the situation.

Please sign in to comment.