Skip to content

Commit 51ad3c8

Browse files
author
Chris Warren-Smith
committed
SDL: updates for flatpak build
1 parent e014a1f commit 51ad3c8

15 files changed

Lines changed: 320 additions & 123 deletions

File tree

Makefile.am

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,25 @@ appImage:
7373
# sudo apt install flatpak-builder
7474
# https://docs.flathub.org/docs/for-app-authors/submission
7575
#
76-
77-
flatpak-build-all:
78-
flatpak-builder --force-clean build-dir io.github.smallbasic.json
76+
# inspect build-dir/files (or /app from flatpack-shell) for additional "cleanup" items
77+
#
7978

8079
flatpak-build:
81-
flatpak-builder --build-only --force-clean --disable-download --disable-updates build-dir io.github.smallbasic.json && \
82-
flatpak-builder --run build-dir io.github.smallbasic.json sbasicg
83-
84-
flatpak-install:
85-
flatpak-builder --user --install --force-clean build-dir io.github.smallbasic.json
80+
flatpak-builder --force-clean --ccache build-dir io.github.smallbasic.json
8681

8782
flatpak-run:
83+
make -s -j$(nproc) && \
84+
flatpak-builder --user --install --force-clean --ccache --disable-download build-dir io.github.smallbasic.json && \
8885
flatpak run io.github.smallbasic
8986

87+
flatpak-debug:
88+
make -s -j$(nproc) && \
89+
flatpak-builder --build-only --force-clean --ccache --disable-download --disable-updates build-dir io.github.smallbasic.json && \
90+
flatpak-builder --run build-dir io.github.smallbasic.json gdb sbasicg
91+
92+
flatpak-shell:
93+
flatpak-builder --build-shell=sbasicg build-dir io.github.smallbasic.json
94+
9095
EXTRA_DIST = \
9196
documentation/build_kwp.cpp \
9297
documentation/sbasic_ref.csv \

configure.ac

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,15 @@ function buildSDL() {
187187
AC_MSG_ERROR([xxd command not installed: configure failed.])
188188
fi
189189

190+
AC_ARG_WITH(flatpak,
191+
[ --with-flatpak Build the flatpak version default=no],
192+
[with_flatpak=$withval],
193+
[with_flatpak=no])
194+
if test "$with_flatpak" = "yes" || test "$with_flatpak" = "full"
195+
then
196+
AC_DEFINE(_FLATPAK, 1, [flatpak build enabled])
197+
fi
198+
190199
case "${host_os}" in
191200
*mingw* | cygwin*)
192201
dnl avoid using MSCRT versions of printf for long double

io.github.smallbasic.json

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{
2+
"app-id": "io.github.smallbasic",
3+
"runtime": "org.freedesktop.Platform",
4+
"runtime-version": "25.08",
5+
"sdk": "org.freedesktop.Sdk",
6+
"command": "sbasicg",
7+
"build-options": {
8+
"env": {
9+
"MAKEFLAGS": "-j$(nproc) -s"
10+
}
11+
},
12+
"finish-args": [
13+
"--socket=wayland",
14+
"--socket=x11",
15+
"--socket=pulseaudio",
16+
"--device=dri",
17+
"--share=ipc",
18+
"--talk-name=org.freedesktop.portal.Desktop",
19+
"--env=SBASICPATH=/app/lib/smallbasic/plugins"
20+
],
21+
"cleanup": [
22+
"/include",
23+
"/lib/pkgconfig",
24+
"/lib/cmake",
25+
"/lib/debug"
26+
/*"/bin/xxd"*/
27+
],
28+
"modules": [
29+
{
30+
"name": "smallbasic-plugins",
31+
"buildsystem": "simple",
32+
"build-commands": [
33+
"./autogen.sh",
34+
"./configure --prefix=/app",
35+
"make -s",
36+
"mkdir -p ${FLATPAK_DEST}/lib/smallbasic/plugins",
37+
"find . -name '*.so' -exec install -Dm755 {} ${FLATPAK_DEST}/lib/smallbasic/plugins/ \\;"
38+
],
39+
"sources": [
40+
{
41+
"type": "git",
42+
"url": "https://github.com/smallbasic/smallbasic.plugins.git",
43+
"commit": "12_32"
44+
}
45+
]
46+
}, {
47+
"name": "xxd",
48+
"buildsystem": "simple",
49+
"build-commands": [
50+
"cd src/xxd && make CC=gcc CFLAGS='-O2'",
51+
"install -Dm755 src/xxd/xxd /app/bin/xxd"
52+
],
53+
"sources": [
54+
{
55+
"type": "git",
56+
"url": "https://github.com/vim/vim.git",
57+
"tag": "v9.1.0"
58+
}
59+
]
60+
}, {
61+
"name": "SDL3",
62+
"buildsystem": "cmake-ninja",
63+
"config-opts": [
64+
"-DCMAKE_BUILD_TYPE=Release"
65+
],
66+
"sources": [
67+
{
68+
"type": "git",
69+
"url": "https://github.com/libsdl-org/SDL.git",
70+
"tag": "release-3.2.26"
71+
}
72+
]
73+
}, {
74+
"name": "sbasic",
75+
"buildsystem": "autotools",
76+
"config-opts": [
77+
"--prefix=/app"
78+
],
79+
"sources": [
80+
{
81+
"type": "dir",
82+
"path": "."
83+
}
84+
],
85+
"build-commands": [
86+
"make install -s -j$(nproc)"
87+
]
88+
}, {
89+
"name": "sbasicg",
90+
"buildsystem": "autotools",
91+
"config-opts": [
92+
"--prefix=/app",
93+
"--enable-sdl",
94+
"--with-flatpak"
95+
],
96+
"sources": [
97+
{
98+
"type": "dir",
99+
"path": "."
100+
}
101+
]
102+
}
103+
]
104+
}

src/common/brun.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,7 @@ int sbasic_exec(const char *file) {
16431643
opt_show_page = 0;
16441644

16451645
// setup global values
1646+
gsb_err_mod_perm = 0;
16461647
gsb_last_line = gsb_last_error = 0;
16471648
strlcpy(gsb_last_file, file, sizeof(gsb_last_file));
16481649
strcpy(gsb_last_errmsg, "");
@@ -1656,6 +1657,8 @@ int sbasic_exec(const char *file) {
16561657
} else if (!success) { // there was some errors; do not continue
16571658
exec_rq = 0;
16581659
gsb_last_error = 1;
1660+
} else if (gsb_err_mod_perm) {
1661+
exec_rq = 0; // a module is not permitted to be run
16591662
}
16601663

16611664
if (exec_rq) { // we will run it

src/common/plugins.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ typedef int (*sblib_exec_fn)(int, int, slib_par_t *, var_t *);
4040
typedef int (*sblib_getname_fn) (int, char *);
4141
typedef int (*sblib_count_fn) (void);
4242
typedef int (*sblib_init_fn) (const char *);
43+
typedef int (*sblib_has_window_ui_fn) (void);
4344
typedef int (*sblib_free_fn) (int, int);
4445
typedef void (*sblib_close_fn) (void);
4546

@@ -372,6 +373,13 @@ static void slib_import_routines(slib_t *lib, int comp) {
372373
}
373374
}
374375

376+
#if !defined(_CONSOLE)
377+
sblib_has_window_ui_fn has_window_ui = slib_getoptptr(lib, "sblib_has_window_ui");
378+
if (has_window_ui && has_window_ui()) {
379+
gsb_err_mod_perm = 1;
380+
}
381+
#endif
382+
375383
if (!total) {
376384
log_printf("LIB: module '%s' has no exports\n", lib->_name);
377385
}

src/common/smbas.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ EXTERN int gsb_last_error; /**< error code, 0 = no error, < 0 = local messages
129129
EXTERN char gsb_last_file[OS_PATHNAME_SIZE + 1]; /**< source code file-name of the last error */
130130
EXTERN char gsb_bas_dir[OS_PATHNAME_SIZE + 1]; /**< source code home dir */
131131
EXTERN char gsb_last_errmsg[SB_ERRMSG_SIZE + 1]; /**< last error message */
132+
EXTERN byte gsb_err_mod_perm; /**< whether a module was not permitted to run */
132133

133134
#include "common/units.h"
134135
#include "common/tasks.h"

src/include/module.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ extern "C" {
2525
*/
2626
int sblib_init(const char *sourceFile);
2727

28+
/**
29+
* @ingroup modstd
30+
*
31+
* Returns whether the module is compatible with IDE builds
32+
*
33+
* @return non-zero on success
34+
*/
35+
int sblib_has_window_ui(void);
36+
2837
/**
2938
* @ingroup modstd
3039
*

src/platform/android/jni/runtime.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,13 +1013,15 @@ void Runtime::onResize(int width, int height, int imeState) {
10131013
}
10141014

10151015
void Runtime::onRunCompleted() {
1016-
const char *storage = getenv("EXTERNAL_DIR");
1017-
if (!storage) {
1018-
storage = getenv("INTERNAL_DIR");
1019-
}
1020-
if (storage) {
1021-
setenv("HOME_DIR", storage, 1);
1022-
chdir(storage);
1016+
if (!_mainBas) {
1017+
const char *storage = getenv("EXTERNAL_DIR");
1018+
if (!storage) {
1019+
storage = getenv("INTERNAL_DIR");
1020+
}
1021+
if (storage) {
1022+
setenv("HOME_DIR", storage, 1);
1023+
chdir(storage);
1024+
}
10231025
}
10241026
}
10251027

src/platform/sdl/editor.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,7 @@ void exportBuffer(const AnsiWidget *out, const char *text, const String &dest, c
183183

184184
bool externalExec(const AnsiWidget *out, const TextEditInput *editWidget, const String &loadPath) {
185185
bool result;
186-
if (editWidget->getTextLength() && !g_exportAddr.empty() && g_exportAddr.indexOf("sbasic", 0) != -1) {
187-
launch(g_exportAddr, loadPath);
188-
result = true;
189-
} else if (editWidget->getTextLength() && !g_exportAddr.empty() && !g_exportToken.empty()) {
186+
if (editWidget->getTextLength() && !g_exportAddr.empty() && !g_exportToken.empty()) {
190187
exportBuffer(out, editWidget->getText(), g_exportAddr, g_exportToken);
191188
result = true;
192189
} else {
@@ -203,6 +200,7 @@ void Runtime::editSource(String loadPath, bool restoreOnExit) {
203200
int charWidth = _output->getCharWidth();
204201
int charHeight = _output->getCharHeight();
205202
int prevScreenId = _output->selectScreen(FORM_SCREEN);
203+
206204
TextEditInput *editWidget;
207205
if (_editor != nullptr) {
208206
editWidget = _editor;
@@ -211,10 +209,12 @@ void Runtime::editSource(String loadPath, bool restoreOnExit) {
211209
} else {
212210
editWidget = new TextEditInput(_programSrc, charWidth, charHeight, 0, 0, w, h);
213211
}
212+
214213
auto *helpWidget = new TextEditHelpWidget(editWidget, charWidth, charHeight);
215214
TextEditInput *widget = editWidget;
216215
String recentFile;
217216
StatusMessage statusMessage(editWidget);
217+
218218
enum InputMode {
219219
kInit, kExportAddr, kExportToken, kCommand
220220
} inputMode = kInit;
@@ -267,6 +267,10 @@ void Runtime::editSource(String loadPath, bool restoreOnExit) {
267267
_output->setStatus(!gsb_last_errmsg[0] ? "Error" : gsb_last_errmsg);
268268
}
269269
}
270+
} else if (gsb_err_mod_perm) {
271+
_output->setStatus("Running ...");
272+
saveFile(editWidget, loadPath);
273+
launchConsole(loadPath);
270274
} else {
271275
statusMessage.update(editWidget, _output, true);
272276
}
@@ -329,7 +333,7 @@ void Runtime::editSource(String loadPath, bool restoreOnExit) {
329333
helpWidget->hide();
330334
helpWidget->cancelMode();
331335
statusMessage.setDirty(editWidget);
332-
Runtime::debugStop();
336+
debugStop();
333337
break;
334338
case SB_KEY_CTRL('s'):
335339
saveFile(editWidget, loadPath);
@@ -364,7 +368,7 @@ void Runtime::editSource(String loadPath, bool restoreOnExit) {
364368
if (editWidget->getTextLength()) {
365369
saveFile(editWidget, loadPath);
366370
saveRecentPosition(loadPath, editWidget->getCursorPos());
367-
_output->setStatus("Export to SmallBASIC. Enter <IP>:<Port> | <sbasic>");
371+
_output->setStatus("Export to SmallBASIC. Enter <IP>:<Port>");
368372
widget = helpWidget;
369373
helpWidget->createLineEdit(g_exportAddr);
370374
showHelpLineInput(helpWidget, 60);
@@ -524,16 +528,9 @@ void Runtime::editSource(String loadPath, bool restoreOnExit) {
524528
switch (inputMode) {
525529
case kExportAddr:
526530
g_exportAddr = helpWidget->getText();
527-
if (g_exportAddr.indexOf("sbasic", 0) == -1) {
528-
inputMode = kExportToken;
529-
helpWidget->createLineEdit(g_exportToken);
530-
_output->setStatus("Enter token. Esc=Close");
531-
} else {
532-
inputMode = kInit;
533-
widget = editWidget;
534-
helpWidget->hide();
535-
launch(g_exportAddr, loadPath);
536-
}
531+
inputMode = kExportToken;
532+
helpWidget->createLineEdit(g_exportToken);
533+
_output->setStatus("Enter token. Esc=Close");
537534
break;
538535
case kExportToken:
539536
g_exportToken = helpWidget->getText();

src/platform/sdl/io.github.smallbasic.json

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,19 @@
1111
},
1212
"finish-args": [
1313
"--socket=wayland",
14-
"--socket=fallback-x11",
1514
"--socket=pulseaudio",
1615
"--device=dri",
1716
"--share=ipc",
1817
"--talk-name=org.freedesktop.portal.Desktop",
1918
"--env=SBASICPATH=/app/lib/smallbasic/plugins"
2019
],
20+
"cleanup": [
21+
"/include",
22+
"/lib/pkgconfig",
23+
"/lib/cmake",
24+
"/lib/debug",
25+
"/bin/xxd"
26+
],
2127
"modules": [
2228
{
2329
"name": "smallbasic-plugins",
@@ -63,6 +69,21 @@
6369
"tag": "release-3.2.26"
6470
}
6571
]
72+
}, {
73+
"name": "sbasic",
74+
"buildsystem": "autotools",
75+
"config-opts": [
76+
"--prefix=/app"
77+
],
78+
"sources": [
79+
{
80+
"type": "dir",
81+
"path": "."
82+
}
83+
],
84+
"build-commands": [
85+
"make install -s -j$(nproc)"
86+
]
6687
}, {
6788
"name": "sbasicg",
6889
"buildsystem": "autotools",

0 commit comments

Comments
 (0)