winegcc: portability

Dimitrie O. Paun dpaun at rogers.com
Sun Feb 29 20:52:07 CST 2004


OK, this is it. I've included the new config.h.in for
patch review convenience. Please run

autoheader
autoconf

after applying it. With this stuff in the tree, we should
be able to build programs/* with it. Next on the list is
-shared support...

ChangeLog
    Instrument winegcc to use the compilers and options detected
    at configure time. Add support for parsing/formatting a string
    array from/to a char string. Add option to disable short wchar
    support in winegcc.

Index: configure.ac
===================================================================
RCS file: /var/cvs/wine/configure.ac,v
retrieving revision 1.244
diff -u -r1.244 configure.ac
--- configure.ac	27 Feb 2004 21:51:13 -0000	1.244
+++ configure.ac	1 Mar 2004 02:45:19 -0000
@@ -41,7 +41,27 @@
 AC_CANONICAL_HOST
 AC_PROG_MAKE_SET
 AC_PROG_CC
+AC_PROG_CXX
 AC_PROG_CPP
+dnl We can't use the result of the above CPP test, it uses by default $(CC) -E
+AC_CHECK_PROG(PROG_CPP, "cpp", "cpp")
+
+AC_DEFINE_UNQUOTED(PROG_CC, "$CC", [Specifies the C compiler])
+AC_DEFINE_UNQUOTED(PROG_CXX, "$CXX", [Specifies the C++ compiler])
+AC_DEFINE_UNQUOTED(PROG_CPP, "$PROG_CPP", [Specifies the C Pre-Processor])
+
+if test "x${GCC}" = "xyes"; then
+    is_cc_gcc=1
+else
+    is_cc_gcc=0
+fi
+if test "x${GXX}" = "xyes"; then
+    is_cxx_gxx=1
+else
+    is_cxx_gxx=0
+fi
+AC_DEFINE_UNQUOTED(IS_CC_GCC, $is_cc_gcc, [Defined to 1 if we use GCC, 0 otherwise])
+AC_DEFINE_UNQUOTED(IS_CXX_GXX, $is_cxx_gxx, [Defined to 1 if we use GXX, 0 otherwise])
 
 AC_CACHE_CHECK([for the directory containing the Wine tools], wine_cv_toolsdir,
   [if test -z "$with_wine_tools"; then
@@ -716,6 +758,15 @@
     EXTRACFLAGS="$EXTRACFLAGS -fno-strength-reduce"
   fi
 
+  dnl Check for -fshort-wchar
+  AC_CACHE_CHECK([for gcc -fshort-wchar support], ac_cv_c_gcc_fshort_wchar,
+      [WINE_TRY_CFLAGS([-fshort-wchar],
+                      ac_cv_c_gcc_fshort_wchar="yes",ac_cv_c_gcc_fshort_wchar="no")])
+  if test "$ac_cv_c_gcc_fshort_wchar" = "yes"
+  then
+      AC_DEFINE(CC_FLAG_SHORT_WCHAR, "-fshort-wchar", [Specifies the compiler flag that forces a short wchar_t])
+  fi
+
   dnl Check for -mpreferred-stack-boundary
   AC_CACHE_CHECK([for gcc -mpreferred-stack-boundary=2 support], ac_cv_c_gcc_stack_boundary,
       [WINE_TRY_CFLAGS([-mpreferred-stack-boundary=2],
@@ -851,19 +902,20 @@
     then
       DLLFLAGS="$DLLFLAGS -fPIC"
       DLLEXT=".so"
+      AC_DEFINE(CC_FLAG_SHARED_LIBS, "-fPIC", [Specifies the compiler flag needed to build shared libraries])
       AC_CACHE_CHECK([whether we can build a GNU style ELF dll], ac_cv_c_dll_gnuelf,
           [WINE_TRY_CFLAGS([-fPIC -shared -Wl,-soname,conftest.so.1.0,-Bsymbolic],
                            ac_cv_c_dll_gnuelf="yes",ac_cv_c_dll_gnuelf="no")])
       if test "$ac_cv_c_dll_gnuelf" = "yes"
       then
         LDSHARED="\$(CC) -shared \$(SONAME:%=-Wl,-soname,%)"
-        LDDLL="\$(CC) -shared -Wl,-Bsymbolic"
+        LDDLLFLAGS="-shared -Wl,-Bsymbolic"
         AC_CACHE_CHECK([whether the linker accepts -z defs], ac_cv_c_dll_zdefs,
           [WINE_TRY_CFLAGS([-fPIC -shared -Wl,-Bsymbolic,-z,defs],
                            ac_cv_c_dll_zdefs="yes",ac_cv_c_dll_zdefs="no")])
         if test "$ac_cv_c_dll_zdefs" = "yes"
         then
-          LDDLL="$LDDLL,-z,defs"
+          LDDLLFLAGS="$LDDLLFLAGS,-z,defs"
         fi
 
         AC_CACHE_CHECK([whether the linker accepts -init and -fini], ac_cv_c_dll_init_fini,
@@ -872,7 +924,7 @@
         if test "$ac_cv_c_dll_init_fini" = "yes"
         then
           AC_DEFINE(HAVE_LINKER_INIT_FINI,1,[Define if the linker supports renaming the init and fini functions])
-          LDDLL="$LDDLL,-init,__wine_spec_init,-fini,__wine_spec_fini"
+          LDDLLFLAGS="$LDDLLFLAGS,-init,__wine_spec_init,-fini,__wine_spec_fini"
         fi
 
         AC_CACHE_CHECK([whether the linker accepts version scripts], ac_cv_c_ld_version_scripts,
@@ -916,7 +968,7 @@
         if test "$ac_cv_c_dll_unixware" = "yes"
         then
           LDSHARED="\$(CC) -Wl,-G \$(SONAME:%=-Wl,-h,%)"
-          LDDLL="\$(CC) -Wl,-G,-B,symbolic"
+          LDDLLFLAGS="-Wl,-G,-B,symbolic"
 
         else
           AC_CACHE_CHECK(whether we can build a Mach-O (Mac OS X/Darwin) dll, ac_cv_c_dll_macho,
@@ -924,13 +976,14 @@
           if test "$ac_cv_c_dll_macho" = "yes"
           then
             LIBEXT="dylib"
-            LDDLL="\$(CC) -bundle -flat_namespace -undefined suppress"
+            LDDLLFLAGS="-bundle -flat_namespace -undefined suppress"
             LDSHARED="\$(CC) -dynamiclib"
             CFLAGS="$CFLAGS -ffixed-r13 -no-cpp-precomp"
           fi
         fi
       fi
     fi
+    LDDLL="\$(CC) $LDDLLFLAGS"
 
     dnl Check for cross compiler to build test programs
     AC_SUBST(CROSSTEST,"")
@@ -943,6 +996,7 @@
     fi
     ;;
 esac
+AC_DEFINE_UNQUOTED(LDDLLFLAGS, "$LDDLLFLAGS", [Flags needed to link a DLL])
 
 if test "$LIBEXT" = "a"; then
   AC_MSG_ERROR(
@@ -1227,6 +1281,7 @@
 AC_C_INLINE
 AC_CHECK_TYPES([mode_t, off_t, pid_t, size_t, ssize_t])
 AC_CHECK_SIZEOF(long long,0)
+AC_CHECK_TYPE(long long)
 
 AC_CACHE_CHECK([whether linux/input.h is for real],
 	wine_cv_linux_input_h,
Index: include/config.h.in
===================================================================
RCS file: /var/cvs/wine/include/config.h.in,v
retrieving revision 1.179
diff -u -r1.179 config.h.in
--- include/config.h.in	5 Feb 2004 01:27:38 -0000	1.179
+++ include/config.h.in	1 Mar 2004 02:45:55 -0000
@@ -2,6 +2,12 @@
 
 #define __WINE_CONFIG_H
 
+/* Specifies the compiler flag needed to build shared libraries */
+#undef CC_FLAG_SHARED_LIBS
+
+/* Specifies the compiler flag that forces a short wchar_t */
+#undef CC_FLAG_SHORT_WCHAR
+
 /* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
    systems. This function is required for `alloca.c' support on those systems.
    */
@@ -791,6 +797,15 @@
 /* Define if we have __va_copy */
 #undef HAVE___VA_COPY
 
+/* Defined to 1 if we use GCC, 0 otherwise */
+#undef IS_CC_GCC
+
+/* Defined to 1 if we use GXX, 0 otherwise */
+#undef IS_CXX_GXX
+
+/* Flags needed to link a DLL */
+#undef LDDLLFLAGS
+
 /* Define to disable all debug messages. */
 #undef NO_DEBUG_MSGS
 
@@ -812,6 +827,15 @@
 /* Define to the version of this package. */
 #undef PACKAGE_VERSION
 
+/* Specifies the C compiler */
+#undef PROG_CC
+
+/* Specifies the C Pre-Processor */
+#undef PROG_CPP
+
+/* Specifies the C++ compiler */
+#undef PROG_CXX
+
 /* The size of a `long long', as computed by sizeof. */
 #undef SIZEOF_LONG_LONG
 
@@ -857,9 +881,9 @@
 /* If using the C implementation of alloca, define if you know the
    direction of stack growth for your system; otherwise it will be
    automatically deduced at run-time.
-	STACK_DIRECTION > 0 => grows toward higher addresses
-	STACK_DIRECTION < 0 => grows toward lower addresses
-	STACK_DIRECTION = 0 => direction of growth unknown */
+        STACK_DIRECTION > 0 => grows toward higher addresses
+        STACK_DIRECTION < 0 => grows toward lower addresses
+        STACK_DIRECTION = 0 => direction of growth unknown */
 #undef STACK_DIRECTION
 
 /* Define if the struct statfs is defined by <sys/mount.h> */
@@ -902,8 +926,6 @@
 /* Define to empty if `const' does not conform to ANSI C. */
 #undef const
 
-/* Define to `__inline__' or `__inline' if that's what the C compiler
-   calls it, or to nothing if 'inline' is not supported under any name.  */
-#ifndef __cplusplus
+/* Define as `__inline' if that's what the C compiler calls it, or to nothing
+   if it is not supported. */
 #undef inline
-#endif
Index: tools/winegcc/utils.c
===================================================================
RCS file: /var/cvs/wine/tools/winegcc/utils.c,v
retrieving revision 1.5
diff -u -r1.5 utils.c
--- tools/winegcc/utils.c	26 Feb 2004 05:28:35 -0000	1.5
+++ tools/winegcc/utils.c	1 Mar 2004 02:41:43 -0000
@@ -118,6 +118,14 @@
     arr->base[arr->size++] = str;
 }
 
+void strarray_addall(strarray* arr, const strarray* from)
+{
+    int i;
+
+    for (i = 0; i < from->size; i++)
+	strarray_add(arr, from->base[i]);
+}
+
 strarray* strarray_dup(const strarray* arr)
 {
     strarray* dup = strarray_alloc();
@@ -127,6 +135,35 @@
 	strarray_add(dup, arr->base[i]);
 
     return dup;
+}
+
+strarray* strarray_fromstring(const char* str, const char* delim)
+{
+    strarray* arr = strarray_alloc();
+    char* buf = strdup(str);
+    const char* tok;
+
+    for(tok = strtok(buf, delim); tok; tok = strtok(0, delim))
+	strarray_add(arr, strdup(tok));
+
+    free(buf);
+    return arr;
+}
+
+char* strarray_tostring(const strarray* arr, const char* sep)
+{
+    char *str, *newstr;
+    int i;
+
+    str = strmake("%s", arr->base[0]);
+    for (i = 1; i < arr->size; i++)
+    {
+	newstr = strmake("%s%s%s", str, sep, arr->base[i]);
+	free(str);
+	str = newstr;
+    }
+
+    return str;
 }
 
 char* get_basename(const char* file)
Index: tools/winegcc/utils.h
===================================================================
RCS file: /var/cvs/wine/tools/winegcc/utils.h,v
retrieving revision 1.4
diff -u -r1.4 utils.h
--- tools/winegcc/utils.h	26 Feb 2004 05:28:35 -0000	1.4
+++ tools/winegcc/utils.h	1 Mar 2004 02:31:34 -0000
@@ -21,7 +21,17 @@
  */
 
 
-void error(const char* s, ...);
+#ifndef DECLSPEC_NORETURN
+# if defined(_MSC_VER) && (_MSC_VER >= 1200) && !defined(MIDL_PASS)
+#  define DECLSPEC_NORETURN __declspec(noreturn)
+# elif defined(__GNUC__)
+#  define DECLSPEC_NORETURN __attribute__((noreturn))
+# else
+#  define DECLSPEC_NORETURN
+# endif
+#endif
+
+void error(const char* s, ...) DECLSPEC_NORETURN;
 
 void* xmalloc(size_t size);
 void* xrealloc(void* p, size_t size);
@@ -38,6 +48,9 @@
 strarray* strarray_dup(const strarray* arr);
 void strarray_free(strarray* arr);
 void strarray_add(strarray* arr, const char* str);
+void strarray_addall(strarray* arr, const strarray* from);
+strarray* strarray_fromstring(const char* str, const char* delim);
+char* strarray_tostring(const strarray* arr, const char* sep);
 
 typedef enum { 
     file_na, file_other, file_obj, file_res,
Index: tools/winegcc/winegcc.c
===================================================================
RCS file: /var/cvs/wine/tools/winegcc/winegcc.c,v
retrieving revision 1.8
diff -u -r1.8 winegcc.c
--- tools/winegcc/winegcc.c	26 Feb 2004 05:28:35 -0000	1.8
+++ tools/winegcc/winegcc.c	1 Mar 2004 02:32:17 -0000
@@ -161,6 +161,7 @@
     int nostdinc;
     int nostdlib;
     int nodefaultlibs;
+    int noshortwchar;
     int gui_app;
     int compile_only;
     const char* output_name;
@@ -199,32 +200,42 @@
     return tmp;
 }
 
-static const char* get_translator(struct options* args)
+static const char* get_translator(struct options* opts)
 {
-    const char* cc = proc_cc; /* keep compiler happy */
-
-    switch(args->processor)
+    switch(opts->processor)
     {
-	case proc_pp:  cc = "cpp"; break;
-	case proc_cc:  cc = "gcc"; break;
-	case proc_cpp: cc = "g++"; break;
-	default: error("Unknown processor");
+        case proc_pp:  return PROG_CPP;
+        case proc_cc:  return PROG_CC;
+        case proc_cpp: return PROG_CXX;
     }
-
-    return cc;
+    error("Unknown processor");
 }
 
 static void compile(struct options* opts)
 {
     strarray *comp_args = strarray_alloc();
-    int j;
+    int j, gcc_defs = 0;
 
+    switch(opts->processor)
+    {
+	case proc_pp:  gcc_defs = 1;
+	case proc_cc:  gcc_defs = IS_CC_GCC; break;
+	case proc_cpp: gcc_defs = IS_CXX_GXX; break;
+    }
     strarray_add(comp_args, get_translator(opts));
 
     if (opts->processor != proc_pp)
     {
-        strarray_add(comp_args, "-fshort-wchar");
-        strarray_add(comp_args, "-fPIC");
+#ifdef CC_FLAG_SHORT_WCHAR
+	if (!opts->noshortwchar)
+	{
+            strarray_add(comp_args, CC_FLAG_SHORT_WCHAR);
+            strarray_add(comp_args, "-DWINE_UNICODE_NATIVE");
+	}
+#endif
+#ifdef CC_FLAG_SHARED_LIBS
+        strarray_add(comp_args, CC_FLAG_SHARED_LIBS);
+#endif
     }
     if (!opts->nostdinc)
     {
@@ -242,33 +253,38 @@
     strarray_add(comp_args, "-D__WINNT");
     strarray_add(comp_args, "-D__WINNT__");
 
-    strarray_add(comp_args, "-D__stdcall=__attribute__((__stdcall__))");
-    strarray_add(comp_args, "-D__cdecl=__attribute__((__cdecl__))");
-    strarray_add(comp_args, "-D__fastcall=__attribute__((__fastcall__))");
-    strarray_add(comp_args, "-D_stdcall=__attribute__((__stdcall__))");
-    strarray_add(comp_args, "-D_cdecl=__attribute__((__cdecl__))");
-    strarray_add(comp_args, "-D_fastcall=__attribute__((__fastcall__))");
-    strarray_add(comp_args, "-D__declspec(x)=__declspec_##x");
-    strarray_add(comp_args, "-D__declspec_align(x)=__attribute__((aligned(x)))");
-    strarray_add(comp_args, "-D__declspec_allocate(x)=__attribute__((section(x)))");
-    strarray_add(comp_args, "-D__declspec_deprecated=__attribute__((deprecated))");
-    strarray_add(comp_args, "-D__declspec_dllimport=__attribute__((dllimport))");
-    strarray_add(comp_args, "-D__declspec_dllexport=__attribute__((dllexport))");
-    strarray_add(comp_args, "-D__declspec_naked=__attribute__((naked))");
-    strarray_add(comp_args, "-D__declspec_noinline=__attribute__((noinline))");
-    strarray_add(comp_args, "-D__declspec_noreturn=__attribute__((noreturn))");
-    strarray_add(comp_args, "-D__declspec_nothrow=__attribute__((nothrow))");
-    strarray_add(comp_args, "-D__declspec_novtable=__attribute__(())"); /* ignore it */
-    strarray_add(comp_args, "-D__declspec_selectany=__attribute__((weak))");
-    strarray_add(comp_args, "-D__declspec_thread=__thread");
+    if (gcc_defs)
+    {
+	strarray_add(comp_args, "-D__stdcall=__attribute__((__stdcall__))");
+	strarray_add(comp_args, "-D__cdecl=__attribute__((__cdecl__))");
+	strarray_add(comp_args, "-D__fastcall=__attribute__((__fastcall__))");
+	strarray_add(comp_args, "-D_stdcall=__attribute__((__stdcall__))");
+	strarray_add(comp_args, "-D_cdecl=__attribute__((__cdecl__))");
+	strarray_add(comp_args, "-D_fastcall=__attribute__((__fastcall__))");
+	strarray_add(comp_args, "-D__declspec(x)=__declspec_##x");
+	strarray_add(comp_args, "-D__declspec_align(x)=__attribute__((aligned(x)))");
+	strarray_add(comp_args, "-D__declspec_allocate(x)=__attribute__((section(x)))");
+	strarray_add(comp_args, "-D__declspec_deprecated=__attribute__((deprecated))");
+	strarray_add(comp_args, "-D__declspec_dllimport=__attribute__((dllimport))");
+	strarray_add(comp_args, "-D__declspec_dllexport=__attribute__((dllexport))");
+	strarray_add(comp_args, "-D__declspec_naked=__attribute__((naked))");
+	strarray_add(comp_args, "-D__declspec_noinline=__attribute__((noinline))");
+	strarray_add(comp_args, "-D__declspec_noreturn=__attribute__((noreturn))");
+	strarray_add(comp_args, "-D__declspec_nothrow=__attribute__((nothrow))");
+	strarray_add(comp_args, "-D__declspec_novtable=__attribute__(())"); /* ignore it */
+	strarray_add(comp_args, "-D__declspec_selectany=__attribute__((weak))");
+	strarray_add(comp_args, "-D__declspec_thread=__thread");
+    }
 
     /* Wine specific defines */
     strarray_add(comp_args, "-D__WINE__");
-    strarray_add(comp_args, "-DWINE_UNICODE_NATIVE");
     strarray_add(comp_args, "-D__int8=char");
     strarray_add(comp_args, "-D__int16=short");
+    /* FIXME: what about 64-bit platforms? */
     strarray_add(comp_args, "-D__int32=int");
+#ifdef HAVE_LONG_LONG
     strarray_add(comp_args, "-D__int64=long long");
+#endif
 
     /* options we handle explicitly */
     if (opts->compile_only)
@@ -439,8 +455,10 @@
     /* compile the .spec.c file into a .spec.o file */
     comp_args = strarray_alloc();
     spec_o_name = get_temp_file(base_name, ".spec.o");
-    strarray_add(comp_args, "gcc");
-    strarray_add(comp_args, "-fPIC");
+    strarray_add(comp_args, PROG_CC);
+#ifdef CC_FLAG_SHARED_LIBS
+    strarray_add(comp_args, CC_FLAG_SHARED_LIBS);
+#endif
     strarray_add(comp_args, "-o");
     strarray_add(comp_args, spec_o_name);
     strarray_add(comp_args, "-c");
@@ -451,12 +469,7 @@
     /* link everything together now */
     link_args = strarray_alloc();
     strarray_add(link_args, get_translator(opts));
-    strarray_add(link_args, "-shared");
-#ifdef HAVE_LINKER_INIT_FINI
-    strarray_add(link_args, "-Wl,-Bsymbolic,-z,defs,-init,__wine_spec_init,-fini,__wine_spec_fini");
-#else
-    strarray_add(link_args, "-Wl,-Bsymbolic,-z,defs");
-#endif
+    strarray_addall(link_args, strarray_fromstring(LDDLLFLAGS, " "));
 
     strarray_add(link_args, "-o");
     strarray_add(link_args, strmake("%s.exe.so", base_file));
@@ -679,6 +692,10 @@
                 case 'E':        /* preprocess only */
                     if (argv[i][2] == 0) linking = 0;
                     break;
+		case 'f':
+		    if (strcmp("-fno-short-wchar", argv[i]) == 0)
+                        opts.noshortwchar = 1;
+		    break;
 		case 'l':
 		    strarray_add(opts.lib_names, option_arg);
 		    break;


-- 
Dimi.




More information about the wine-patches mailing list