summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorGravatar waker <wakeroid@gmail.com>2012-05-08 22:02:33 +0200
committerGravatar waker <wakeroid@gmail.com>2012-05-08 22:02:33 +0200
commit7393ba274256a37a8a36c61fcd1b375693d16f93 (patch)
treeaafb6d13991a14e0d59b7c5915daceac52c2cbee /main.c
parent20cb0c42823315cdb7467673aa9740fed9b1feef (diff)
added support for universal static binary builds, used in all official packages
Diffstat (limited to 'main.c')
-rw-r--r--main.c122
1 files changed, 74 insertions, 48 deletions
diff --git a/main.c b/main.c
index 77751595..2f01d1ee 100644
--- a/main.c
+++ b/main.c
@@ -671,15 +671,48 @@ restore_resume_state (void) {
int
main (int argc, char *argv[]) {
+ int portable = 0;
+#if STATICLINK
+ int staticlink = 1;
+#else
+ int staticlink = 0;
+#endif
#if PORTABLE
- strcpy (dbinstalldir, argv[0]);
- char *e = dbinstalldir + strlen (dbinstalldir);
- while (e >= dbinstalldir && *e != '/') {
- e--;
+ portable = 1;
+ if (!realpath (argv[0], dbinstalldir)) {
+ strcpy (dbinstalldir, argv[0]);
+ }
+ char *e = strrchr (dbinstalldir, '/');
+ if (e) {
+ *e = 0;
+ }
+ else {
+ fprintf (stderr, "couldn't determine install folder from path %s\n", argv[0]);
+ exit (-1);
}
- *e = 0;
#else
- strcpy (dbinstalldir, PREFIX);
+ if (!realpath (argv[0], dbinstalldir)) {
+ strcpy (dbinstalldir, argv[0]);
+ }
+ char *e = strrchr (dbinstalldir, '/');
+ if (e) {
+ *e = 0;
+ }
+ else {
+ fprintf (stderr, "couldn't determine install folder from path %s\n", argv[0]);
+ exit (-1);
+ }
+ struct stat st;
+ char checkpath[PATH_MAX];
+ snprintf (checkpath, sizeof (checkpath), "%s/.ddb_portable", dbinstalldir);
+ if (!stat (checkpath, &st)) {
+ if (S_ISREG (st.st_mode)) {
+ portable = 1;
+ }
+ }
+ if (!portable) {
+ strcpy (dbinstalldir, PREFIX);
+ }
#endif
#ifdef __linux__
@@ -689,26 +722,18 @@ main (int argc, char *argv[]) {
setlocale (LC_NUMERIC, "C");
#ifdef ENABLE_NLS
// fprintf (stderr, "enabling gettext support: package=" PACKAGE ", dir=" LOCALEDIR "...\n");
-#if PORTABLE
- char localedir[PATH_MAX];
- snprintf (localedir, sizeof (localedir), "%s/locale", dbinstalldir);
- bindtextdomain (PACKAGE, localedir);
-#else
- bindtextdomain (PACKAGE, LOCALEDIR);
-#endif
+ if (portable) {
+ char localedir[PATH_MAX];
+ snprintf (localedir, sizeof (localedir), "%s/locale", dbinstalldir);
+ bindtextdomain (PACKAGE, localedir);
+ }
+ else {
+ bindtextdomain (PACKAGE, LOCALEDIR);
+ }
bind_textdomain_codeset (PACKAGE, "UTF-8");
textdomain (PACKAGE);
#endif
- int staticlink = 0;
- int portable = 0;
-#if STATICLINK
- staticlink = 1;
-#endif
-#if PORTABLE
- portable = 1;
-#endif
-
fprintf (stderr, "starting deadbeef " VERSION "%s%s\n", staticlink ? " [static]" : "", portable ? " [portable]" : "");
srand (time (NULL));
#ifdef __linux__
@@ -750,34 +775,35 @@ main (int argc, char *argv[]) {
#endif
-#if PORTABLE
- if (snprintf (dbdocdir, sizeof (dbdocdir), "%s/doc", dbinstalldir) > sizeof (dbdocdir)) {
- fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir);
- return -1;
- }
- if (snprintf (dbplugindir, sizeof (dbplugindir), "%s/plugins", dbinstalldir) > sizeof (dbplugindir)) {
- fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir);
- return -1;
- }
- if (snprintf (dbpixmapdir, sizeof (dbpixmapdir), "%s/pixmaps", dbinstalldir) > sizeof (dbpixmapdir)) {
- fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir);
- return -1;
- }
- mkdir (dbplugindir, 0755);
-#else
- if (snprintf (dbdocdir, sizeof (dbdocdir), "%s", DOCDIR) > sizeof (dbdocdir)) {
- fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir);
- return -1;
- }
- if (snprintf (dbplugindir, sizeof (dbplugindir), "%s/deadbeef", LIBDIR) > sizeof (dbplugindir)) {
- fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir);
- return -1;
+ if (portable) {
+ if (snprintf (dbdocdir, sizeof (dbdocdir), "%s/doc", dbinstalldir) > sizeof (dbdocdir)) {
+ fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir);
+ return -1;
+ }
+ if (snprintf (dbplugindir, sizeof (dbplugindir), "%s/plugins", dbinstalldir) > sizeof (dbplugindir)) {
+ fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir);
+ return -1;
+ }
+ if (snprintf (dbpixmapdir, sizeof (dbpixmapdir), "%s/pixmaps", dbinstalldir) > sizeof (dbpixmapdir)) {
+ fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir);
+ return -1;
+ }
+ mkdir (dbplugindir, 0755);
}
- if (snprintf (dbpixmapdir, sizeof (dbpixmapdir), "%s/share/deadbeef/pixmaps", PREFIX) > sizeof (dbpixmapdir)) {
- fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir);
- return -1;
+ else {
+ if (snprintf (dbdocdir, sizeof (dbdocdir), "%s", DOCDIR) > sizeof (dbdocdir)) {
+ fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir);
+ return -1;
+ }
+ if (snprintf (dbplugindir, sizeof (dbplugindir), "%s/deadbeef", LIBDIR) > sizeof (dbplugindir)) {
+ fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir);
+ return -1;
+ }
+ if (snprintf (dbpixmapdir, sizeof (dbpixmapdir), "%s/share/deadbeef/pixmaps", PREFIX) > sizeof (dbpixmapdir)) {
+ fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir);
+ return -1;
+ }
}
-#endif
for (int i = 1; i < argc; i++) {
// help, version and nowplaying are executed with any filter