2003-07-21 05:52:37 +08:00
|
|
|
/* gimptool in C
|
2007-11-17 21:30:23 +08:00
|
|
|
* Copyright (C) 2001-2007 Tor Lillqvist
|
2003-07-21 05:52:37 +08:00
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2003-07-21 05:52:37 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-07-21 05:52:37 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2003-07-21 05:52:37 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2007-11-17 05:37:20 +08:00
|
|
|
* Gimptool rewritten in C, originally for Win32, where end-users who
|
|
|
|
* might want to build and install a plug-in from source don't
|
|
|
|
* necessarily have any Bourne-compatible shell to run the gimptool
|
|
|
|
* script in. Later fixed up to replace the gimptool script on all
|
|
|
|
* platforms.
|
2003-07-21 05:52:37 +08:00
|
|
|
*/
|
|
|
|
|
2018-06-15 23:10:21 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2003-07-21 05:52:37 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2008-10-02 03:13:16 +08:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2013-10-15 07:58:39 +08:00
|
|
|
#include <gio/gio.h>
|
2003-07-21 05:52:37 +08:00
|
|
|
|
2011-04-28 18:47:38 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2007-11-17 05:37:20 +08:00
|
|
|
|
2008-10-02 03:13:16 +08:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#include "libgimpbase/gimpwin32-io.h"
|
|
|
|
#endif
|
|
|
|
|
2003-07-21 05:52:37 +08:00
|
|
|
|
2008-09-04 19:58:48 +08:00
|
|
|
static gboolean silent = FALSE;
|
|
|
|
static gboolean dry_run = FALSE;
|
2018-05-27 23:49:17 +08:00
|
|
|
static const gchar *cli_prefix;
|
|
|
|
static const gchar *cli_exec_prefix;
|
2007-11-17 21:30:23 +08:00
|
|
|
|
2008-09-04 19:58:48 +08:00
|
|
|
static gboolean msvc_syntax = FALSE;
|
|
|
|
static const gchar *env_cc;
|
|
|
|
static const gchar *env_cflags;
|
|
|
|
static const gchar *env_ldflags;
|
|
|
|
static const gchar *env_libs;
|
2007-11-17 21:30:23 +08:00
|
|
|
|
2003-07-21 05:52:37 +08:00
|
|
|
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#define EXEEXT ".exe"
|
|
|
|
#else
|
|
|
|
#define EXEEXT ""
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#define COPY win32_command ("copy")
|
|
|
|
#define REMOVE win32_command ("del")
|
2018-10-03 16:30:13 +08:00
|
|
|
#define REMOVE_DIR win32_command ("rd /s /q")
|
2003-07-21 05:52:37 +08:00
|
|
|
#else
|
|
|
|
#define COPY "cp"
|
|
|
|
#define REMOVE "rm -f"
|
2018-10-03 16:30:13 +08:00
|
|
|
#define REMOVE_DIR "rm -Rf"
|
2003-07-21 05:52:37 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static struct {
|
2007-11-17 21:30:23 +08:00
|
|
|
const gchar *option;
|
2008-09-04 19:58:48 +08:00
|
|
|
const gchar *value;
|
2003-07-21 05:52:37 +08:00
|
|
|
} dirs[] = {
|
2007-11-17 21:30:23 +08:00
|
|
|
{ "prefix", PREFIX },
|
|
|
|
{ "exec-prefix", EXEC_PREFIX },
|
|
|
|
{ "bindir", BINDIR },
|
|
|
|
{ "sbindir", SBINDIR },
|
|
|
|
{ "libexecdir", LIBEXECDIR },
|
2019-01-25 08:05:09 +08:00
|
|
|
{ "datadir", DATADIR },
|
2007-11-17 21:30:23 +08:00
|
|
|
{ "datarootdir", DATAROOTDIR },
|
|
|
|
{ "sysconfdir", SYSCONFDIR },
|
2007-11-17 05:37:20 +08:00
|
|
|
{ "sharedstatedir", SHAREDSTATEDIR },
|
2007-11-17 21:30:23 +08:00
|
|
|
{ "localstatedir", LOCALSTATEDIR },
|
|
|
|
{ "libdir", LIBDIR },
|
|
|
|
{ "infodir", INFODIR },
|
|
|
|
{ "mandir", MANDIR },
|
2007-11-13 19:37:11 +08:00
|
|
|
#if 0
|
|
|
|
/* For --includedir we want the includedir of the developer package,
|
|
|
|
* not an includedir under the runtime installation prefix.
|
|
|
|
*/
|
2007-11-17 21:30:23 +08:00
|
|
|
{ "includedir", INCLUDEDIR },
|
2007-11-13 19:37:11 +08:00
|
|
|
#endif
|
2007-11-17 21:30:23 +08:00
|
|
|
{ "gimpplugindir", GIMPPLUGINDIR },
|
|
|
|
{ "gimpdatadir", GIMPDATADIR }
|
2003-07-21 05:52:37 +08:00
|
|
|
};
|
|
|
|
|
2008-12-23 19:36:09 +08:00
|
|
|
|
|
|
|
static void usage (int exit_status) G_GNUC_NORETURN;
|
|
|
|
|
|
|
|
|
2003-07-21 05:52:37 +08:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
|
|
|
|
static gchar *
|
2008-09-05 01:46:51 +08:00
|
|
|
win32_command (const gchar *command)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2008-09-05 01:46:51 +08:00
|
|
|
const gchar *comspec = getenv ("COMSPEC");
|
2003-07-21 05:52:37 +08:00
|
|
|
|
|
|
|
if (!comspec)
|
2008-09-05 01:46:51 +08:00
|
|
|
comspec = "cmd.exe";
|
2003-07-21 05:52:37 +08:00
|
|
|
|
|
|
|
return g_strdup_printf ("%s /c %s", comspec, command);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static gboolean
|
2008-09-04 19:58:48 +08:00
|
|
|
starts_with_dir (const gchar *string,
|
2018-05-27 23:49:17 +08:00
|
|
|
const gchar *dir)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *dirslash = g_strconcat (dir, "/", NULL);
|
|
|
|
gboolean retval;
|
|
|
|
|
|
|
|
retval = (g_str_has_prefix (string, dirslash) ||
|
|
|
|
g_strcmp0 (string, dir) == 0);
|
|
|
|
g_free (dirslash);
|
|
|
|
|
|
|
|
return retval;
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
2008-09-04 19:58:48 +08:00
|
|
|
one_line_output (const gchar *program,
|
2018-05-27 21:17:42 +08:00
|
|
|
const gchar *args)
|
2007-11-13 19:37:11 +08:00
|
|
|
{
|
|
|
|
gchar *command = g_strconcat (program, " ", args, NULL);
|
2007-11-17 21:30:23 +08:00
|
|
|
FILE *pipe = popen (command, "r");
|
2013-03-28 05:56:01 +08:00
|
|
|
gchar line[4096];
|
2007-11-13 19:37:11 +08:00
|
|
|
|
|
|
|
if (pipe == NULL)
|
|
|
|
{
|
2007-11-17 21:30:23 +08:00
|
|
|
g_printerr ("Cannot run '%s'\n", command);
|
2018-05-27 23:49:17 +08:00
|
|
|
g_free (command);
|
2007-11-17 21:30:23 +08:00
|
|
|
exit (EXIT_FAILURE);
|
2007-11-13 19:37:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fgets (line, sizeof (line), pipe) == NULL)
|
|
|
|
line[0] = '\0';
|
|
|
|
|
|
|
|
if (strlen (line) > 0 && line [strlen (line) - 1] == '\n')
|
|
|
|
line [strlen (line) - 1] = '\0';
|
|
|
|
if (strlen (line) > 0 && line [strlen (line) - 1] == '\r')
|
|
|
|
line [strlen (line) - 1] = '\0';
|
|
|
|
|
|
|
|
pclose (pipe);
|
|
|
|
|
|
|
|
if (strlen (line) == 0)
|
|
|
|
{
|
2007-11-17 21:30:23 +08:00
|
|
|
g_printerr ("No output from '%s'\n", command);
|
2018-05-27 23:49:17 +08:00
|
|
|
g_free (command);
|
2007-11-17 21:30:23 +08:00
|
|
|
exit (EXIT_FAILURE);
|
2007-11-13 19:37:11 +08:00
|
|
|
}
|
2018-05-27 23:49:17 +08:00
|
|
|
g_free (command);
|
2007-11-13 19:37:11 +08:00
|
|
|
|
|
|
|
return g_strdup (line);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
2008-09-04 19:58:48 +08:00
|
|
|
pkg_config (const gchar *args)
|
2007-11-13 19:37:11 +08:00
|
|
|
{
|
2007-11-17 07:21:40 +08:00
|
|
|
#ifdef G_OS_WIN32
|
2007-11-13 19:37:11 +08:00
|
|
|
if (msvc_syntax)
|
|
|
|
return one_line_output ("pkg-config --msvc-syntax", args);
|
2007-11-17 07:21:40 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return one_line_output ("pkg-config", args);
|
2007-11-13 19:37:11 +08:00
|
|
|
}
|
|
|
|
|
2018-05-27 23:49:17 +08:00
|
|
|
static gchar *
|
2007-11-13 19:37:11 +08:00
|
|
|
get_runtime_prefix (gchar slash)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
|
|
|
#ifdef G_OS_WIN32
|
2007-11-13 19:37:11 +08:00
|
|
|
|
|
|
|
/* Don't use the developer package prefix, but deduce the
|
|
|
|
* installation-time prefix from where gimp-x.y.exe can be found.
|
2003-07-21 05:52:37 +08:00
|
|
|
*/
|
|
|
|
|
2003-07-28 06:52:25 +08:00
|
|
|
gchar *path;
|
2007-11-17 21:30:23 +08:00
|
|
|
gchar *p, *r;
|
2003-07-21 05:52:37 +08:00
|
|
|
|
2007-11-17 05:37:20 +08:00
|
|
|
path = g_find_program_in_path ("gimp-" GIMP_APP_VERSION ".exe");
|
2003-07-21 05:52:37 +08:00
|
|
|
|
2003-07-28 06:52:25 +08:00
|
|
|
if (path == NULL)
|
|
|
|
path = g_find_program_in_path ("gimp.exe");
|
2007-11-17 21:30:23 +08:00
|
|
|
|
2005-05-23 06:59:47 +08:00
|
|
|
if (path != NULL)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2005-05-23 06:59:47 +08:00
|
|
|
r = strrchr (path, G_DIR_SEPARATOR);
|
|
|
|
if (r != NULL)
|
2018-05-27 21:17:42 +08:00
|
|
|
{
|
|
|
|
*r = '\0';
|
|
|
|
if (strlen (path) >= 4 &&
|
|
|
|
g_ascii_strcasecmp (r - 4, G_DIR_SEPARATOR_S "bin") == 0)
|
|
|
|
{
|
|
|
|
r[-4] = '\0';
|
|
|
|
if (slash == '/')
|
|
|
|
{
|
|
|
|
/* Use forward slashes, less quoting trouble in Makefiles */
|
2018-05-27 23:49:17 +08:00
|
|
|
while ((p = strchr (path, '\\')) != NULL)
|
2018-05-27 21:17:42 +08:00
|
|
|
*p = '/';
|
|
|
|
}
|
2018-05-27 23:49:17 +08:00
|
|
|
return path;
|
2018-05-27 21:17:42 +08:00
|
|
|
}
|
|
|
|
}
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
2007-11-17 21:30:23 +08:00
|
|
|
g_printerr ("Cannot determine GIMP " GIMP_APP_VERSION " installation location\n");
|
|
|
|
|
|
|
|
exit (EXIT_FAILURE);
|
2003-07-21 05:52:37 +08:00
|
|
|
#else
|
2007-11-13 19:37:11 +08:00
|
|
|
/* On Unix assume the executable package is in the same prefix as the developer stuff */
|
2018-06-15 23:10:21 +08:00
|
|
|
return pkg_config ("--variable=prefix gimp-" GIMP_PKGCONFIG_VERSION);
|
2003-07-21 05:52:37 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-05-27 23:49:17 +08:00
|
|
|
static gchar *
|
2003-07-21 05:52:37 +08:00
|
|
|
get_exec_prefix (gchar slash)
|
|
|
|
{
|
|
|
|
#ifdef G_OS_WIN32
|
2018-05-27 23:49:17 +08:00
|
|
|
if (cli_exec_prefix != NULL)
|
|
|
|
return g_strdup (cli_exec_prefix);
|
2003-07-21 05:52:37 +08:00
|
|
|
|
|
|
|
/* On Win32, exec_prefix is always same as prefix. Or is it? Maybe not,
|
|
|
|
* but at least in tml's prebuilt stuff it is. If somebody else does
|
|
|
|
* it another way, feel free to hack this.
|
|
|
|
*/
|
2018-05-27 23:49:17 +08:00
|
|
|
return get_runtime_prefix (slash);
|
2003-07-21 05:52:37 +08:00
|
|
|
#else
|
2018-05-27 23:49:17 +08:00
|
|
|
return g_strdup (EXEC_PREFIX);
|
2003-07-21 05:52:37 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-05-27 23:49:17 +08:00
|
|
|
static gchar *
|
2008-09-04 19:58:48 +08:00
|
|
|
expand_and_munge (const gchar *value)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *retval;
|
2008-09-05 01:46:51 +08:00
|
|
|
|
2003-07-21 05:52:37 +08:00
|
|
|
if (starts_with_dir (value, "${prefix}"))
|
2008-09-05 01:46:51 +08:00
|
|
|
retval = g_strconcat (PREFIX, value + strlen ("${prefix}"), NULL);
|
2003-07-21 05:52:37 +08:00
|
|
|
else if (starts_with_dir (value, "${exec_prefix}"))
|
2008-09-05 01:46:51 +08:00
|
|
|
retval = g_strconcat (EXEC_PREFIX, value + strlen ("${exec_prefix}"), NULL);
|
|
|
|
else
|
|
|
|
retval = g_strdup (value);
|
|
|
|
|
|
|
|
if (starts_with_dir (retval, EXEC_PREFIX))
|
2018-05-27 23:49:17 +08:00
|
|
|
{
|
|
|
|
gchar *exec_prefix = get_exec_prefix ('/');
|
|
|
|
|
|
|
|
retval = g_strconcat (exec_prefix, retval + strlen (EXEC_PREFIX), NULL);
|
|
|
|
g_free (exec_prefix);
|
|
|
|
}
|
2003-07-21 05:52:37 +08:00
|
|
|
|
2008-09-05 01:46:51 +08:00
|
|
|
if (starts_with_dir (retval, PREFIX))
|
2018-05-27 23:49:17 +08:00
|
|
|
{
|
|
|
|
gchar *runtime_prefix = get_runtime_prefix ('/');
|
|
|
|
|
|
|
|
retval = g_strconcat (runtime_prefix, retval + strlen (PREFIX), NULL);
|
|
|
|
g_free (runtime_prefix);
|
|
|
|
}
|
2003-07-21 05:52:37 +08:00
|
|
|
|
2008-09-05 01:46:51 +08:00
|
|
|
return retval;
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
find_out_env_flags (void)
|
|
|
|
{
|
|
|
|
gchar *p;
|
|
|
|
|
|
|
|
if ((p = getenv ("CC")) != NULL && *p != '\0')
|
|
|
|
env_cc = p;
|
|
|
|
else if (msvc_syntax)
|
|
|
|
env_cc = "cl -MD";
|
|
|
|
else
|
2007-11-17 05:37:20 +08:00
|
|
|
env_cc = CC;
|
2003-07-21 05:52:37 +08:00
|
|
|
|
2013-09-10 18:06:55 +08:00
|
|
|
if (g_ascii_strncasecmp (env_cc, "cl", 2) == 0 &&
|
|
|
|
g_ascii_strncasecmp (env_cc, "clang", 5) != 0)
|
2003-07-21 05:52:37 +08:00
|
|
|
msvc_syntax = TRUE;
|
|
|
|
|
|
|
|
if ((p = getenv ("CFLAGS")) != NULL)
|
|
|
|
env_cflags = p;
|
|
|
|
else
|
2007-11-13 19:37:11 +08:00
|
|
|
env_cflags = "";
|
2003-07-21 05:52:37 +08:00
|
|
|
|
|
|
|
if ((p = getenv ("LDFLAGS")) != NULL)
|
|
|
|
env_ldflags = p;
|
|
|
|
else
|
2007-11-13 19:37:11 +08:00
|
|
|
env_ldflags = "";
|
2003-07-21 05:52:37 +08:00
|
|
|
|
|
|
|
if ((p = getenv ("LIBS")) != NULL && *p != '\0')
|
|
|
|
env_libs = p;
|
|
|
|
else
|
|
|
|
env_libs = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage (int exit_status)
|
|
|
|
{
|
2007-11-17 21:30:23 +08:00
|
|
|
g_print ("\
|
2018-06-15 23:10:21 +08:00
|
|
|
Usage: gimptool-" GIMP_TOOL_VERSION " [OPTION]...\n\
|
2003-07-21 05:52:37 +08:00
|
|
|
\n\
|
|
|
|
General options:\n\
|
|
|
|
--help print this message\n\
|
|
|
|
--quiet, --silent don't echo build commands\n\
|
|
|
|
--version print the version of GIMP associated with this script\n\
|
|
|
|
-n, --just-print, --dry-run, --recon\n\
|
|
|
|
don't actually run any commands; just print them\n\
|
|
|
|
Developer options:\n\
|
|
|
|
--cflags print the compiler flags that are necessary to\n\
|
|
|
|
compile a plug-in\n\
|
|
|
|
--libs print the linker flags that are necessary to link a\n\
|
|
|
|
plug-in\n\
|
|
|
|
--prefix=PREFIX use PREFIX instead of the installation prefix that\n\
|
|
|
|
GIMP was built when computing the output for --cflags\n\
|
|
|
|
and --libs\n\
|
|
|
|
--exec-prefix=PREFIX use PREFIX instead of the installation exec prefix\n\
|
|
|
|
that GIMP was built when computing the output for\n\
|
|
|
|
--cflags and --libs\n\
|
|
|
|
--msvc-syntax print flags in MSVC syntax\n\
|
|
|
|
\n\
|
|
|
|
Installation directory options:\n\
|
|
|
|
--prefix --exec-prefix --bindir --sbindir --libexecdir --datadir --sysconfdir\n\
|
|
|
|
--sharedstatedir --localstatedir --libdir --infodir --mandir --includedir\n\
|
|
|
|
--gimpplugindir --gimpdatadir\n\
|
|
|
|
\n\
|
|
|
|
The --cflags and --libs options can be appended with -noui to get appropriate\n\
|
|
|
|
settings for plug-ins which do not use GTK+.\n\
|
|
|
|
\n\
|
|
|
|
User options:\n\
|
|
|
|
--build plug-in.c build a plug-in from a source file\n\
|
|
|
|
--install plug-in.c same as --build, but installs the built\n\
|
|
|
|
plug-in as well\n\
|
|
|
|
--install-bin plug-in install a compiled plug-in\n\
|
|
|
|
--install-script script.scm install a script-fu script\n\
|
|
|
|
\n\
|
|
|
|
--uninstall-bin plug-in remove a plug-in again\n\
|
|
|
|
--uninstall-script plug-in remove a script-fu script\n\
|
|
|
|
\n\
|
|
|
|
The --install and --uninstall options have \"admin\" counterparts (with\n\
|
|
|
|
prefix --install-admin instead of --install) that can be used instead to\n\
|
2007-11-13 19:37:11 +08:00
|
|
|
install/uninstall a plug-in or script in the machine directory instead of a\n\
|
2003-07-21 05:52:37 +08:00
|
|
|
user directory.\n\
|
|
|
|
\n\
|
|
|
|
For plug-ins which do not use GTK+, the --build and --install options can be\n\
|
|
|
|
appended with -noui for appropriate settings. For plug-ins that use GTK+ but\n\
|
2010-01-02 01:46:08 +08:00
|
|
|
not libgimpui, append -nogimpui.\n");
|
2003-07-21 05:52:37 +08:00
|
|
|
exit (exit_status);
|
|
|
|
}
|
2007-11-17 21:30:23 +08:00
|
|
|
|
2003-07-21 05:52:37 +08:00
|
|
|
static gchar *
|
2007-11-13 19:37:11 +08:00
|
|
|
get_includedir (void)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-06-15 23:10:21 +08:00
|
|
|
return pkg_config ("--variable=includedir gimp-" GIMP_PKGCONFIG_VERSION);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
2007-11-13 19:37:11 +08:00
|
|
|
static void
|
|
|
|
do_includedir (void)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *includedir = get_includedir ();
|
|
|
|
|
|
|
|
g_print ("%s\n", includedir);
|
|
|
|
g_free (includedir);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
2007-11-13 19:37:11 +08:00
|
|
|
get_cflags (void)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-06-15 23:10:21 +08:00
|
|
|
return pkg_config ("--cflags gimpui-" GIMP_PKGCONFIG_VERSION);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
2007-11-13 19:37:11 +08:00
|
|
|
static void
|
|
|
|
do_cflags (void)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *cflags = get_cflags ();
|
|
|
|
|
|
|
|
g_print ("%s\n", cflags);
|
|
|
|
g_free (cflags);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
2007-11-13 19:37:11 +08:00
|
|
|
get_cflags_noui (void)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-06-15 23:10:21 +08:00
|
|
|
return pkg_config ("--cflags gimp-" GIMP_PKGCONFIG_VERSION);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-11-13 19:37:11 +08:00
|
|
|
do_cflags_noui (void)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *cflags = get_cflags_noui ();
|
|
|
|
|
|
|
|
g_print ("%s\n", cflags);
|
|
|
|
g_free (cflags);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
2007-11-13 19:37:11 +08:00
|
|
|
get_cflags_nogimpui (void)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-06-15 23:10:21 +08:00
|
|
|
return pkg_config ("--cflags gimp-" GIMP_PKGCONFIG_VERSION " gtk+-3.0");
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-11-13 19:37:11 +08:00
|
|
|
do_cflags_nogimpui (void)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *cflags = get_cflags_nogimpui ();
|
|
|
|
|
|
|
|
g_print ("%s\n", cflags);
|
|
|
|
g_free (cflags);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
get_libs (void)
|
|
|
|
{
|
2018-06-15 23:10:21 +08:00
|
|
|
return pkg_config ("--libs gimpui-" GIMP_PKGCONFIG_VERSION);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
do_libs (void)
|
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *libs = get_libs ();
|
|
|
|
|
|
|
|
g_print ("%s\n", libs);
|
|
|
|
g_free (libs);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
get_libs_noui (void)
|
|
|
|
{
|
2018-06-15 23:10:21 +08:00
|
|
|
return pkg_config ("--libs gimp-" GIMP_PKGCONFIG_VERSION);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
do_libs_noui (void)
|
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *libs = get_libs_noui ();
|
|
|
|
|
|
|
|
g_print ("%s\n", libs);
|
|
|
|
g_free (libs);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
2007-11-13 19:37:11 +08:00
|
|
|
static gchar *
|
|
|
|
get_libs_nogimpui (void)
|
|
|
|
{
|
2018-06-15 23:10:21 +08:00
|
|
|
return pkg_config ("--libs gimp-" GIMP_PKGCONFIG_VERSION " gtk+-3.0");
|
2007-11-13 19:37:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
do_libs_nogimpui (void)
|
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *libs = get_libs_nogimpui ();
|
|
|
|
|
|
|
|
g_print ("%s\n", libs);
|
|
|
|
g_free (libs);
|
2007-11-13 19:37:11 +08:00
|
|
|
}
|
|
|
|
|
2003-07-21 05:52:37 +08:00
|
|
|
static void
|
|
|
|
maybe_run (gchar *cmd)
|
|
|
|
{
|
|
|
|
if (!silent)
|
2007-11-17 21:30:23 +08:00
|
|
|
g_print ("%s\n", cmd);
|
2003-07-21 05:52:37 +08:00
|
|
|
|
2014-09-29 00:18:00 +08:00
|
|
|
/* system() declared with attribute warn_unused_result.
|
|
|
|
* Trick to get rid of the compilation warning without using the result.
|
|
|
|
*/
|
|
|
|
if (dry_run || system (cmd))
|
|
|
|
;
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-09-04 19:58:48 +08:00
|
|
|
do_build_2 (const gchar *cflags,
|
2018-05-27 21:17:42 +08:00
|
|
|
const gchar *libs,
|
|
|
|
const gchar *install_dir,
|
|
|
|
const gchar *what)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-05-27 13:25:58 +08:00
|
|
|
const gchar *lang_flag = "";
|
2008-09-04 19:58:48 +08:00
|
|
|
const gchar *output_flag;
|
|
|
|
const gchar *here_comes_linker_flags = "";
|
|
|
|
const gchar *windows_subsystem_flag = "";
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *cmd;
|
|
|
|
gchar *dest_dir;
|
|
|
|
gchar *dest_exe;
|
|
|
|
gchar *source = g_shell_quote (what);
|
|
|
|
|
|
|
|
gchar *tmp;
|
2008-09-04 19:58:48 +08:00
|
|
|
gchar *p, *q;
|
2003-07-21 05:52:37 +08:00
|
|
|
|
|
|
|
if (install_dir != NULL)
|
|
|
|
dest_dir = g_strconcat (install_dir, "/", NULL);
|
|
|
|
else
|
2018-05-27 23:49:17 +08:00
|
|
|
dest_dir = g_strdup ("");
|
2003-07-21 05:52:37 +08:00
|
|
|
|
|
|
|
dest_exe = g_strdup (what);
|
|
|
|
|
|
|
|
p = strrchr (dest_exe, '.');
|
2007-11-17 21:30:23 +08:00
|
|
|
if (p == NULL ||
|
|
|
|
!(strcmp (p, ".c") == 0 ||
|
|
|
|
strcmp (p, ".cc") == 0 ||
|
|
|
|
strcmp (p, ".cpp") == 0))
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-05-27 13:25:58 +08:00
|
|
|
/* If the file doesn't have a "standard" C/C++ suffix and:
|
|
|
|
* 1) if the compiler is known as a C++ compiler, then treat the file as a
|
|
|
|
* C++ file if possible.
|
|
|
|
* It's known that G++ and Clang++ treat a file as a C file if they are
|
|
|
|
* run with the "-x c++" option.
|
|
|
|
* 2) if the compiler is known as a C compiler or a multiple-language
|
|
|
|
* compiler, then treat the file as a C file if possible.
|
|
|
|
* It's known that GCC and Clang treat a file as a C file if they are
|
|
|
|
* run with the "-x c" option.
|
|
|
|
* TODO We may want to further support compilation with a source file
|
|
|
|
* without a standard suffix in more compilers as far as possible.
|
|
|
|
*/
|
|
|
|
if (strcmp (env_cc, "g++") == 0 ||
|
|
|
|
strncmp (env_cc, "g++-", sizeof ("g++-") - 1) == 0 ||
|
|
|
|
strcmp (env_cc, "clang++") == 0 ||
|
|
|
|
strncmp (env_cc, "clang++-", sizeof ("clang++-") - 1) == 0)
|
|
|
|
lang_flag = "-x c++ ";
|
|
|
|
else if (strcmp (env_cc, "gcc") == 0 ||
|
|
|
|
strncmp (env_cc, "gcc-", sizeof ("gcc-") - 1) == 0)
|
|
|
|
{
|
|
|
|
/* It's known GCC recognizes .CPP and .cxx, so bypass these suffixes */
|
|
|
|
if (p != NULL && strcmp (p, ".CPP") != 0 && strcmp (p, ".cxx") != 0)
|
|
|
|
lang_flag = "-x c ";
|
|
|
|
}
|
|
|
|
else if (strcmp (env_cc, "clang") == 0 ||
|
|
|
|
strncmp (env_cc, "clang-", sizeof ("clang-") - 1) == 0)
|
|
|
|
{
|
|
|
|
/* It's known Clang recognizes .CC, .CPP, .cxx and .CXX,
|
|
|
|
* so bypass these suffixes
|
|
|
|
*/
|
|
|
|
if (p != NULL && strcmp (p, ".CC") != 0 && strcmp (p, ".CPP") != 0 &&
|
|
|
|
strcmp (p, ".cxx") != 0 && strcmp (p, ".CXX") != 0)
|
|
|
|
lang_flag = "-x c ";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-05-27 22:08:06 +08:00
|
|
|
g_printerr ("The source file (%s) doesn't have a \"standard\" C or C++ suffix, "
|
2018-05-27 13:25:58 +08:00
|
|
|
"and the tool failed to confirm the language of the file.\n"
|
|
|
|
"Please be explicit about the language of the file "
|
|
|
|
"by renaming it with one of the suffixes: .c .cc .cpp\n",
|
|
|
|
what);
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
2018-05-27 22:08:06 +08:00
|
|
|
if (p)
|
|
|
|
*p = '\0';
|
2003-07-21 05:52:37 +08:00
|
|
|
q = strrchr (dest_exe, G_DIR_SEPARATOR);
|
|
|
|
#ifdef G_OS_WIN32
|
2007-11-17 21:30:23 +08:00
|
|
|
{
|
|
|
|
gchar *r = strrchr (dest_exe, '/');
|
|
|
|
if (r != NULL && (q == NULL || r > q))
|
|
|
|
q = r;
|
|
|
|
}
|
2003-07-21 05:52:37 +08:00
|
|
|
#endif
|
|
|
|
if (q == NULL)
|
|
|
|
q = dest_exe;
|
|
|
|
else
|
|
|
|
q++;
|
2007-11-17 21:30:23 +08:00
|
|
|
|
2018-10-03 16:30:13 +08:00
|
|
|
if (install_dir)
|
2019-09-16 15:53:24 +08:00
|
|
|
{
|
|
|
|
tmp = dest_dir;
|
|
|
|
dest_dir = g_strconcat (dest_dir, q, G_DIR_SEPARATOR_S, NULL);
|
|
|
|
g_free (tmp);
|
|
|
|
|
|
|
|
g_mkdir_with_parents (dest_dir,
|
|
|
|
S_IRUSR | S_IXUSR | S_IWUSR |
|
|
|
|
S_IRGRP | S_IXGRP |
|
|
|
|
S_IROTH | S_IXOTH);
|
|
|
|
}
|
2018-10-03 16:30:13 +08:00
|
|
|
|
|
|
|
tmp = g_strconcat (dest_dir, q, NULL);
|
2018-05-27 23:49:17 +08:00
|
|
|
g_free (dest_dir);
|
|
|
|
|
2018-10-03 16:30:13 +08:00
|
|
|
dest_exe = g_shell_quote (tmp);
|
2018-05-27 23:49:17 +08:00
|
|
|
g_free (tmp);
|
2003-07-21 05:52:37 +08:00
|
|
|
|
|
|
|
if (msvc_syntax)
|
|
|
|
{
|
|
|
|
output_flag = "-Fe";
|
2007-11-17 07:21:40 +08:00
|
|
|
here_comes_linker_flags = " -link";
|
|
|
|
windows_subsystem_flag = " -subsystem:windows";
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
output_flag = "-o ";
|
2007-11-17 07:21:40 +08:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
windows_subsystem_flag = " -mwindows";
|
|
|
|
#endif
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
2018-05-27 13:25:58 +08:00
|
|
|
cmd = g_strdup_printf ("%s %s%s %s %s%s %s%s %s%s %s %s",
|
2018-05-27 21:17:42 +08:00
|
|
|
env_cc,
|
|
|
|
lang_flag,
|
|
|
|
env_cflags,
|
|
|
|
cflags,
|
|
|
|
output_flag,
|
2018-05-27 23:49:17 +08:00
|
|
|
dest_exe,
|
|
|
|
source,
|
2018-05-27 21:17:42 +08:00
|
|
|
here_comes_linker_flags,
|
|
|
|
env_ldflags,
|
|
|
|
windows_subsystem_flag,
|
|
|
|
libs,
|
|
|
|
env_libs);
|
2016-05-23 04:38:12 +08:00
|
|
|
|
2003-07-21 05:52:37 +08:00
|
|
|
maybe_run (cmd);
|
2018-05-27 23:49:17 +08:00
|
|
|
|
|
|
|
g_free (dest_exe);
|
|
|
|
g_free (source);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-02 03:13:16 +08:00
|
|
|
do_build (const gchar *what)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *cflags = get_cflags ();
|
|
|
|
gchar *libs = get_libs ();
|
|
|
|
|
|
|
|
do_build_2 (cflags, libs, NULL, what);
|
|
|
|
|
|
|
|
g_free (cflags);
|
|
|
|
g_free (libs);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-02 03:13:16 +08:00
|
|
|
do_build_noui (const gchar *what)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *cflags = get_cflags_noui ();
|
|
|
|
gchar *libs = get_libs_noui ();
|
|
|
|
|
|
|
|
do_build_2 (cflags, libs, NULL, what);
|
|
|
|
|
|
|
|
g_free (cflags);
|
|
|
|
g_free (libs);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-02 03:13:16 +08:00
|
|
|
do_build_nogimpui (const gchar *what)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
|
|
|
do_build (what);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
2011-10-04 20:58:52 +08:00
|
|
|
get_user_plugin_dir (void)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2013-02-20 02:34:01 +08:00
|
|
|
return g_build_filename (gimp_directory (),
|
2011-10-04 20:58:52 +08:00
|
|
|
"plug-ins",
|
|
|
|
NULL);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
2018-10-03 16:30:13 +08:00
|
|
|
static gchar *
|
2019-09-16 15:53:24 +08:00
|
|
|
get_plugin_dir (const gchar *base_dir,
|
|
|
|
const gchar *what)
|
2018-10-03 16:30:13 +08:00
|
|
|
{
|
|
|
|
gchar *separator, *dot, *plugin_name, *plugin_dir;
|
|
|
|
gchar *tmp = g_strdup (what);
|
|
|
|
|
|
|
|
separator = strrchr (tmp, G_DIR_SEPARATOR);
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
{
|
2019-09-16 15:53:24 +08:00
|
|
|
gchar *alt_separator = strrchr (tmp, '/');
|
|
|
|
|
|
|
|
if (alt_separator != NULL &&
|
|
|
|
(separator == NULL || alt_separator > separator))
|
|
|
|
{
|
|
|
|
separator = alt_separator;
|
|
|
|
}
|
2018-10-03 16:30:13 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
dot = strrchr (tmp, '.');
|
|
|
|
|
|
|
|
if (separator)
|
|
|
|
plugin_name = separator + 1;
|
|
|
|
else
|
|
|
|
plugin_name = tmp;
|
|
|
|
|
|
|
|
if (dot)
|
|
|
|
*dot = '\0';
|
|
|
|
|
|
|
|
plugin_dir = g_strconcat (base_dir,
|
2019-09-16 15:53:24 +08:00
|
|
|
G_DIR_SEPARATOR_S,
|
|
|
|
plugin_name,
|
|
|
|
NULL);
|
2018-10-03 16:30:13 +08:00
|
|
|
|
|
|
|
g_free (tmp);
|
|
|
|
|
|
|
|
return plugin_dir;
|
|
|
|
}
|
|
|
|
|
2003-07-21 05:52:37 +08:00
|
|
|
static void
|
2008-10-02 03:13:16 +08:00
|
|
|
do_install (const gchar *what)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *cflags = get_cflags ();
|
|
|
|
gchar *libs = get_libs ();
|
|
|
|
gchar *dir = get_user_plugin_dir ();
|
|
|
|
|
|
|
|
do_build_2 (cflags, libs, dir, what);
|
|
|
|
|
|
|
|
g_free (cflags);
|
|
|
|
g_free (libs);
|
|
|
|
g_free (dir);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-02 03:13:16 +08:00
|
|
|
do_install_noui (const gchar *what)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *cflags = get_cflags_noui ();
|
|
|
|
gchar *libs = get_libs_noui ();
|
|
|
|
gchar *dir = get_user_plugin_dir ();
|
|
|
|
|
|
|
|
do_build_2 (cflags, libs, dir, what);
|
|
|
|
|
|
|
|
g_free (cflags);
|
|
|
|
g_free (libs);
|
|
|
|
g_free (dir);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-02 03:13:16 +08:00
|
|
|
do_install_nogimpui (const gchar *what)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
|
|
|
do_install (what);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
get_sys_plugin_dir (gboolean forward_slashes)
|
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *dir;
|
|
|
|
|
2013-07-04 21:11:47 +08:00
|
|
|
#ifdef G_OS_WIN32
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *rprefix;
|
2003-07-21 05:52:37 +08:00
|
|
|
|
2011-10-04 20:58:52 +08:00
|
|
|
rprefix = get_runtime_prefix (forward_slashes ? '/' : G_DIR_SEPARATOR);
|
|
|
|
|
2018-05-27 23:49:17 +08:00
|
|
|
dir = g_build_path (forward_slashes ? "/" : G_DIR_SEPARATOR_S,
|
|
|
|
rprefix,
|
|
|
|
"lib", "gimp",
|
|
|
|
GIMP_PLUGIN_VERSION,
|
|
|
|
"plug-ins",
|
|
|
|
NULL);
|
|
|
|
g_free (rprefix);
|
2013-07-04 21:11:47 +08:00
|
|
|
#else
|
2018-05-27 23:49:17 +08:00
|
|
|
dir = g_build_path (forward_slashes ? "/" : G_DIR_SEPARATOR_S,
|
|
|
|
LIBDIR,
|
|
|
|
"gimp",
|
|
|
|
GIMP_PLUGIN_VERSION,
|
|
|
|
"plug-ins",
|
|
|
|
NULL);
|
2013-07-04 21:11:47 +08:00
|
|
|
#endif
|
2018-05-27 23:49:17 +08:00
|
|
|
|
|
|
|
return dir;
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-02 03:13:16 +08:00
|
|
|
do_install_admin (const gchar *what)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *cflags = get_cflags ();
|
|
|
|
gchar *libs = get_libs ();
|
|
|
|
gchar *dir = get_sys_plugin_dir (TRUE);
|
|
|
|
|
|
|
|
do_build_2 (cflags, libs, dir, what);
|
|
|
|
|
|
|
|
g_free (cflags);
|
|
|
|
g_free (libs);
|
|
|
|
g_free (dir);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-02 03:13:16 +08:00
|
|
|
do_install_admin_noui (const gchar *what)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *cflags = get_cflags_noui ();
|
|
|
|
gchar *libs = get_libs_noui ();
|
|
|
|
gchar *dir = get_sys_plugin_dir (TRUE);
|
|
|
|
|
|
|
|
do_build_2 (cflags, libs, dir, what);
|
|
|
|
|
|
|
|
g_free (cflags);
|
|
|
|
g_free (libs);
|
|
|
|
g_free (dir);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-02 03:13:16 +08:00
|
|
|
do_install_admin_nogimpui (const gchar *what)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *cflags = get_cflags ();
|
|
|
|
gchar *libs = get_libs ();
|
|
|
|
gchar *dir = get_sys_plugin_dir (TRUE);
|
|
|
|
|
|
|
|
do_build_2 (cflags, libs, dir, what);
|
|
|
|
|
|
|
|
g_free (cflags);
|
|
|
|
g_free (libs);
|
|
|
|
g_free (dir);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-02 03:13:16 +08:00
|
|
|
do_install_bin_2 (const gchar *dir,
|
2018-05-27 21:17:42 +08:00
|
|
|
const gchar *what)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *cmd;
|
|
|
|
gchar *quoted_src;
|
|
|
|
gchar *quoted_dir;
|
|
|
|
|
2018-10-03 16:30:13 +08:00
|
|
|
gchar *dest_dir = g_strconcat (dir, G_DIR_SEPARATOR_S, NULL);
|
2019-09-16 15:53:24 +08:00
|
|
|
|
2018-10-03 16:30:13 +08:00
|
|
|
g_mkdir_with_parents (dest_dir,
|
2008-10-02 03:13:16 +08:00
|
|
|
S_IRUSR | S_IXUSR | S_IWUSR |
|
|
|
|
S_IRGRP | S_IXGRP |
|
|
|
|
S_IROTH | S_IXOTH);
|
|
|
|
|
2018-05-27 23:49:17 +08:00
|
|
|
quoted_src = g_shell_quote (what);
|
2018-10-03 16:30:13 +08:00
|
|
|
quoted_dir = g_shell_quote (dest_dir);
|
2018-05-27 23:49:17 +08:00
|
|
|
cmd = g_strconcat (COPY, " ", quoted_src, " ", quoted_dir, NULL);
|
|
|
|
maybe_run (cmd);
|
|
|
|
|
2018-10-03 16:30:13 +08:00
|
|
|
g_free (dest_dir);
|
2018-05-27 23:49:17 +08:00
|
|
|
g_free (cmd);
|
|
|
|
g_free (quoted_src);
|
|
|
|
g_free (quoted_dir);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-02 03:13:16 +08:00
|
|
|
do_install_bin (const gchar *what)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *dir = get_user_plugin_dir ();
|
2018-10-03 16:30:13 +08:00
|
|
|
gchar *plugin_dir = get_plugin_dir (dir, what);
|
2018-05-27 23:49:17 +08:00
|
|
|
|
2018-10-03 16:30:13 +08:00
|
|
|
do_install_bin_2 (plugin_dir, what);
|
|
|
|
|
|
|
|
g_free (plugin_dir);
|
2018-05-27 23:49:17 +08:00
|
|
|
g_free (dir);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-02 03:13:16 +08:00
|
|
|
do_install_admin_bin (const gchar *what)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *dir = get_sys_plugin_dir (FALSE);
|
2018-10-03 16:30:13 +08:00
|
|
|
gchar *plugin_dir = get_plugin_dir (dir, what);
|
2018-05-27 23:49:17 +08:00
|
|
|
|
|
|
|
do_install_bin_2 (dir, what);
|
2018-10-03 16:30:13 +08:00
|
|
|
|
|
|
|
g_free (plugin_dir);
|
2018-05-27 23:49:17 +08:00
|
|
|
g_free (dir);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-10-03 16:30:13 +08:00
|
|
|
do_uninstall (const gchar *dir)
|
|
|
|
{
|
|
|
|
gchar *cmd;
|
|
|
|
gchar *quoted_src;
|
2019-09-16 15:53:24 +08:00
|
|
|
|
2018-10-03 16:30:13 +08:00
|
|
|
quoted_src = g_shell_quote (dir);
|
|
|
|
|
|
|
|
cmd = g_strconcat (REMOVE_DIR, " ", quoted_src, NULL);
|
|
|
|
maybe_run (cmd);
|
|
|
|
|
|
|
|
g_free (cmd);
|
|
|
|
g_free (quoted_src);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
do_uninstall_script_2 (const gchar *dir,
|
|
|
|
const gchar *what)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *cmd;
|
|
|
|
gchar *quoted_src;
|
|
|
|
gchar *src;
|
|
|
|
|
|
|
|
src = g_strconcat (dir, G_DIR_SEPARATOR_S, what, NULL);
|
|
|
|
quoted_src = g_shell_quote (src);
|
|
|
|
|
|
|
|
cmd = g_strconcat (REMOVE, " ", quoted_src, NULL);
|
|
|
|
maybe_run (cmd);
|
|
|
|
|
|
|
|
g_free (cmd);
|
|
|
|
g_free (quoted_src);
|
2018-10-03 16:30:13 +08:00
|
|
|
g_free (src);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
2018-05-27 23:49:17 +08:00
|
|
|
static gchar *
|
2008-10-02 03:13:16 +08:00
|
|
|
maybe_append_exe (const gchar *what)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
gchar *p = strrchr (what, '.');
|
|
|
|
|
2005-09-09 21:48:54 +08:00
|
|
|
if (p == NULL || g_ascii_strcasecmp (p, ".exe") != 0)
|
2009-10-08 03:31:55 +08:00
|
|
|
return g_strconcat (what, ".exe", NULL);
|
2003-07-21 05:52:37 +08:00
|
|
|
#endif
|
|
|
|
|
2018-05-27 23:49:17 +08:00
|
|
|
return g_strdup (what);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-02 03:13:16 +08:00
|
|
|
do_uninstall_bin (const gchar *what)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-10-03 16:30:13 +08:00
|
|
|
gchar *dir = get_user_plugin_dir ();
|
|
|
|
gchar *exe = maybe_append_exe (what);
|
|
|
|
gchar *plugin_dir = get_plugin_dir (dir, what);
|
2018-05-27 23:49:17 +08:00
|
|
|
|
2018-10-03 16:30:13 +08:00
|
|
|
do_uninstall (plugin_dir);
|
2018-05-27 23:49:17 +08:00
|
|
|
|
2018-10-03 16:30:13 +08:00
|
|
|
g_free (plugin_dir);
|
2018-05-27 23:49:17 +08:00
|
|
|
g_free (dir);
|
|
|
|
g_free (exe);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-02 03:13:16 +08:00
|
|
|
do_uninstall_admin_bin (const gchar *what)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-10-03 16:30:13 +08:00
|
|
|
gchar *dir = get_sys_plugin_dir (FALSE);
|
|
|
|
gchar *exe = maybe_append_exe (what);
|
|
|
|
gchar *plugin_dir = get_plugin_dir (dir, what);
|
2018-05-27 23:49:17 +08:00
|
|
|
|
2018-10-03 16:30:13 +08:00
|
|
|
do_uninstall (plugin_dir);
|
2018-05-27 23:49:17 +08:00
|
|
|
|
2018-10-03 16:30:13 +08:00
|
|
|
g_free (plugin_dir);
|
2018-05-27 23:49:17 +08:00
|
|
|
g_free (dir);
|
|
|
|
g_free (exe);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
2011-10-04 20:58:52 +08:00
|
|
|
get_user_script_dir (void)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2013-02-20 02:34:01 +08:00
|
|
|
return g_build_filename (gimp_directory (),
|
2011-10-04 20:58:52 +08:00
|
|
|
"scripts",
|
|
|
|
NULL);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-02 03:13:16 +08:00
|
|
|
do_install_script (const gchar *what)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *dir = get_user_script_dir ();
|
|
|
|
|
|
|
|
do_install_bin_2 (dir, what);
|
|
|
|
g_free (dir);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
2011-10-04 20:58:52 +08:00
|
|
|
get_sys_script_dir (void)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *dir;
|
|
|
|
gchar *prefix = get_runtime_prefix (G_DIR_SEPARATOR);
|
|
|
|
|
|
|
|
dir = g_build_filename (prefix, "share", "gimp",
|
|
|
|
GIMP_PLUGIN_VERSION, "scripts",
|
|
|
|
NULL);
|
|
|
|
g_free (prefix);
|
|
|
|
|
|
|
|
return dir;
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-02 03:13:16 +08:00
|
|
|
do_install_admin_script (const gchar *what)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *dir = get_sys_script_dir ();
|
|
|
|
|
|
|
|
do_install_bin_2 (dir, what);
|
|
|
|
g_free (dir);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-02 03:13:16 +08:00
|
|
|
do_uninstall_script (const gchar *what)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *dir = get_user_script_dir ();
|
|
|
|
|
2018-10-03 16:30:13 +08:00
|
|
|
do_uninstall_script_2 (dir, what);
|
2018-05-27 23:49:17 +08:00
|
|
|
g_free (dir);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-02 03:13:16 +08:00
|
|
|
do_uninstall_admin_script (const gchar *what)
|
2003-07-21 05:52:37 +08:00
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *dir = get_sys_script_dir ();
|
|
|
|
|
2018-10-03 16:30:13 +08:00
|
|
|
do_uninstall_script_2 (dir, what);
|
2018-05-27 23:49:17 +08:00
|
|
|
g_free (dir);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc,
|
|
|
|
char **argv)
|
|
|
|
{
|
|
|
|
gint argi;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
if (argc == 1)
|
2007-11-17 21:30:23 +08:00
|
|
|
usage (EXIT_SUCCESS);
|
2003-07-21 05:52:37 +08:00
|
|
|
|
|
|
|
/* First scan for flags that affect our behaviour globally, but
|
|
|
|
* are still allowed late on the command line.
|
|
|
|
*/
|
|
|
|
argi = 0;
|
|
|
|
while (++argi < argc)
|
|
|
|
{
|
|
|
|
if (strcmp (argv[argi], "-n") == 0 ||
|
2018-05-27 21:17:42 +08:00
|
|
|
strcmp (argv[argi], "--just-print") == 0 ||
|
|
|
|
strcmp (argv[argi], "--dry-run") == 0 ||
|
|
|
|
strcmp (argv[argi], "--recon") == 0)
|
2007-11-17 21:30:23 +08:00
|
|
|
{
|
|
|
|
dry_run = TRUE;
|
|
|
|
}
|
2007-11-13 19:37:11 +08:00
|
|
|
else if (strcmp (argv[argi], "--help") == 0)
|
2007-11-17 21:30:23 +08:00
|
|
|
{
|
|
|
|
usage (EXIT_SUCCESS);
|
|
|
|
}
|
2007-11-13 19:37:11 +08:00
|
|
|
else if (g_str_has_prefix (argv[argi], "--prefix="))
|
2007-11-17 21:30:23 +08:00
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
cli_prefix = argv[argi] + strlen ("--prefix=");
|
2007-11-17 21:30:23 +08:00
|
|
|
}
|
2007-11-13 19:37:11 +08:00
|
|
|
else if (g_str_has_prefix (argv[argi], "--exec-prefix="))
|
2007-11-17 21:30:23 +08:00
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
cli_exec_prefix = argv[argi] + strlen ("--exec_prefix=");
|
2007-11-17 21:30:23 +08:00
|
|
|
}
|
2003-07-21 05:52:37 +08:00
|
|
|
else if (strcmp (argv[argi], "--msvc-syntax") == 0)
|
2007-11-17 21:30:23 +08:00
|
|
|
{
|
2018-10-03 16:30:13 +08:00
|
|
|
#ifdef G_OS_WIN32
|
2007-11-17 21:30:23 +08:00
|
|
|
msvc_syntax = TRUE;
|
2018-10-03 16:30:13 +08:00
|
|
|
#else
|
|
|
|
g_printerr ("Ignoring --msvc-syntax\n");
|
|
|
|
#endif
|
2007-11-17 21:30:23 +08:00
|
|
|
}
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
find_out_env_flags ();
|
|
|
|
|
|
|
|
/* Second pass, actually do something. */
|
|
|
|
argi = 0;
|
|
|
|
while (++argi < argc)
|
|
|
|
{
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (dirs); i++)
|
2007-11-17 21:30:23 +08:00
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *test = g_strconcat ("--", dirs[i].option, NULL);
|
|
|
|
|
2018-10-03 16:30:13 +08:00
|
|
|
if (strcmp (argv[argi], test) == 0)
|
2018-05-27 23:49:17 +08:00
|
|
|
{
|
|
|
|
g_free (test);
|
|
|
|
break;
|
|
|
|
}
|
2018-10-03 16:30:13 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
g_free (test);
|
|
|
|
}
|
2007-11-17 21:30:23 +08:00
|
|
|
}
|
|
|
|
|
2003-07-21 05:52:37 +08:00
|
|
|
if (i < G_N_ELEMENTS (dirs))
|
2007-11-17 21:30:23 +08:00
|
|
|
{
|
2018-05-27 23:49:17 +08:00
|
|
|
gchar *expanded = expand_and_munge (dirs[i].value);
|
|
|
|
|
|
|
|
g_print ("%s\n", expanded);
|
|
|
|
g_free (expanded);
|
2007-11-17 21:30:23 +08:00
|
|
|
}
|
2003-07-21 05:52:37 +08:00
|
|
|
else if (strcmp (argv[argi], "--quiet") == 0 ||
|
2007-11-17 21:30:23 +08:00
|
|
|
strcmp (argv[argi], "--silent") == 0)
|
|
|
|
{
|
|
|
|
silent = TRUE;
|
|
|
|
}
|
2003-07-21 05:52:37 +08:00
|
|
|
else if (strcmp (argv[argi], "--version") == 0)
|
2018-05-27 21:17:42 +08:00
|
|
|
{
|
|
|
|
g_print ("%d.%d.%d\n",
|
2007-11-17 21:30:23 +08:00
|
|
|
GIMP_MAJOR_VERSION, GIMP_MINOR_VERSION, GIMP_MICRO_VERSION);
|
2018-05-27 21:17:42 +08:00
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
}
|
2003-07-21 05:52:37 +08:00
|
|
|
else if (strcmp (argv[argi], "-n") == 0 ||
|
2018-05-27 21:17:42 +08:00
|
|
|
strcmp (argv[argi], "--just-print") == 0 ||
|
|
|
|
strcmp (argv[argi], "--dry-run") == 0 ||
|
|
|
|
strcmp (argv[argi], "--recon") == 0)
|
|
|
|
; /* Already handled */
|
2007-11-13 19:37:11 +08:00
|
|
|
else if (strcmp (argv[argi], "--includedir") == 0)
|
2018-05-27 21:17:42 +08:00
|
|
|
do_includedir ();
|
2003-07-21 05:52:37 +08:00
|
|
|
else if (strcmp (argv[argi], "--cflags") == 0)
|
2018-05-27 21:17:42 +08:00
|
|
|
do_cflags ();
|
2003-07-21 05:52:37 +08:00
|
|
|
else if (strcmp (argv[argi], "--cflags-noui") == 0)
|
2018-05-27 21:17:42 +08:00
|
|
|
do_cflags_noui ();
|
2003-07-21 05:52:37 +08:00
|
|
|
else if (strcmp (argv[argi], "--cflags-nogimpui") == 0)
|
2018-05-27 21:17:42 +08:00
|
|
|
do_cflags_nogimpui ();
|
2003-07-21 05:52:37 +08:00
|
|
|
else if (strcmp (argv[argi], "--libs") == 0)
|
2018-05-27 21:17:42 +08:00
|
|
|
do_libs ();
|
2003-07-21 05:52:37 +08:00
|
|
|
else if (strcmp (argv[argi], "--libs-noui") == 0)
|
2018-05-27 21:17:42 +08:00
|
|
|
do_libs_noui ();
|
2007-11-13 19:37:11 +08:00
|
|
|
else if (strcmp (argv[argi], "--libs-nogimpui") == 0)
|
2018-05-27 21:17:42 +08:00
|
|
|
do_libs_nogimpui ();
|
2007-11-13 19:37:11 +08:00
|
|
|
else if (g_str_has_prefix (argv[argi], "--prefix="))
|
2018-05-27 21:17:42 +08:00
|
|
|
;
|
2007-11-13 19:37:11 +08:00
|
|
|
else if (g_str_has_prefix (argv[argi], "--exec-prefix="))
|
2018-05-27 21:17:42 +08:00
|
|
|
;
|
2003-07-21 05:52:37 +08:00
|
|
|
else if (strcmp (argv[argi], "--msvc-syntax") == 0)
|
2018-05-27 21:17:42 +08:00
|
|
|
;
|
2003-07-21 05:52:37 +08:00
|
|
|
else if (strcmp (argv[argi], "--build") == 0)
|
2018-05-27 21:17:42 +08:00
|
|
|
do_build (argv[++argi]);
|
2003-07-21 05:52:37 +08:00
|
|
|
else if (strcmp (argv[argi], "--build-noui") == 0)
|
2018-05-27 21:17:42 +08:00
|
|
|
do_build_noui (argv[++argi]);
|
2003-07-21 05:52:37 +08:00
|
|
|
else if (strcmp (argv[argi], "--build-nogimpui") == 0)
|
2018-05-27 21:17:42 +08:00
|
|
|
do_build_nogimpui (argv[++argi]);
|
2003-07-21 05:52:37 +08:00
|
|
|
else if (strcmp (argv[argi], "--install") == 0)
|
2018-05-27 21:17:42 +08:00
|
|
|
do_install (argv[++argi]);
|
2003-07-21 05:52:37 +08:00
|
|
|
else if (strcmp (argv[argi], "--install-noui") == 0)
|
2018-05-27 21:17:42 +08:00
|
|
|
do_install_noui (argv[++argi]);
|
2003-07-21 05:52:37 +08:00
|
|
|
else if (strcmp (argv[argi], "--install-nogimpui") == 0)
|
2018-05-27 21:17:42 +08:00
|
|
|
do_install_nogimpui (argv[++argi]);
|
2003-07-21 05:52:37 +08:00
|
|
|
else if (strcmp (argv[argi], "--install-admin") == 0)
|
2018-05-27 21:17:42 +08:00
|
|
|
do_install_admin (argv[++argi]);
|
2003-07-21 05:52:37 +08:00
|
|
|
else if (strcmp (argv[argi], "--install-admin-noui") == 0)
|
2018-05-27 21:17:42 +08:00
|
|
|
do_install_admin_noui (argv[++argi]);
|
2003-07-21 05:52:37 +08:00
|
|
|
else if (strcmp (argv[argi], "--install-admin-nogimpui") == 0)
|
2018-05-27 21:17:42 +08:00
|
|
|
do_install_admin_nogimpui (argv[++argi]);
|
2003-07-21 05:52:37 +08:00
|
|
|
else if (strcmp (argv[argi], "--install-bin") == 0)
|
2018-05-27 21:17:42 +08:00
|
|
|
do_install_bin (argv[++argi]);
|
2003-07-21 05:52:37 +08:00
|
|
|
else if (strcmp (argv[argi], "--install-admin-bin") == 0)
|
2018-05-27 21:17:42 +08:00
|
|
|
do_install_admin_bin (argv[++argi]);
|
2003-07-21 05:52:37 +08:00
|
|
|
else if (strcmp (argv[argi], "--uninstall-bin") == 0)
|
2018-05-27 21:17:42 +08:00
|
|
|
do_uninstall_bin (argv[++argi]);
|
2003-07-21 05:52:37 +08:00
|
|
|
else if (strcmp (argv[argi], "--uninstall-admin-bin") == 0)
|
2018-05-27 21:17:42 +08:00
|
|
|
do_uninstall_admin_bin (argv[++argi]);
|
2003-07-21 05:52:37 +08:00
|
|
|
else if (strcmp (argv[argi], "--install-script") == 0)
|
2018-05-27 21:17:42 +08:00
|
|
|
do_install_script (argv[++argi]);
|
2003-07-21 05:52:37 +08:00
|
|
|
else if (strcmp (argv[argi], "--install-admin-script") == 0)
|
2018-05-27 21:17:42 +08:00
|
|
|
do_install_admin_script (argv[++argi]);
|
2003-07-21 05:52:37 +08:00
|
|
|
else if (strcmp (argv[argi], "--uninstall-script") == 0)
|
2018-05-27 21:17:42 +08:00
|
|
|
do_uninstall_script (argv[++argi]);
|
2003-07-21 05:52:37 +08:00
|
|
|
else if (strcmp (argv[argi], "--uninstall-admin-script") == 0)
|
2018-05-27 21:17:42 +08:00
|
|
|
do_uninstall_admin_script (argv[++argi]);
|
2003-07-21 05:52:37 +08:00
|
|
|
else
|
2018-05-27 21:17:42 +08:00
|
|
|
{
|
|
|
|
g_printerr ("Unrecognized switch %s\n", argv[argi]);
|
|
|
|
usage (EXIT_FAILURE);
|
|
|
|
}
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
2007-11-17 21:30:23 +08:00
|
|
|
|
|
|
|
exit (EXIT_SUCCESS);
|
2003-07-21 05:52:37 +08:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Local Variables:
|
|
|
|
* mode: c
|
|
|
|
* End:
|
|
|
|
*/
|