Mac OS X Support (patch with diff -u)

Pierre d'Herbemont stegefin at free.fr
Sun Apr 27 15:09:43 CDT 2003


Hi,
Here is a patch which mostly enables compilation on Mac OS X. The 
support is not full as there is still some makefiles issues on which I 
can't find a *clean* correction and a new issue I discovered in this 
cvs version related to the libwine_port and the getopt function.

Sorry for the -u option, I thought it was enabled by default :(

ChangeLog:
   * configure.ac
     configure
     Add Mac OS X Support, including Mach-O.
     Fix PowerPC recognition

   * Make.rules.in:
     Add the LDDYLIB definition for Mach-O support.

   * libs/wine/Makefile.in,
     libs/unicode/Makefile.in:
     Add Mach-O support, add target for .dylib

   * dlls/Makedll.rules.in
     Add an entry for .dylib building

   * tools/winebuild/import.c
     tools/winebuild/spec32.c
     Mac OS X linker does not support the same syntax as linux linker, 
add a case for darwin

   * scheduler/process.c
     Add support for the environ of darwin.

   * scheduler/sysdeps.c
     include/winnt.h
     For darwin the TEB should be in r13, fix it.

   * loader/module.c
     Add Mach-O recognition for executable.

   * libs/port/interlocked.c
     Add r0 preservation in interlocked functions in order lwarx to be 
effective and change ';' into '\n'.

Pierre d'Herbemont <stegefin at free.fr>

Thanks.

-------------- next part --------------
? .DS_Store
? patch.diff.txt
? dlls/.DS_Store
? include/.DS_Store
? libs/port/.DS_Store
? libs/unicode/.DS_Store
? libs/wine/.DS_Store
? loader/.DS_Store
? scheduler/.DS_Store
? tools/.DS_Store
? tools/winebuild/.DS_Store
Index: Make.rules.in
===================================================================
RCS file: /home/wine/wine/Make.rules.in,v
retrieving revision 1.155
diff -u -r1.155 Make.rules.in
--- Make.rules.in	21 Apr 2003 23:54:06 -0000	1.155
+++ Make.rules.in	27 Apr 2003 20:04:18 -0000
@@ -34,6 +34,7 @@
 DLLEXT    = @DLLEXT@
 IMPLIBEXT = @IMPLIBEXT@
 LDSHARED  = @LDSHARED@
+LDDYLIB   = @LDDYLIB@
 DLLTOOL   = @DLLTOOL@
 DLLWRAP   = @DLLWRAP@
 AR        = @AR@ rc
Index: configure.ac
===================================================================
RCS file: /home/wine/wine/configure.ac,v
retrieving revision 1.152
diff -u -r1.152 configure.ac
--- configure.ac	27 Apr 2003 00:47:59 -0000	1.152
+++ configure.ac	27 Apr 2003 20:05:17 -0000
@@ -777,6 +777,7 @@
 AC_SUBST(DLLIBS,"")
 AC_SUBST(LDDLLFLAGS,"")
 AC_SUBST(LDSHARED,"")
+AC_SUBST(LDDYLIB,"")
 AC_SUBST(LIBEXT,"so")
 AC_SUBST(IMPLIBEXT,"def")
 
@@ -792,6 +793,56 @@
     fi
     IMPLIBEXT="a"
     ;;
+  darwin*|macosx*)
+    AC_CHECK_HEADERS(dlfcn.h,
+        [AC_CHECK_FUNCS(dlopen,,
+          [AC_CHECK_LIB(dl,dlopen,
+             [AC_DEFINE(HAVE_DLOPEN,1,[Define if you have dlopen])
+              DLLIBS="-ldl"],
+          [have_dlcompat="no"])])],
+        [have_dlcompat="no"])
+    if test "$have_dlcompat" = "no"
+    then
+      echo
+      echo "*** Error: No dlcompat found,"
+      echo "***        install it in order to build wine on Mac OS X/Darwin"
+      exit
+    fi
+    
+    AC_CHECK_LIB(poll,poll,
+       [AC_DEFINE(HAVE_DLPOLL,1,[Define if you have lpoll])
+        LIBS="$LIBS -lpoll"],
+       [have_lpoll="no"])
+    
+    if test "$have_lpoll" = "no"
+    then
+      echo
+      echo "*** Error: No lpoll found,"
+      echo "***        install it in order to build wine on Mac OS X/Darwin"
+      exit
+    fi
+
+    AC_CHECK_HEADERS(mach-o/loader.h,
+       [AC_DEFINE(HAVE_MACHO_LOADER_H,1,[Define if you have mach-o/loader.h])],
+       [have_macho_loader_h="no"])
+
+    if test "$have_lpoll" = "no"
+    then
+      echo
+      echo "*** Error: No Macho header found,"
+      echo "***        mach-o/loader.h should be installed with the developer tools"
+      echo "***        install them in order to build wine on Mac OS X/Darwin"
+      exit
+    fi
+    AC_DEFINE(USE_MACHO,1,[Define if you use mach-o])
+    
+    CFLAGS="-no-cpp-precomp"
+    LDSHARED="\$(CC) -bundle -flat_namespace -undefined suppress"
+    LDDLLFLAGS=""
+    LIBEXT=dylib
+    AC_SUBST(LDDYLIB,"\$(CC) -dynamiclib -single_module -flat_namespace -undefined suppress")
+    DLLEXT=".so"
+  ;;
   *)
     AC_CHECK_HEADERS(dlfcn.h,
         [AC_CHECK_FUNCS(dlopen,,
@@ -868,6 +919,8 @@
 case $build_os in
   cygwin*|mingw32*)
     AC_SUBST(LDPATH,"PATH=\"\$(TOOLSDIR)/libs/unicode:\$\$PATH\"") ;;
+  darwin*|macosx*)
+    AC_SUBST(LDPATH,"DYLD_LIBRARY_PATH=\"\$(TOOLSDIR)/library:\$(TOOLSDIR)/unicode:\$\$PATH\"") ;;
   *)
     AC_SUBST(LDPATH,"LD_LIBRARY_PATH=\"\$(TOOLSDIR)/libs/unicode:\$\$LD_LIBRARY_PATH\"") ;;
 esac
@@ -1295,10 +1348,17 @@
   *i[[3456789]]86*) WINE_CHECK_DEFINE([__i386__]) ;;
   *alpha*)          WINE_CHECK_DEFINE([__ALPHA__]) ;;
   *sparc*)          WINE_CHECK_DEFINE([__sparc__]) ;;
+dnl for the powerpc it seems to be two flags, FIXME : they should be unified
+  *powerpc*)        WINE_CHECK_DEFINE([__powerpc__])
+                    WINE_CHECK_DEFINE([__PPC__]) ;;
 esac
 
 case $host_vendor in
   *sun*) WINE_CHECK_DEFINE([__sun__]) ;;
+esac
+
+case $host_os in
+  *darwin*|macosx*) WINE_CHECK_DEFINE([__darwin__]) ;;
 esac
 
 dnl **** Generate output files ****
Index: dlls/Makedll.rules.in
===================================================================
RCS file: /home/wine/wine/dlls/Makedll.rules.in,v
retrieving revision 1.55
diff -u -r1.55 Makedll.rules.in
--- dlls/Makedll.rules.in	21 Apr 2003 23:54:06 -0000	1.55
+++ dlls/Makedll.rules.in	27 Apr 2003 20:05:17 -0000
@@ -34,6 +34,10 @@
 	$(LDCOMBINE) $(ALL_OBJS) -o $@
 	-$(STRIP) --strip-unneeded $@
 
+# Rule for .dylib files
+$(MODULE).dylib: $(MAINSPEC).o $(ALL_OBJS) Makefile.in
+	$(LDSHARED) $(LDDLLFLAGS) $(MAINSPEC).o $(ALL_OBJS) -o $@ -L$(DLLDIR) $(LDIMPORTS:%=-l%) $(ALL_LIBS) -lc
+
 # Rule for 16-bit glue
 
 $(MODULE).glue.c: $(C_SRCS) $(C_SRCS16) $(WINEBUILD)
Index: include/winnt.h
===================================================================
RCS file: /home/wine/wine/include/winnt.h,v
retrieving revision 1.157
diff -u -r1.157 winnt.h
--- include/winnt.h	10 Apr 2003 00:19:25 -0000	1.157
+++ include/winnt.h	27 Apr 2003 20:05:36 -0000
@@ -1632,7 +1632,11 @@
 extern inline struct _TEB * WINAPI NtCurrentTeb(void)
 {
     struct _TEB *teb;
+# ifdef __darwin
+    __asm__("\tmr %0, r13" : "=r" (teb));
+# else
     __asm__("\tmr %0, 2" : "=r" (teb));
+# endif
     return teb;
 }
 #else
Index: libs/port/interlocked.c
===================================================================
RCS file: /home/wine/wine/libs/port/interlocked.c,v
retrieving revision 1.1
diff -u -r1.1 interlocked.c
--- libs/port/interlocked.c	20 Mar 2003 22:06:16 -0000	1.1
+++ libs/port/interlocked.c	27 Apr 2003 20:05:37 -0000
@@ -107,11 +107,11 @@
     long ret = 0;
     long scratch;
     __asm__ __volatile__(
-        "0:    lwarx %0,0,%2 ;"
+        "0:    lwarx %0,0,%2 \n"
         "      xor. %1,%4,%0;"
-        "      bne 1f;"
-        "      stwcx. %3,0,%2;"
-        "      bne- 0b;"
+        "      bne 1f\n"
+        "      stwcx. %3,0,%2\n"
+        "      bne- 0b\n"
         "1:    "
         : "=&r"(ret), "=&r"(scratch)
         : "r"(dest), "r"(xchg), "r"(compare)
@@ -124,15 +124,15 @@
     long ret = 0;
     long scratch;
     __asm__ __volatile__(
-        "0:    lwarx %0,0,%2 ;"
-        "      xor. %1,%4,%0;"
-        "      bne 1f;"
-        "      stwcx. %3,0,%2;"
-        "      bne- 0b;"
+        "0:    lwarx %0,0,%2 \n"
+        "      xor. %1,%4,%0\n"
+        "      bne 1f\n"
+        "      stwcx. %3,0,%2\n"
+        "      bne- 0b\n"
         "1:    "
         : "=&r"(ret), "=&r"(scratch)
         : "r"(dest), "r"(xchg), "r"(compare)
-        : "cr0","memory");
+        : "cr0","memory","r0");
     return ret;
 }
 
@@ -141,13 +141,13 @@
     long ret = 0;
     long zero = 0;
     __asm__ __volatile__(
-        "0:    lwarx %0, %3, %1;"
-        "      add %0, %2, %0;"
-        "      stwcx. %0, %3, %1;"
-        "      bne- 0b;"
+        "0:    lwarx %0, %3, %1\n"
+        "      add %0, %2, %0\n"
+        "      stwcx. %0, %3, %1\n"
+        "      bne- 0b\n"
         : "=&r" (ret)
         : "r"(dest), "r"(incr), "r"(zero)
-        : "cr0", "memory"
+        : "cr0", "memory", "r0"
     );
     return ret-incr;
 }
@@ -156,12 +156,12 @@
 {
     long ret = 0;
     __asm__ __volatile__(
-        "0:    lwarx %0,0,%1 ;"
-        "      stwcx. %2,0,%1;"
-        "      bne- 0b;"
+        "0:    lwarx %0,0,%1 \n"
+        "      stwcx. %2,0,%1\n"
+        "      bne- 0b\n"
         : "=&r"(ret)
         : "r"(dest), "r"(val)
-        : "cr0","memory");
+        : "cr0","memory","r0");
     return ret;
 }
 
@@ -169,12 +169,12 @@
 {
     void *ret = NULL;
     __asm__ __volatile__(
-        "0:    lwarx %0,0,%1 ;"
-        "      stwcx. %2,0,%1;"
-        "      bne- 0b;"
+        "0:    lwarx %0,0,%1 \n"
+        "      stwcx. %2,0,%1 \n"
+        "      bne- 0b \n"
         : "=&r"(ret)
         : "r"(dest), "r"(val)
-        : "cr0","memory");
+        : "cr0","memory","r0");
     return ret;
 }
 
Index: libs/unicode/Makefile.in
===================================================================
RCS file: /home/wine/wine/libs/unicode/Makefile.in,v
retrieving revision 1.3
diff -u -r1.3 Makefile.in
--- libs/unicode/Makefile.in	23 Mar 2003 20:11:45 -0000	1.3
+++ libs/unicode/Makefile.in	27 Apr 2003 20:05:37 -0000
@@ -85,6 +85,12 @@
 
 @MAKE_RULES@
 
+libwine_unicode.$(SOVERSION).dylib: $(OBJS) Makefile.in
+	$(LDDYLIB) $(OBJS) -o $@
+
+libwine_unicode.dylib: libwine_unicode.$(SOVERSION).dylib
+	$(RM) $@ && $(LN_S) libwine_unicode.$(SOVERSION).dylib $@
+
 libwine_unicode.so.$(SOVERSION): $(OBJS) Makefile.in
 	$(LDSHARED) $(OBJS) -o $@
 
@@ -97,7 +103,11 @@
 libwine_unicode.dll: $(OBJS) wine_unicode.def Makefile.in
 	$(DLLWRAP) --def $(SRCDIR)/wine_unicode.def -o $@ $(OBJS)
 
-.PHONY: install-lib-so install-lib-dll install-dev-so install-dev-dll
+.PHONY: install-lib-dylib install-lib-so install-lib-dll install-dev-so install-dev-dll
+
+install-lib-dylib: libwine_unicode.$(SOVERSION).dylib dummy
+	$(MKINSTALLDIRS) $(libdir)
+	$(INSTALL_PROGRAM) libwine_unicode.$(SOVERSION).dylib $(libdir)/libwine_unicode.$(SOVERSION).dylib
 
 install-lib-so: libwine_unicode.so.$(SOVERSION) dummy
 	$(MKINSTALLDIRS) $(libdir)
@@ -107,6 +117,10 @@
 	$(MKINSTALLDIRS) $(libdir)
 	$(INSTALL_DATA) libwine_unicode.dll $(libdir)/libwine_unicode.dll
 
+install-dev-dylib: dummy
+	$(MKINSTALLDIRS) $(libdir)
+	cd $(libdir) && $(RM) libwine_unicode.dylib && $(LN_S) libwine_unicode.$(SOVERSION).dylib libwine_unicode.dylib
+
 install-dev-so: dummy
 	$(MKINSTALLDIRS) $(libdir)
 	cd $(libdir) && $(RM) libwine_unicode.so && $(LN_S) libwine_unicode.so.$(SOVERSION) libwine_unicode.so
@@ -119,9 +133,9 @@
 install install-dev:: $(LIBEXT:%=install-dev-%)
 
 uninstall::
-	$(RM) $(libdir)/libwine_unicode.a $(libdir)/libwine_unicode.dll $(libdir)/libwine_unicode.so $(libdir)/libwine_unicode.so.$(SOVERSION)
+	$(RM) $(libdir)/libwine_unicode.a $(libdir)/libwine_unicode.dll $(libdir)/libwine_unicode.so $(libdir)/libwine_unicode.so.$(SOVERSION) $(libdir)/libwine_unicode.dylib $(libdir)/libwine_unicode.$(SOVERSION).dylib
 
 clean::
-	$(RM) libwine_unicode.so.$(SOVERSION) libwine_unicode.dll
+	$(RM) libwine_unicode.so.$(SOVERSION) libwine_unicode.dll libwine_unicode.$(SOVERSION).dylib
 
 ### Dependencies:
Index: libs/wine/Makefile.in
===================================================================
RCS file: /home/wine/wine/libs/wine/Makefile.in,v
retrieving revision 1.2
diff -u -r1.2 Makefile.in
--- libs/wine/Makefile.in	23 Mar 2003 00:28:53 -0000	1.2
+++ libs/wine/Makefile.in	27 Apr 2003 20:05:38 -0000
@@ -20,6 +20,12 @@
 
 @MAKE_RULES@
 
+libwine.$(SOVERSION).dylib: $(OBJS)
+	$(LDDYLIB) $(OBJS) $(EXTRALIBS) $(LIBS) -o $@
+        
+libwine.dylib: libwine.$(SOVERSION).dylib
+	$(RM) $@ && $(LN_S) libwine.$(SOVERSION).dylib $@
+
 libwine.so.$(SOVERSION): $(OBJS) Makefile.in
 	$(LDSHARED) $(OBJS) $(EXTRALIBS) $(LIBS) -o $@
 
@@ -32,7 +38,11 @@
 libwine.dll: $(OBJS) wine.def Makefile.in
 	$(DLLWRAP) --def $(SRCDIR)/wine.def -o $@ $(OBJS) $(EXTRALIBS)
 
-.PHONY: install-lib-so install-lib-dll install-dev-so install-dev-dll
+.PHONY: install-lib-dylib install-lib-so install-lib-dll install-dev-so install-dev-dll
+
+install-lib-dylib: libwine.$(SOVERSION).dylib dummy
+	$(MKINSTALLDIRS) $(libdir)
+	$(INSTALL_PROGRAM) libwine.$(SOVERSION).dylib $(libdir)/libwine.$(SOVERSION).dylib
 
 install-lib-so: libwine.so.$(SOVERSION) dummy
 	$(MKINSTALLDIRS) $(libdir)
@@ -42,6 +52,10 @@
 	$(MKINSTALLDIRS) $(libdir)
 	$(INSTALL_DATA) libwine.dll $(libdir)/libwine.dll
 
+install-dev-dylib: dummy
+	$(MKINSTALLDIRS) $(libdir)
+	cd $(libdir) && $(RM) libwine.dylib && $(LN_S) libwine.$(SOVERSION).dylib libwine.dylib
+
 install-dev-so: dummy
 	$(MKINSTALLDIRS) $(libdir)
 	cd $(libdir) && $(RM) libwine.so && $(LN_S) libwine.so.$(SOVERSION) libwine.so
@@ -54,9 +68,9 @@
 install install-dev:: $(LIBEXT:%=install-dev-%)
 
 uninstall::
-	$(RM) $(libdir)/libwine.a $(libdir)/libwine.dll $(libdir)/libwine.so $(libdir)/libwine.so.$(SOVERSION)
+	$(RM) $(libdir)/libwine.a $(libdir)/libwine.dll $(libdir)/libwine.so $(libdir)/libwine.so.$(SOVERSION) $(libdir)/libwine.dylib $(libdir)/libwine.$(SOVERSION).dylib
 
 clean::
-	$(RM) libwine.so.$(SOVERSION) libwine.dll
+	$(RM) libwine.so.$(SOVERSION) libwine.dll libwine.$(SOVERSION).dylib
 
 ### Dependencies:
Index: loader/module.c
===================================================================
RCS file: /home/wine/wine/loader/module.c,v
retrieving revision 1.182
diff -u -r1.182 module.c
--- loader/module.c	5 Apr 2003 05:13:33 -0000	1.182
+++ loader/module.c	27 Apr 2003 20:05:42 -0000
@@ -30,6 +30,9 @@
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #endif
+#ifdef HAVE_MACHO_LOADER_H_
+# include <mach-o/loader.h>
+#endif
 #include "wine/winbase16.h"
 #include "winerror.h"
 #include "winternl.h"
@@ -255,6 +258,18 @@
             unsigned char ignored[12];
             unsigned short type;
         } elf;
+#ifdef USE_MACHO
+        struct
+        {
+            unsigned long magic;
+            unsigned long cputype;
+            unsigned long cpusubtype;
+            unsigned long filetype;
+            unsigned long ncmds;
+            unsigned long sizeofcmds;
+            unsigned long flags;
+        } macho;
+#endif /* USE_MACHO */
         IMAGE_DOS_HEADER mz;
     } header;
 
@@ -277,6 +292,30 @@
         }
         return BINARY_UNKNOWN;
     }
+    
+#ifdef USE_MACHO
+    /* Mach-o File with Endian set to Big Endian */
+    if (header.macho.magic == 0xfeedface)
+    {
+         /* FIXME: we don't bother to check byte order, architecture, etc. */
+         switch(header.macho.filetype)
+         {
+           case MH_BUNDLE: return BINARY_UNIX_LIB;
+         }
+         return BINARY_UNKNOWN;
+    }
+
+    /* Mach-o File with Endian set to Little Endian */
+    if (header.macho.magic == 0xecafdeef)
+    {
+         /* FIXME: we don't bother to check byte order, architecture, etc. */
+         switch(header.macho.filetype)
+         {
+           case MH_BUNDLE: return BINARY_UNIX_LIB;
+         }
+         return BINARY_UNKNOWN;
+    }
+#endif /* USE_MACHO */
 
     /* Not ELF, try DOS */
 
Index: scheduler/process.c
===================================================================
RCS file: /home/wine/wine/scheduler/process.c,v
retrieving revision 1.213
diff -u -r1.213 process.c
--- scheduler/process.c	27 Apr 2003 00:47:58 -0000	1.213
+++ scheduler/process.c	27 Apr 2003 20:05:52 -0000
@@ -32,6 +32,11 @@
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #endif
+#ifdef __darwin__
+# include <crt_externs.h>
+# define environ (*_NSGetEnviron())
+#endif
+
 #include "wine/winbase16.h"
 #include "wine/winuser16.h"
 #include "wine/exception.h"
Index: scheduler/sysdeps.c
===================================================================
RCS file: /home/wine/wine/scheduler/sysdeps.c,v
retrieving revision 1.65
diff -u -r1.65 sysdeps.c
--- scheduler/sysdeps.c	13 Apr 2003 01:04:25 -0000	1.65
+++ scheduler/sysdeps.c	27 Apr 2003 20:05:53 -0000
@@ -89,7 +89,11 @@
     wine_ldt_init_fs( teb->teb_sel, &fs_entry );
 #elif defined(__powerpc__)
     /* On PowerPC, the current TEB is in the gpr13 register */
+# ifdef __darwin__
+    __asm__ __volatile__("mr r13, %0" : : "r" (teb));
+# else /* __darwin__ */
     __asm__ __volatile__("mr 2, %0" : : "r" (teb));
+# endif
 #elif defined(HAVE__LWP_CREATE)
     /* On non-i386 Solaris, we use the LWP private pointer */
     _lwp_setprivate( teb );
@@ -465,7 +469,11 @@
     return (struct _TEB *)_lwp_getprivate();
 }
 #elif defined(__powerpc__)
+# ifdef __darwin__
+__ASM_GLOBAL_FUNC( NtCurrentTeb, "\n\tmr r3,r13\n\tblr" );
+# else
 __ASM_GLOBAL_FUNC( NtCurrentTeb, "\n\tmr 3,2\n\tblr" );
+# endif
 #else
 # error NtCurrentTeb not defined for this architecture
 #endif  /* __i386__ */
Index: tools/winebuild/import.c
===================================================================
RCS file: /home/wine/wine/tools/winebuild/import.c,v
retrieving revision 1.49
diff -u -r1.49 import.c
--- tools/winebuild/import.c	10 Apr 2003 18:36:40 -0000	1.49
+++ tools/winebuild/import.c	27 Apr 2003 20:05:59 -0000
@@ -819,6 +819,28 @@
             }
 
 #elif defined(__PPC__)
+/* Darwin's ld doesn't like the same asm code as linux linker... */
+# ifdef __darwin___
+            fprintf(outfile, "\taddi r1, r1, -0x4\\n\"\n");
+            fprintf(outfile, "\t\"\\tstw r9, 0(r1)\\n\"\n");
+            fprintf(outfile, "\t\"\\taddi r1, r1, -0x4\\n\"\n");
+            fprintf(outfile, "\t\"\\tstw r8, 0(r1)\\n\"\n");
+            fprintf(outfile, "\t\"\\taddi r1, r1, -0x4\\n\"\n");
+            fprintf(outfile, "\t\"\\tstw r7, 0(r1)\\n\"\n");
+
+            fprintf(outfile, "\t\"\\tlis r9,ha16(_imports+%d)\\n\"\n", pos);
+            fprintf(outfile, "\t\"\\tla r8,lo16(_imports+%d)(r9)\\n\"\n", pos);
+            fprintf(outfile, "\t\"\\tlwz r7, 0(r8)\\n\"\n");
+            fprintf(outfile, "\t\"\\tmtctr r7\\n\"\n");
+
+            fprintf(outfile, "\t\"\\tlwz r7, 0(r1)\\n\"\n");
+            fprintf(outfile, "\t\"\\taddi r1, r1, 0x4\\n\"\n");
+            fprintf(outfile, "\t\"\\tlwz r8, 0(r1)\\n\"\n");
+            fprintf(outfile, "\t\"\\taddi r1, r1, 0x4\\n\"\n");
+            fprintf(outfile, "\t\"\\tlwz r9, 0(r1)\\n\"\n");
+            fprintf(outfile, "\t\"\\taddi r1, r1, 0x4\\n\"\n");
+            fprintf(outfile, "\t\"\\tbctr\\n");
+# else /* __darwin___ */
             fprintf(outfile, "\taddi 1, 1, -0x4\\n\"\n");
             fprintf(outfile, "\t\"\\tstw 9, 0(1)\\n\"\n");
             fprintf(outfile, "\t\"\\taddi 1, 1, -0x4\\n\"\n");
@@ -838,6 +860,7 @@
             fprintf(outfile, "\t\"\\tlwz 9, 0(1)\\n\"\n");
             fprintf(outfile, "\t\"\\taddi 1, 1, 0x4\\n\"\n");
             fprintf(outfile, "\t\"\\tbctr\\n");
+# endif /* __darwin___ */
 #else
 #error You need to define import thunks for your architecture!
 #endif
@@ -845,7 +868,13 @@
         }
         pos += 4;
     }
+
+/* darwin and Mach-o have a different behavior */
+#ifdef __darwin__
+    fprintf( outfile, "\".text\");\n#ifndef __GNUC__\n}\n#endif\n\n" );
+#else
     fprintf( outfile, "\".section\\t\\\".text\\\"\");\n#ifndef __GNUC__\n}\n#endif\n\n" );
+#endif /* __darwin__ */
 
  done:
     return nb_imm;
@@ -968,6 +997,11 @@
     fprintf( outfile, "#ifndef __GNUC__\n" );
     fprintf( outfile, "static void __asm__dummy_delay_import(void) {\n" );
     fprintf( outfile, "#endif\n" );
+    
+#ifdef __darwin__
+    /* darwin likes this one */
+    fprintf( outfile, "\"\\t.data\\n\"" );
+#endif
 
     fprintf( outfile, "asm(\".align %d\\n\"\n", get_alignment(8) );
     fprintf( outfile, "    \"\\t" __ASM_FUNC("__wine_delay_load_asm") "\\n\"\n" );
@@ -982,6 +1016,53 @@
     fprintf( outfile, "    \"\\tmov %%g1, %%o0\\n\"\n" );
     fprintf( outfile, "    \"\\tjmp %%o0\\n\\trestore\\n\"\n" );
 #elif defined(__PPC__)
+# ifdef __darwin__
+    /* Save all callee saved registers into a stackframe. */
+    fprintf( outfile, "    \"\\tstwu r1, -48(r1)\\n\"\n" );
+    fprintf( outfile, "    \"\\tstw Êr3, 4(r1)\\n\"\n" );
+    fprintf( outfile, "    \"\\tstw Êr4, 8(r1)\\n\"\n" );
+    fprintf( outfile, "    \"\\tstw Êr5, 12(r1)\\n\"\n" );
+    fprintf( outfile, "    \"\\tstw Êr6, 16(r1)\\n\"\n" );
+    fprintf( outfile, "    \"\\tstw Êr7, 20(r1)\\n\"\n" );
+    fprintf( outfile, "    \"\\tstw Êr8, 24(r1)\\n\"\n" );
+    fprintf( outfile, "    \"\\tstw Êr9, 28(r1)\\n\"\n" );
+    fprintf( outfile, "    \"\\tstw Êr10, 32(r1)\\n\"\n" );
+    fprintf( outfile, "    \"\\tstw Êr11, 36(r1)\\n\"\n" );
+    fprintf( outfile, "    \"\\tstw Êr12, 40(r1)\\n\"\n" );
+
+    /* r0 -> r3 (arg1) */
+    fprintf( outfile, "    \"\\tmr Êr3, r0\\n\"\n" );
+
+    /* save return address */
+    fprintf( outfile, "    \"\\tmflr Êr0\\n\"\n" );
+    fprintf( outfile, "    \"\\tstw Êr0, 44(r1)\\n\"\n" );
+
+    /* Call the __wine_delay_load function, arg1 is arg1. */
+    fprintf( outfile, "    \"\\tbl __wine_delay_load\\n\"\n" );
+
+    /* Load return value from call into ctr register */
+    fprintf( outfile, "    \"\\tmtctr r3\\n\"\n" );
+
+    /* restore all saved registers and drop stackframe. */
+    fprintf( outfile, "    \"\\tlwz Êr3, 4(r1)\\n\"\n" );
+    fprintf( outfile, "    \"\\tlwz Êr4, 8(r1)\\n\"\n" );
+    fprintf( outfile, "    \"\\tlwz Êr5, 12(r1)\\n\"\n" );
+    fprintf( outfile, "    \"\\tlwz Êr6, 16(r1)\\n\"\n" );
+    fprintf( outfile, "    \"\\tlwz Êr7, 20(r1)\\n\"\n" );
+    fprintf( outfile, "    \"\\tlwz Êr8, 24(r1)\\n\"\n" );
+    fprintf( outfile, "    \"\\tlwz Êr9, 28(r1)\\n\"\n" );
+    fprintf( outfile, "    \"\\tlwz Êr10, 32(r1)\\n\"\n" );
+    fprintf( outfile, "    \"\\tlwz Êr11, 36(r1)\\n\"\n" );
+    fprintf( outfile, "    \"\\tlwz Êr12, 40(r1)\\n\"\n" );
+
+    /* Load return value from call into return register */
+    fprintf( outfile, "    \"\\tlwz Êr0, 44(r1)\\n\"\n" );
+    fprintf( outfile, "    \"\\tmtlr r0\\n\"\n" );
+    fprintf( outfile, "    \"\\taddi r1, r1, 48\\n\"\n" );
+
+    /* branch to ctr register. */
+    fprintf( outfile, "    \"\\tbctr\\n\"\n" );
+# else /* __darwin__ */
     /* Save all callee saved registers into a stackframe. */
     fprintf( outfile, "    \"\\tstwu %%r1, -48(%%r1)\\n\"\n" );
     fprintf( outfile, "    \"\\tstw  %%r3, 4(%%r1)\\n\"\n" );
@@ -1025,7 +1106,7 @@
     fprintf( outfile, "    \"\\taddi %%r1, %%r1, 48\\n\"\n" );
     /* branch to ctr register. */
     fprintf( outfile, "    \"\\tbctr\\n\"\n" );
-
+# endif /* __darwin__ */
 #else
 #error You need to defined delayed import thunks for your architecture!
 #endif
@@ -1092,6 +1173,28 @@
             }
 
 #elif defined(__PPC__)
+# ifdef __darwin__
+            fprintf(outfile, "\t\"addi 1, 1, -0x4\\n\"\n");
+            fprintf(outfile, "\t\"\\tstw 9, 0(1)\\n\"\n");
+            fprintf(outfile, "\t\"\\taddi 1, 1, -0x4\\n\"\n");
+            fprintf(outfile, "\t\"\\tstw 8, 0(1)\\n\"\n");
+            fprintf(outfile, "\t\"\\taddi 1, 1, -0x4\\n\"\n");
+            fprintf(outfile, "\t\"\\tstw 7, 0(1)\\n\"\n");
+
+            fprintf(outfile, "\t\"\\tlis 9,ha16(_delay_imports+%d)\\n\"\n", pos);
+            fprintf(outfile, "\t\"\\tla 8,lo16(_delay_imports+%d)(9)\\n\"\n", pos);
+            fprintf(outfile, "\t\"\\tlwz 7, 0(8)\\n\"\n");
+            fprintf(outfile, "\t\"\\tmtctr 7\\n\"\n");
+
+            fprintf(outfile, "\t\"\\tlwz 7, 0(1)\\n\"\n");
+            fprintf(outfile, "\t\"\\taddi 1, 1, 0x4\\n\"\n");
+            fprintf(outfile, "\t\"\\tlwz 8, 0(1)\\n\"\n");
+            fprintf(outfile, "\t\"\\taddi 1, 1, 0x4\\n\"\n");
+            fprintf(outfile, "\t\"\\tlwz 9, 0(1)\\n\"\n");
+
+            fprintf(outfile, "\t\"\\taddi 1, 1, 0x4\\n\"\n");
+            fprintf(outfile, "\t\"\\tbctr\\n\"");
+# else /* __darwine__*/ 
             fprintf(outfile, "\t\"addi 1, 1, -0x4\\n\"\n");
             fprintf(outfile, "\t\"\\tstw 9, 0(1)\\n\"\n");
             fprintf(outfile, "\t\"\\taddi 1, 1, -0x4\\n\"\n");
@@ -1116,12 +1219,20 @@
             fprintf(outfile, "\t\"lwz r0, %d(r0)\\n\\t\"\n", pos);
             fprintf(outfile, "\t\"mtctr r0\\n\\t\"\n");
             fprintf(outfile, "\t\"bctr\\n\"");*/
+# endif /* __darwin__ */
 #else
 #error You need to define delayed import thunks for your architecture!
 #endif
             fprintf( outfile, "\n" );
         }
     }
+    
+#ifdef __darwin__
+    fprintf( outfile, "\".text\");\n" );
+#else /* __darwin__ */
+    fprintf( outfile, "\".section \\\".text\\\"\");\n" );
+#endif /* __darwin__ */
+
     fprintf( outfile, "\".section \\\".text\\\"\");\n" );
     fprintf( outfile, "#ifndef __GNUC__\n" );
     fprintf( outfile, "}\n" );
Index: tools/winebuild/spec32.c
===================================================================
RCS file: /home/wine/wine/tools/winebuild/spec32.c,v
retrieving revision 1.65
diff -u -r1.65 spec32.c
--- tools/winebuild/spec32.c	3 Apr 2003 18:05:17 -0000	1.65
+++ tools/winebuild/spec32.c	27 Apr 2003 20:06:03 -0000
@@ -429,6 +429,20 @@
         fprintf( outfile, "    \"\\t.section\\t\\\".text\\\"\\n\");\n" );
     }
 #elif defined(__PPC__)
+# ifdef __darwin__
+    if (constructor)
+    {
+        fprintf( outfile, "asm(\"\\t.section .init,ax\\n\"\n" );
+        fprintf( outfile, "    \"\\tbl " __ASM_NAME("%s") "\\n\"\n", constructor );
+        fprintf( outfile, "    \"\\t.text\\n\");\n" );
+    }
+    if (destructor)
+    {
+        fprintf( outfile, "asm(\"\\t.section .fini,ax\\n\"\n" );
+        fprintf( outfile, "    \"\\tbl " __ASM_NAME("%s") "\\n\"\n", destructor );
+        fprintf( outfile, "    \"\\t.text\\n\");\n" );
+    }
+# else /* __darwin__ */
     if (constructor)
     {
         fprintf( outfile, "asm(\"\\t.section\\t\\\".init\\\" ,\\\"ax\\\"\\n\"\n" );
@@ -441,6 +455,7 @@
         fprintf( outfile, "    \"\\tbl " __ASM_NAME("%s") "\\n\"\n", destructor );
         fprintf( outfile, "    \"\\t.section\\t\\\".text\\\"\\n\");\n" );
     }
+# endif /* __darwin__ */
 #else
 #error You need to define the DLL constructor for your architecture
 #endif
@@ -489,7 +504,11 @@
     fprintf( outfile, "#ifndef __GNUC__\n" );
     fprintf( outfile, "static void __asm__dummy_header(void) {\n" );
     fprintf( outfile, "#endif\n" );
+#ifdef __darwin__
+    fprintf( outfile, "asm(\".text\\n\\t\"\n" );
+#else
     fprintf( outfile, "asm(\".section \\\".text\\\"\\n\\t\"\n" );
+#endif
     fprintf( outfile, "    \".align %d\\n\"\n", get_alignment(page_size) );
     fprintf( outfile, "    \"" __ASM_NAME("pe_header") ":\\t.skip 65536\\n\\t\");\n" );
     fprintf( outfile, "#ifndef __GNUC__\n" );
@@ -546,7 +565,11 @@
         else
         {
             fprintf( outfile, "#ifdef __GNUC__\n" );
+            fprintf( outfile, "# ifdef __darwin__\n" );
+            fprintf( outfile, "extern void DllMain() __attribute__((weak_import));\n" );
+            fprintf( outfile, "# else\n" );
             fprintf( outfile, "extern void DllMain() __attribute__((weak));\n" );
+            fprintf( outfile, "# endif\n" );
             fprintf( outfile, "#else\n" );
             fprintf( outfile, "extern void DllMain();\n" );
             fprintf( outfile, "static void __asm__dummy_dllmain(void)" );
@@ -920,7 +943,11 @@
     fprintf( outfile, "    \"\\tbl " __ASM_NAME("__wine_dbg_%s_init") "\\n\"\n", prefix );
     fprintf( outfile, "    \"\\t.section\\t\\\".fini\\\" ,\\\"ax\\\"\\n\"\n" );
     fprintf( outfile, "    \"\\tbl " __ASM_NAME("__wine_dbg_%s_fini") "\\n\"\n", prefix );
+# ifdef __darwin__
+    fprintf( outfile, "    \"\\t.text\\n\");\n" );
+# else
     fprintf( outfile, "    \"\\t.section\\t\\\".text\\\"\\n\");\n" );
+# endif
 #else
 #error You need to define the DLL constructor for your architecture
 #endif


More information about the wine-patches mailing list