From 07a2aaa9eeaddba86df76af24c70436541d91a9f Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Wed, 27 Sep 2023 16:26:27 +0200 Subject: [PATCH] reintroduce conditional front-ends at build, try to auto-detect them. --- Makefile | 44 ++++++++++++++++++++++++++++--------------- README.md | 12 ++++++++++++ dist/x48ng.man.1 | 4 +--- src/runtime_options.c | 41 +++++++++++++++++++++++----------------- src/runtime_options.h | 10 ++++++++-- src/ui.c | 4 ++++ src/ui.h | 4 ++++ 7 files changed, 82 insertions(+), 37 deletions(-) diff --git a/Makefile b/Makefile index bbbabf2..9a19fe2 100644 --- a/Makefile +++ b/Makefile @@ -8,24 +8,14 @@ MAKEFLAGS +=-j$(NUM_CORES) -l$(NUM_CORES) CC ?= gcc -GUI ?= sdl +WITH_X11 ?= yes +WITH_SDL ?= yes + OPTIM ?= 2 CFLAGS = -g -O$(OPTIM) -I./src/ -D_GNU_SOURCE=1 -DVERSION_MAJOR=$(VERSION_MAJOR) -DVERSION_MINOR=$(VERSION_MINOR) -DPATCHLEVEL=$(PATCHLEVEL) LIBS = -lm -### X11 UI -CFLAGS += $(shell pkg-config --cflags x11 xext) -D_GNU_SOURCE=1 -LIBS += $(shell pkg-config --libs x11 xext) - -### SDL UI -CFLAGS += $(shell pkg-config --cflags SDL_gfx sdl12_compat) -LIBS += $(shell pkg-config --libs SDL_gfx sdl12_compat) - -### Text UI -CFLAGS += $(shell pkg-config --cflags ncursesw -DNCURSES_WIDECHAR=1) -LIBS += $(shell pkg-config --libs ncursesw) - ### debugger CFLAGS += $(shell pkg-config --cflags readline) LIBS += $(shell pkg-config --libs readline) @@ -45,12 +35,36 @@ DOTOS = src/emu_serial.o \ src/debugger.o \ src/runtime_options.o \ src/romio.o \ - src/ui_x11.o \ - src/ui_sdl.o \ src/ui_text.o \ src/ui.o \ src/main.o +### X11 UI +ifeq ($(WITH_X11), yes) + X11CFLAGS = $(shell pkg-config --cflags x11 xext) -D_GNU_SOURCE=1 + X11LIBS = $(shell pkg-config --libs x11 xext) + ifneq ($(X11CFLAGS), "") + CFLAGS += $(X11CFLAGS) -DHAS_X11=1 + LIBS += $(X11LIBS) + DOTOS += src/ui_x11.o + endif +endif + +### SDL UI +ifeq ($(WITH_SDL), yes) +SDLCFLAGS = $(shell pkg-config --cflags SDL_gfx sdl12_compat) +SDLLIBS = $(shell pkg-config --libs SDL_gfx sdl12_compat) +ifneq ($(SDLCFLAGS), "") + CFLAGS += $(SDLCFLAGS) -DHAS_SDL=1 + LIBS += $(SDLLIBS) + DOTOS += src/ui_sdl.o +endif +endif + +### Text UI +CFLAGS += $(shell pkg-config --cflags ncursesw) -DNCURSES_WIDECHAR=1 +LIBS += $(shell pkg-config --libs ncursesw) + .PHONY: all clean clean-all pretty-code install all: dist/mkcard dist/checkrom dist/dump2rom dist/x48ng diff --git a/README.md b/README.md index 60e7e90..104fa38 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,14 @@ See https://github.com/gwenhael-le-moine/x48ng/issues ## Compilation +The `Makefile` will try to autodetect if necessary dependencies for x11 and sdl front-ends are met and enable/disable x11 and sdl front-ends accordingly. + +You can force disable x11 front-end by compiling with `make WITH_X11=no`. + +You can force disable sdl front-end by compiling with `make WITH_SDL=no`. + +Ncurses front-end is always built-in. + ### Dependencies (see .github/workflows/c-cpp.yml for debian packages names) - readline @@ -74,6 +82,10 @@ for x11 version: - x11 +for Ncurses: + +- ncursesw + ## Installation 1. Run `sudo make install PREFIX=/usr DOCDIR=/usr/doc/x48ng MANDIR=/usr/man DESTDIR=/tmp/package` filling in your own values for PREFIX, DOCDIR, MANDIR and DESTDIR. diff --git a/dist/x48ng.man.1 b/dist/x48ng.man.1 index 8e61cd0..c0493ba 100644 --- a/dist/x48ng.man.1 +++ b/dist/x48ng.man.1 @@ -49,7 +49,7 @@ x48ng \- scientific calculator and an HP 48 emulator .B x48ng [\--options ...] -where options include: +where options include (depending on compiled front-ends): .br \-h \-\-help what you are reading .br @@ -70,8 +70,6 @@ where options include: \-\-serial\-line= use as serial device default: /dev/ttyS0) .br \-V \-\-verbose be verbose (default: false) -.br - \-u \-\-front-end specify a front-end (available: x11, sdl, text; default: x11) .br \-\-x11 use X11 front-end (default: true) .br diff --git a/src/runtime_options.c b/src/runtime_options.c index f6ebee6..b3bb8fd 100644 --- a/src/runtime_options.c +++ b/src/runtime_options.c @@ -29,7 +29,13 @@ char* stateFileName = "hp48"; char* port1FileName = "port1"; char* port2FileName = "port2"; +#ifdef HAS_X11 int frontend_type = FRONTEND_X11; +#elif HAS_SDL +int frontend_type = FRONTEND_SDL; +#else +int frontend_type = FRONTEND_TEXT; +#endif /* sdl */ int show_ui_chrome = 1; @@ -158,8 +164,6 @@ int parse_args( int argc, char* argv[] ) { "serial-line", required_argument, NULL, 1015 }, - { "front-end", required_argument, NULL, 'u' }, - { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'v' }, @@ -173,10 +177,13 @@ int parse_args( int argc, char* argv[] ) { "no-debug", no_argument, &useDebugger, 0 }, +#ifdef HAS_SDL { "sdl", no_argument, &frontend_type, FRONTEND_SDL }, { "sdl-no-chrome", no_argument, &show_ui_chrome, 0 }, { "sdl-fullscreen", no_argument, &show_ui_fullscreen, 1 }, +#endif +#ifdef HAS_X11 { "x11", no_argument, &frontend_type, FRONTEND_X11 }, { "x11-netbook", no_argument, &netbook, 1 }, { "x11-visual", required_argument, NULL, 8110 }, @@ -184,6 +191,7 @@ int parse_args( int argc, char* argv[] ) { "x11-medium-font", required_argument, NULL, 8112 }, { "x11-large-font", required_argument, NULL, 8113 }, { "x11-connection-font", required_argument, NULL, 8114 }, +#endif { "tui", no_argument, &frontend_type, FRONTEND_TEXT}, @@ -212,11 +220,12 @@ int parse_args( int argc, char* argv[] ) "\t --serial-line=\t\tuse as serial device default: " "%s)\n" "\t-V --verbose\t\t\tbe verbose (default: false)\n" - "\t-u --front-end\t\t\tspecify a front-end (available: x11, sdl, " - "text; " - "default: x11)\n" +#ifdef HAS_X11 "\t --x11\t\tuse X11 front-end (default: true)\n" +#endif +#ifdef HAS_SDL "\t --sdl\t\tuse SDL front-end (default: false)\n" +#endif "\t --tui\t\tuse terminal front-end (default: false)\n" "\t-t --use-terminal\t\tactivate pseudo terminal interface (default: " "true)\n" @@ -225,11 +234,14 @@ int parse_args( int argc, char* argv[] ) "\t-i --initialize\t\t\tinitialize the content of \n" "\t-r --reset\t\t\tperform a reset on startup\n" "\t-T --throttle\t\t\ttry to emulate real speed (default: false)\n" +#ifdef HAS_SDL "\t --sdl-no-chrome\t\tonly display the LCD (default: " "false)\n" "\t --sdl-fullscreen\t\tmake the UI fullscreen " "(default: " "false)\n" +#endif +#ifdef HAS_X11 "\t --x11-netbook\t\tmake the UI horizontal (default: " "false)\n" "\t --x11-visual=\tuse visual (default: " @@ -244,6 +256,7 @@ int parse_args( int argc, char* argv[] ) "font (default: %s)\n" "\t --x11-connection-font=\tuse as " "connection font (default: %s)\n" +#endif "\t --mono\t\t\tmake the UI monochrome (default: " "false)\n" "\t --gray\t\t\tmake the UI grayscale (default: " @@ -281,6 +294,7 @@ int parse_args( int argc, char* argv[] ) case 1015: serialLine = optarg; break; +#ifdef HAS_X11 case 8110: x11_visual = optarg; break; @@ -296,18 +310,7 @@ int parse_args( int argc, char* argv[] ) case 8114: connFont = optarg; break; - case 'u': - if ( strcmp( optarg, "sdl" ) == 0 ) - frontend_type = FRONTEND_SDL; - else if ( strcmp( optarg, "text" ) == 0 ) - frontend_type = FRONTEND_TEXT; - else if ( strcmp( optarg, "x11" ) == 0 ) - frontend_type = FRONTEND_X11; - else { - fprintf( stderr, "Error: unknown frontend '%s'\n", optarg ); - exit( 1 ); - } - break; +#endif case 'V': verbose = 1; break; @@ -355,12 +358,16 @@ int parse_args( int argc, char* argv[] ) fprintf( stderr, "resetOnStartup = %i\n", resetOnStartup ); fprintf( stderr, "frontend_type = " ); switch ( frontend_type ) { +#ifdef HAS_X11 case FRONTEND_X11: fprintf( stderr, "x11\n" ); break; +#endif +#ifdef HAS_SDL case FRONTEND_SDL: fprintf( stderr, "sdl\n" ); break; +#endif case FRONTEND_TEXT: fprintf( stderr, "text\n" ); break; diff --git a/src/runtime_options.h b/src/runtime_options.h index fd31931..7dc1335 100644 --- a/src/runtime_options.h +++ b/src/runtime_options.h @@ -1,8 +1,14 @@ #ifndef _OPTIONS_H #define _OPTIONS_H 1 -#define FRONTEND_SDL 0 -#define FRONTEND_X11 1 +#ifdef HAS_SDL +# define FRONTEND_SDL 0 +#endif + +#ifdef HAS_X11 +# define FRONTEND_X11 1 +#endif + #define FRONTEND_TEXT 2 extern char* progname; diff --git a/src/ui.c b/src/ui.c index c09c10e..823ec31 100644 --- a/src/ui.c +++ b/src/ui.c @@ -152,14 +152,18 @@ void ( *init_ui )( int argc, char** argv ); void setup_frontend( void ) { switch ( frontend_type ) { +#ifdef HAS_X11 case FRONTEND_X11: default: init_ui = init_x11_ui; break; +#endif +#ifdef HAS_SDL case FRONTEND_SDL: init_ui = init_sdl_ui; break; +#endif case FRONTEND_TEXT: init_ui = init_text_ui; diff --git a/src/ui.h b/src/ui.h index 453468d..6b679de 100644 --- a/src/ui.h +++ b/src/ui.h @@ -26,9 +26,13 @@ extern letter_t small_font[ 128 ]; /*************/ /* functions */ /*************/ +#ifdef HAS_X11 extern void init_x11_ui( int argc, char** argv ); +#endif +#ifdef HAS_SDL extern void init_sdl_ui( int argc, char** argv ); +#endif extern void init_text_ui( int argc, char** argv );