[PATCH v2 1/2] tools: headers should be within a consistent includedir.
Kevin Puetz
PuetzKevinA at JohnDeere.com
Thu Feb 3 08:27:24 CST 2022
A wine installation should not be divided across multiple prefixes,
and one shouldn't mix components from multiple installations.
winegcc should therefore select a single viable get_inc_dir
(as was with get_lib_dir) and add (only) its
${includedir}/wine/msvcrt and ${includedir}/wine/windows,
not offer gcc multiple (potentially nonexistent or unrelated)
paths to search for wine headers
Signed-off-by: Kevin Puetz <PuetzKevinA at JohnDeere.com>
--
e.g. for a wine built with --prefix /opt/wine-6
it's potentially the case that /usr/include/wine/* may also exist
(perhaps from a distro package), but we don't really want
winegcc adding both -I/opt/wine-6/include/windows -I/usr/include/wine/windows
get_inc_dir is identical in all winegcc/widl/wrc tools, and thus seems
like a good candidate to move into tools.h. However, its interactions
with init_argv0_dir (includedir global variable, INCLUDDIR macro, etc)
made that not really work out.
---
tools/widl/widl.c | 39 ++++++++++++++++++++++------------
tools/winegcc/winegcc.c | 47 ++++++++++++++++++++++++-----------------
tools/wrc/wrc.c | 39 ++++++++++++++++++++++------------
3 files changed, 80 insertions(+), 45 deletions(-)
diff --git a/tools/widl/widl.c b/tools/widl/widl.c
index 7686594b7d3..8150d6158e4 100644
--- a/tools/widl/widl.c
+++ b/tools/widl/widl.c
@@ -256,6 +256,29 @@ static void add_widl_version_define(void)
wpp_add_cmdline_define(version_str);
}
+static const char *get_inc_dir(const char *sysroot)
+{
+ const char *stdincpath[] = { includedir, INCLUDEDIR, "/usr/include", "/usr/local/include" };
+ const char *root = sysroot ? sysroot : "";
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(stdincpath); i++)
+ {
+ const char *root = (sysroot && i) ? sysroot : "";
+ char *path;
+ struct stat statbuf;
+
+ if (!stdincpath[i]) continue;
+ path = strmake( "%s%s/%s",root, stdincpath[i], "wine");
+ if (!stat(path,&statbuf) && S_ISDIR(statbuf.st_mode))
+ {
+ return strmake( "%s%s",root,stdincpath[i]);
+ }
+ }
+
+ return strmake( "%s%s", root, INCLUDEDIR );
+}
+
/* clean things up when aborting on a signal */
static void exit_on_signal( int sig )
{
@@ -733,19 +756,9 @@ int main(int argc,char *argv[])
if (stdinc)
{
- static const char *incl_dirs[] = { INCLUDEDIR, "/usr/include", "/usr/local/include" };
-
- if (includedir)
- {
- wpp_add_include_path( strmake( "%s/wine/msvcrt", includedir ));
- wpp_add_include_path( strmake( "%s/wine/windows", includedir ));
- }
- for (i = 0; i < ARRAY_SIZE(incl_dirs); i++)
- {
- if (i && !strcmp( incl_dirs[i], incl_dirs[0] )) continue;
- wpp_add_include_path( strmake( "%s%s/wine/msvcrt", sysroot, incl_dirs[i] ));
- wpp_add_include_path( strmake( "%s%s/wine/windows", sysroot, incl_dirs[i] ));
- }
+ const char *inc_dir = get_inc_dir(sysroot);
+ wpp_add_include_path( strmake( "%s/wine/msvcrt", inc_dir));
+ wpp_add_include_path( strmake( "%s/wine/windows", inc_dir));
}
if (pointer_size)
diff --git a/tools/winegcc/winegcc.c b/tools/winegcc/winegcc.c
index 8644afe7535..6e701a5c08b 100644
--- a/tools/winegcc/winegcc.c
+++ b/tools/winegcc/winegcc.c
@@ -647,6 +647,29 @@ static char *get_lib_dir( struct options *opts )
return strmake( "%s%s", root, LIBDIR );
}
+static const char *get_inc_dir(const char *sysroot)
+{
+ const char *stdincpath[] = { includedir, INCLUDEDIR, "/usr/include", "/usr/local/include" };
+ const char *root = sysroot ? sysroot : "";
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(stdincpath); i++)
+ {
+ const char *root = (sysroot && i) ? sysroot : "";
+ char *path;
+ struct stat statbuf;
+
+ if (!stdincpath[i]) continue;
+ path = strmake( "%s%s/%s",root, stdincpath[i], "wine");
+ if (!stat(path,&statbuf) && S_ISDIR(statbuf.st_mode))
+ {
+ return strmake( "%s%s",root,stdincpath[i]);
+ }
+ }
+
+ return strmake( "%s%s", root, INCLUDEDIR );
+}
+
static void init_argv0_dir( const char *argv0 )
{
#ifndef _WIN32
@@ -813,32 +836,18 @@ no_compat_defines:
/* standard includes come last in the include search path */
if (!opts->wine_objdir && !opts->nostdinc)
{
- const char *incl_dirs[] = { INCLUDEDIR, "/usr/include", "/usr/local/include" };
- const char *root = opts->isysroot ? opts->isysroot : opts->sysroot ? opts->sysroot : "";
+ const char *inc_sysroot = opts->isysroot ? opts->isysroot : opts->sysroot;
+ const char *inc_dir = get_inc_dir(inc_sysroot);
const char *isystem = gcc_defs ? "-isystem" : "-I";
const char *idirafter = gcc_defs ? "-idirafter" : "-I";
if (opts->use_msvcrt)
{
- if (includedir) strarray_add( &comp_args, strmake( "%s%s/wine/msvcrt", isystem, includedir ));
- for (j = 0; j < ARRAY_SIZE(incl_dirs); j++)
- {
- if (j && !strcmp( incl_dirs[0], incl_dirs[j] )) continue;
- strarray_add(&comp_args, strmake( "%s%s%s/wine/msvcrt", isystem, root, incl_dirs[j] ));
- }
+ strarray_add(&comp_args, strmake( "%s%s/wine/msvcrt", isystem, inc_dir ));
strarray_add(&comp_args, "-D__MSVCRT__");
}
- if (includedir)
- {
- strarray_add( &comp_args, strmake( "%s%s/wine/windows", isystem, includedir ));
- strarray_add( &comp_args, strmake( "%s%s", idirafter, includedir ));
- }
- for (j = 0; j < ARRAY_SIZE(incl_dirs); j++)
- {
- if (j && !strcmp( incl_dirs[0], incl_dirs[j] )) continue;
- strarray_add(&comp_args, strmake( "%s%s%s/wine/windows", isystem, root, incl_dirs[j] ));
- strarray_add(&comp_args, strmake( "%s%s%s", idirafter, root, incl_dirs[j] ));
- }
+ strarray_add(&comp_args, strmake( "%s%s/wine/windows", isystem, inc_dir ));
+ strarray_add(&comp_args, strmake( "%s%s", idirafter, inc_dir));
}
else if (opts->wine_objdir)
strarray_add(&comp_args, strmake("-I%s/include", opts->wine_objdir) );
diff --git a/tools/wrc/wrc.c b/tools/wrc/wrc.c
index 41207120237..3b38629c71b 100644
--- a/tools/wrc/wrc.c
+++ b/tools/wrc/wrc.c
@@ -225,6 +225,29 @@ static void set_version_defines(void)
free( version );
}
+static const char *get_inc_dir(const char *sysroot)
+{
+ const char *stdincpath[] = { includedir, INCLUDEDIR, "/usr/include", "/usr/local/include" };
+ const char *root = sysroot ? sysroot : "";
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(stdincpath); i++)
+ {
+ const char *root = (sysroot && i) ? sysroot : "";
+ char *path;
+ struct stat statbuf;
+
+ if (!stdincpath[i]) continue;
+ path = strmake( "%s%s/%s",root, stdincpath[i], "wine");
+ if (!stat(path,&statbuf) && S_ISDIR(statbuf.st_mode))
+ {
+ return strmake( "%s%s",root,stdincpath[i]);
+ }
+ }
+
+ return strmake( "%s%s", root, INCLUDEDIR );
+}
+
/* clean things up when aborting on a signal */
static void exit_on_signal( int sig )
{
@@ -453,19 +476,9 @@ int main(int argc,char *argv[])
/* If we do need to search standard includes, add them to the path */
if (stdinc)
{
- static const char *incl_dirs[] = { INCLUDEDIR, "/usr/include", "/usr/local/include" };
-
- if (includedir)
- {
- wpp_add_include_path( strmake( "%s/wine/msvcrt", includedir ));
- wpp_add_include_path( strmake( "%s/wine/windows", includedir ));
- }
- for (i = 0; i < ARRAY_SIZE(incl_dirs); i++)
- {
- if (i && !strcmp( incl_dirs[i], incl_dirs[0] )) continue;
- wpp_add_include_path( strmake( "%s%s/wine/msvcrt", sysroot, incl_dirs[i] ));
- wpp_add_include_path( strmake( "%s%s/wine/windows", sysroot, incl_dirs[i] ));
- }
+ const char *inc_dir = get_inc_dir(sysroot);
+ wpp_add_include_path( strmake( "%s/wine/msvcrt", inc_dir));
+ wpp_add_include_path( strmake( "%s/wine/windows", inc_dir));
}
/* Kill io buffering when some kind of debuglevel is enabled */
--
2.34.1
More information about the wine-devel
mailing list