diff --git a/Makefile b/Makefile index d205009..1f23c86 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,13 @@ VERSION_MAJOR = 1 VERSION_MINOR = 3 PATCHLEVEL = 2 +INSTALL_PREFIX = /usr/local +INSTALL_BINARY_DIR = "$(INSTALL_PREFIX)"/bin +INSTALL_DATA_DIR = "$(INSTALL_PREFIX)"/share/$(TARGET) +INSTALL_DOC_DIR = "$(INSTALL_PREFIX)"/doc/$(TARGET) +INSTALL_MENU_DIR = "$(INSTALL_PREFIX)"/share/applications +INSTALL_MAN_DIR = "$(INSTALL_PREFIX)/share/man/man1" + # DEBUG_CFLAGS = -g # -pg OPTIM ?= 2 @@ -216,13 +223,6 @@ else endif # Installation -INSTALL_PREFIX = /usr/local -INSTALL_BINARY_DIR = "$(INSTALL_PREFIX)"/bin -INSTALL_DATA_DIR = "$(INSTALL_PREFIX)"/share/$(TARGET) -INSTALL_DOC_DIR = "$(INSTALL_PREFIX)"/doc/$(TARGET) -INSTALL_MENU_DIR = "$(INSTALL_PREFIX)"/share/applications -INSTALL_MAN_DIR = "$(INSTALL_PREFIX)/share/man/man1" - dist/$(TARGET).desktop: dist/$(TARGET).desktop.in perl -p -e "s!TARGET!$(TARGET)!" < dist/$(TARGET).desktop.in >$@ diff --git a/dist/x49gpng.scd b/dist/x49gpng.scd index 876c32b..40195ab 100644 --- a/dist/x49gpng.scd +++ b/dist/x49gpng.scd @@ -51,7 +51,7 @@ Please consult HP's manual (for their official firmware) or the documentation of - *-h* *--help* print this message and exit - *--verbose* print out more information -- *--state*[=_filename_] alternate config file +- *--datadir*[=_absolute path_] alternate datadir (default: $XDG_CONFIG_HOME/x49gpng/) - *--50g* emulate an HP 50g (default) - *--49gp* emulate an HP 49g+ - *--newrpl-keyboard* label keyboard for newRPL diff --git a/src/x49gpng/flash.c b/src/x49gpng/flash.c index cd2304d..e6e1bca 100644 --- a/src/x49gpng/flash.c +++ b/src/x49gpng/flash.c @@ -10,6 +10,7 @@ #include "x49gp.h" #include "ui.h" +#include "options.h" #define FLASH_STATE_NORMAL 0 @@ -435,11 +436,11 @@ static int flash_load( x49gp_module_t* module, GKeyFile* key ) if ( flash->size > st.st_size ) { fprintf( stderr, "Flash too small, rebuilding\n" ); - x49gp->startup_reinit = X49GP_REINIT_FLASH_FULL; + opt.reinit = X49GP_REINIT_FLASH_FULL; } - if ( x49gp->startup_reinit >= X49GP_REINIT_FLASH ) { + if ( opt.reinit >= X49GP_REINIT_FLASH ) { - if ( x49gp->startup_reinit == X49GP_REINIT_FLASH_FULL ) + if ( opt.reinit == X49GP_REINIT_FLASH_FULL ) memset( phys_ram_base + flash->offset, 0xff, flash->size - st.st_size ); bootfd = x49gp_module_open_rodata( @@ -467,7 +468,7 @@ static int flash_load( x49gp_module_t* module, GKeyFile* key ) close( bootfd ); g_free( bootfile ); - if ( x49gp->startup_reinit == X49GP_REINIT_FLASH_FULL ) { + if ( opt.reinit == X49GP_REINIT_FLASH_FULL ) { /* The stock firmware expects special markers in certain spots across the flash. Without these, the user banks act up and are not usable, and PINIT apparently won't @@ -485,8 +486,8 @@ static int flash_load( x49gp_module_t* module, GKeyFile* key ) retry: filename = NULL; - if ( x49gp->firmware != NULL ) - filename = g_strdup( x49gp->firmware ); + if ( opt.firmware != NULL ) + filename = g_strdup( opt.firmware ); else gui_open_firmware( x49gp, &filename ); @@ -496,7 +497,7 @@ retry: fprintf( stderr, "%s: %s:%u: open %s: %s\n", module->name, __FUNCTION__, __LINE__, filename, strerror( errno ) ); /* Mark firmware as invalid if there is one */ memset( phys_ram_base + flash->offset + BOOT_SIZE, 0, 16 ); - if ( x49gp->firmware != NULL ) { + if ( opt.firmware != NULL ) { fprintf( stderr, "Warning: Could not " "open selected firmware, " "falling back to bootloader " @@ -514,7 +515,7 @@ retry: /* Mark firmware as invalid if there is one */ memset( phys_ram_base + flash->offset + BOOT_SIZE, 0, 16 ); - if ( x49gp->firmware != NULL ) { + if ( opt.firmware != NULL ) { fprintf( stderr, "Warning: " "Could not read " "selected firmware, " @@ -531,7 +532,7 @@ retry: } else if ( bytes_read < 16 || memcmp( phys_ram_base + flash->offset + BOOT_SIZE, "KINPOUPDATEIMAGE", 16 ) != 0 ) { /* Mark firmware as invalid */ memset( phys_ram_base + flash->offset + BOOT_SIZE, 0, 16 ); - if ( x49gp->firmware != NULL ) { + if ( opt.firmware != NULL ) { fprintf( stderr, "Warning: " "Firmware is invalid, " "falling back to " @@ -553,7 +554,7 @@ retry: /* Mark firmware as invalid if there is one */ memset( phys_ram_base + flash->offset + BOOT_SIZE, 0, 16 ); - if ( x49gp->firmware != NULL ) { + if ( opt.firmware != NULL ) { fprintf( stderr, "Warning: " "Could not read " "selected firmware, " diff --git a/src/x49gpng/main.c b/src/x49gpng/main.c index 6e6803d..29e10b0 100644 --- a/src/x49gpng/main.c +++ b/src/x49gpng/main.c @@ -285,11 +285,6 @@ int main( int argc, char** argv ) if ( x49gp_modules_init( x49gp ) ) exit( EXIT_FAILURE ); - x49gp->basename = g_path_get_dirname( opt.state_filename ); - x49gp->debug_port = opt.debug_port; - x49gp->startup_reinit = opt.reinit; - x49gp->firmware = opt.firmware; - int error = x49gp_modules_load( x49gp, opt.state_filename ); if ( error || opt.reinit >= X49GP_REINIT_REBOOT_ONLY ) { if ( error && error != -EAGAIN ) diff --git a/src/x49gpng/module.c b/src/x49gpng/module.c index 2f76232..c936c69 100644 --- a/src/x49gpng/module.c +++ b/src/x49gpng/module.c @@ -8,6 +8,7 @@ #include "list.h" #include "x49gp.h" +#include "options.h" int x49gp_modules_init( x49gp_t* x49gp ) { @@ -94,7 +95,7 @@ int x49gp_modules_load( x49gp_t* x49gp, const char* filename ) printf( "%s:%u:\n", __FUNCTION__, __LINE__ ); #endif - if ( g_mkdir_with_parents( x49gp->basename, 0755 ) ) { + if ( g_mkdir_with_parents( opt.datadir, 0755 ) ) { error = -errno; fprintf( stderr, "%s:%u: g_mkdir_with_parents: %s\n", __FUNCTION__, __LINE__, strerror( errno ) ); return error; @@ -213,7 +214,6 @@ int x49gp_module_unregister( x49gp_module_t* module ) int x49gp_module_get_filename( x49gp_module_t* module, GKeyFile* key, const char* name, char* reset, char** valuep, char** path ) { - x49gp_t* x49gp = module->x49gp; int error; error = x49gp_module_get_string( module, key, name, reset, valuep ); @@ -223,7 +223,7 @@ int x49gp_module_get_filename( x49gp_module_t* module, GKeyFile* key, const char return error; } - *path = g_build_filename( x49gp->basename, *valuep, NULL ); + *path = g_build_filename( opt.datadir, *valuep, NULL ); if ( NULL == path ) { fprintf( stderr, "%s: %s:%u: Out of memory\n", module->name, __FUNCTION__, __LINE__ ); g_free( *valuep ); @@ -374,6 +374,8 @@ int x49gp_module_open_rodata( x49gp_module_t* module, const char* name, char** p int error; *path = g_build_filename( x49gp->progpath, name, NULL ); + if ( opt.verbose ) + fprintf( stderr, "reading %s\n", *path ); if ( NULL == *path ) { fprintf( stderr, "%s: %s:%u: Out of memory\n", module->name, __FUNCTION__, __LINE__ ); return -ENOMEM; @@ -386,6 +388,8 @@ int x49gp_module_open_rodata( x49gp_module_t* module, const char* name, char** p g_free( *path ); *path = g_build_filename( X49GP_DATADIR, name, NULL ); + if ( opt.verbose ) + fprintf( stderr, "reading %s\n", *path ); if ( NULL == *path ) { fprintf( stderr, "%s: %s:%u: Out of memory\n", module->name, __FUNCTION__, __LINE__ ); return -ENOMEM; diff --git a/src/x49gpng/options.c b/src/x49gpng/options.c index 6490a17..d43987c 100644 --- a/src/x49gpng/options.c +++ b/src/x49gpng/options.c @@ -13,6 +13,7 @@ #include "gdbstub.h" struct options opt = { + .datadir = NULL, .config_lua_filename = NULL, .state_filename = NULL, .debug_port = 0, @@ -140,9 +141,7 @@ void config_init( char* progname, int argc, char* argv[] ) {"print-config", no_argument, &print_config_and_exit, true}, {"verbose", no_argument, &clopt_verbose, true}, - {"config", required_argument, NULL, 'c' }, - - {"state", required_argument, NULL, 1 }, + {"datadir", required_argument, NULL, 1 }, {"enable-debug", required_argument, NULL, 'D' }, {"debug", no_argument, NULL, 'd' }, @@ -173,17 +172,22 @@ void config_init( char* progname, int argc, char* argv[] ) "Valid options:\n" " -h --help print this message and exit\n" " --verbose print out more information\n" - " --state[=] alternate config file\n" + "\n" + " --datadir[=] alternate datadir (default: $XDG_CONFIG_HOME/%s/)\n" + "\n" " --50g emulate an HP 50g (default)\n" " --49gp emulate an HP 49g+\n" " --newrpl-keyboard label keyboard for newRPL\n" + "\n" " -n --name[=] set alternate UI name\n" " -t --font[=] set alternate UI font\n" " -s --font-size[=] scale text by X (default: 3)\n" " -S --display-scale[=] scale LCD by X (default: 2)\n" + "\n" " -D --enable-debug[=] enable the debugger interface\n" " (default port: %u)\n" " -d --debug use along -D to also start the debugger immediately\n" + "\n" " -f --reflash[=firmware] rebuild the flash using the supplied firmware\n" " (default: select one interactively)\n" " (implies -r for safety reasons)\n" @@ -191,11 +195,12 @@ void config_init( char* progname, int argc, char* argv[] ) " in the area beyond the firmware\n" " -r --reboot reboot on startup instead of continuing from the\n" " saved state in the state file\n\n" + "\n" "The state file is formatted as INI file and contains the settings for which persistence makes sense like CPU " "registers, etc.\n" "If the state file is omitted, ~/.config/%s/state is used.\n" "Please consult the manual for more details on state file settings.\n", - progname, VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL, progname, DEFAULT_GDBSTUB_PORT, progname ); + progname, VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL, progname, progname, DEFAULT_GDBSTUB_PORT, progname ); exit( EXIT_SUCCESS ); break; case 'r': @@ -203,7 +208,7 @@ void config_init( char* progname, int argc, char* argv[] ) opt.reinit = X49GP_REINIT_REBOOT_ONLY; break; case 1: - opt.state_filename = strdup( optarg ); + opt.datadir = strdup( optarg ); break; case 'D': do_enable_debugger = true; @@ -245,9 +250,14 @@ void config_init( char* progname, int argc, char* argv[] ) } } - const char* user_config_dir = g_get_user_config_dir(); + if ( opt.datadir == NULL ) { + const char* user_config_dir = g_get_user_config_dir(); + opt.datadir = g_build_filename( user_config_dir, progname, NULL ); + } - opt.config_lua_filename = g_build_filename( user_config_dir, progname, config_lua_filename, NULL ); + opt.config_lua_filename = g_build_filename( opt.datadir, progname, config_lua_filename, NULL ); + + opt.state_filename = g_build_filename( opt.datadir, "state", NULL ); /**********************/ /* 1. read config.lua */ @@ -316,8 +326,8 @@ void config_init( char* progname, int argc, char* argv[] ) if ( !haz_config_file ) { fprintf( stderr, "\nConfiguration file %s doesn't seem to exist or is invalid!\n", opt.config_lua_filename ); - fprintf( stderr, "You can solve this by running `mkdir -p %s/%s && %s --print-config >> %s`\n\n", user_config_dir, progname, - progname, opt.config_lua_filename ); + fprintf( stderr, "You can solve this by running `mkdir -p %s/ && %s --print-config >> %s`\n\n", opt.datadir, progname, + opt.config_lua_filename ); } if ( do_enable_debugger ) { @@ -337,7 +347,4 @@ void config_init( char* progname, int argc, char* argv[] ) if ( do_reflash_full ) opt.reinit = X49GP_REINIT_FLASH_FULL; } - - if ( opt.state_filename == NULL ) - opt.state_filename = g_build_filename( user_config_dir, progname, "state", NULL ); } diff --git a/src/x49gpng/options.h b/src/x49gpng/options.h index 68194b8..c1d0d55 100644 --- a/src/x49gpng/options.h +++ b/src/x49gpng/options.h @@ -1,6 +1,8 @@ #ifndef _CONFIG_H #define _CONFIG_H 1 +#include + #include "x49gp.h" #ifndef VERSION_MAJOR @@ -31,6 +33,8 @@ struct options { int font_size; char* config_lua_filename; bool verbose; + + char* datadir; }; extern struct options opt; diff --git a/src/x49gpng/ui.c b/src/x49gpng/ui.c index 1f0617c..2743a2f 100644 --- a/src/x49gpng/ui.c +++ b/src/x49gpng/ui.c @@ -826,8 +826,8 @@ static void do_start_gdb_server( GtkMenuItem* menuitem, gpointer user_data ) { x49gp_t* x49gp = user_data; - if ( x49gp->debug_port != 0 && !gdbserver_isactive() ) { - gdbserver_start( x49gp->debug_port ); + if ( opt.debug_port != 0 && !gdbserver_isactive() ) { + gdbserver_start( opt.debug_port ); gdb_handlesig( x49gp->env, 0 ); } } @@ -1541,7 +1541,7 @@ static int ui_load( x49gp_module_t* module, GKeyFile* keyfile ) g_signal_connect_swapped( G_OBJECT( menu_unmount ), "activate", G_CALLBACK( s3c2410_sdi_unmount ), x49gp ); ui->menu_unmount = menu_unmount; - if ( x49gp->debug_port != 0 ) { + if ( opt.debug_port != 0 ) { gtk_menu_shell_append( GTK_MENU_SHELL( ui->menu ), gtk_separator_menu_item_new() ); GtkWidget* menu_debug = gtk_menu_item_new_with_label( "Start debugger" ); diff --git a/src/x49gpng/x49gp.h b/src/x49gpng/x49gp.h index cb43ab5..a1e63d0 100644 --- a/src/x49gpng/x49gp.h +++ b/src/x49gpng/x49gp.h @@ -86,10 +86,6 @@ struct __x49gp_s__ { GKeyFile* state_filename; const char* progname; const char* progpath; - const char* basename; - int debug_port; - x49gp_reinit_t startup_reinit; - char* firmware; }; extern void x49gp_set_idle( x49gp_t*, x49gp_arm_idle_t idle );