Fixed bug 938 - SDL fails to link in mingw+msys+libtool SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Fri, 30 Dec 2011 14:14:45 -0500
branchSDL-1.2
changeset 6130 987c365cc7bf
parent 6129 19c7412a6345
child 6131 804c6c62c55f
Fixed bug 938 - SDL fails to link in mingw+msys+libtool Carlo Bramini 2010-01-27 10:06:17 PST When building third party software powered by libtool (like xine-lib and several others) under Mingw+MSys, libSDL fails to link. I got this message when building SDL video out component of xine-lib: *** Warning: linker path does not have real file for library -lmingw32. *** I have the capability to make that library automatically link in when *** you link to this library. But I can only do this if you have a *** shared version of the library, which you do not appear to have *** because I did check the linker path looking for a file starting *** with libmingw32 and none of the candidates passed a file format test *** using a file magic. Last file checked: /mingw/lib/libmingw32.a Apparently there is no need to manually add -lmingw32 for making libSDL working. If this flag is removed, everything is built without troubles. If it has been added for fixing a cross-compiler, perhaps if would be a better idea to adjust its SPECS file in the same manner it has been done in the true one used by mingw on Windows (I'm just guessing why it exists here). There is also another message received on the console: *** Warning: linker path does not have real file for library -lSDLmain. *** I have the capability to make that library automatically link in when *** you link to this library. But I can only do this if you have a *** shared version of the library, which you do not appear to have *** because I did check the linker path looking for a file starting *** with libSDLmain and none of the candidates passed a file format test *** using a file magic. Last file checked: /mingw/lib/libSDLmain.a This message, like previous one, is caused by -no-undefined flag sent to libtool when building shared libraries. Actually adding an .la file with its dependencies solves the troubles, so I believe it would be better to create it too in the build process of libSDL.
Makefile.in
SDL.qpg.in
build-scripts/makedep.sh
configure.in
--- a/Makefile.in	Fri Dec 30 06:54:58 2011 -0500
+++ b/Makefile.in	Fri Dec 30 14:14:45 2011 -0500
@@ -36,9 +36,10 @@
 SOURCES = @SOURCES@
 OBJECTS = @OBJECTS@
 
-SDLMAIN_TARGET = libSDLmain.a
+SDLMAIN_TARGET = libSDLmain.la
 SDLMAIN_SOURCES = @SDLMAIN_SOURCES@
 SDLMAIN_OBJECTS = @SDLMAIN_OBJECTS@
+SDLMAIN_LDFLAGS = @SDLMAIN_LDFLAGS@
 
 DIST = acinclude autogen.sh Borland.html Borland.zip BUGS build-scripts configure configure.in COPYING CREDITS CWprojects.sea.bin docs docs.html include INSTALL Makefile.dc Makefile.minimal Makefile.in MPWmake.sea.bin README* sdl-config.in sdl.m4 sdl.pc.in SDL.qpg.in SDL.spec SDL.spec.in src test TODO VisualCE VisualC.html VisualC Watcom-OS2.zip Watcom-Win32.zip symbian.zip WhatsNew Xcode
 
@@ -65,22 +66,17 @@
 
 .PHONY: all depend install install-bin install-hdrs install-lib install-data install-man uninstall uninstall-bin uninstall-hdrs uninstall-lib uninstall-data uninstall-man clean distclean dist
 depend:
-	@SOURCES="$(SOURCES)" INCLUDE="$(INCLUDE)" output="$(depend)" \
+	@SOURCES="$(SOURCES) $(SDLMAIN_SOURCES)" INCLUDE="$(INCLUDE)" output="$(depend)" \
 	$(SHELL) $(auxdir)/makedep.sh
-	@for src in $(SDLMAIN_SOURCES); do \
-	    obj=`echo $$src | sed -e 's|.*/||' -e 's|\.[^\.]*$$|.o|'`; \
-	    echo "\$$(objects)/$$obj: $$src" >>$(depend); \
-	    echo "	\$$(CC) \$$(CFLAGS) \$$(EXTRA_CFLAGS) -c $$src -o \$$@" >>$(depend); \
-	done
 
 include $(depend)
 
 $(objects)/$(TARGET): $(OBJECTS)
-	$(LIBTOOL) --mode=link $(CC) -o $@ $(OBJECTS) $(LDFLAGS) $(EXTRA_LDFLAGS) $(LT_LDFLAGS)
+	$(LIBTOOL) --mode=link $(CC) -o $@ $^ $(LDFLAGS) $(EXTRA_LDFLAGS) $(LT_LDFLAGS)
 
 $(objects)/$(SDLMAIN_TARGET): $(SDLMAIN_OBJECTS)
-	$(AR) cru $@ $(SDLMAIN_OBJECTS)
-	$(RANLIB) $@
+	$(LIBTOOL) --mode=link $(CC) -o $@ $^ $(LDFLAGS) $(EXTRA_LDFLAGS) $(LT_LDFLAGS) $(SDLMAIN_LDFLAGS)
+
 
 install: all install-bin install-hdrs install-lib install-data install-man
 install-bin:
@@ -95,8 +91,7 @@
 install-lib: $(objects) $(objects)/$(TARGET) $(objects)/$(SDLMAIN_TARGET)
 	$(SHELL) $(auxdir)/mkinstalldirs $(DESTDIR)$(libdir)
 	$(LIBTOOL) --mode=install $(INSTALL) $(objects)/$(TARGET) $(DESTDIR)$(libdir)/$(TARGET)
-	$(INSTALL) -m 644 $(objects)/$(SDLMAIN_TARGET) $(DESTDIR)$(libdir)/$(SDLMAIN_TARGET)
-	$(RANLIB) $(DESTDIR)$(libdir)/$(SDLMAIN_TARGET)
+	$(LIBTOOL) --mode=install $(INSTALL) $(objects)/$(SDLMAIN_TARGET) $(DESTDIR)$(libdir)/$(SDLMAIN_TARGET)
 install-data:
 	$(SHELL) $(auxdir)/mkinstalldirs $(DESTDIR)$(datadir)/aclocal
 	$(INSTALL) -m 644 $(srcdir)/sdl.m4 $(DESTDIR)$(datadir)/aclocal/sdl.m4
@@ -120,7 +115,7 @@
 	-rmdir $(DESTDIR)$(includedir)/SDL
 uninstall-lib:
 	$(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libdir)/$(TARGET)
-	rm -f $(DESTDIR)$(libdir)/$(SDLMAIN_TARGET)
+	$(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libdir)/$(SDLMAIN_TARGET)
 uninstall-data:
 	rm -f $(DESTDIR)$(datadir)/aclocal/sdl.m4
 	rm -f $(DESTDIR)$(libdir)/pkgconfig/sdl.pc
--- a/SDL.qpg.in	Fri Dec 30 06:54:58 2011 -0500
+++ b/SDL.qpg.in	Fri Dec 30 14:14:45 2011 -0500
@@ -28,7 +28,8 @@
          <QPG:Add filetype="symlink" file="libSDL.so" install="/usr/lib/" linkto="libSDL-@SDL_MAJOR_VERSION@.@SDL_MINOR_VERSION@.so.@LT_AGE@"/>
          <QPG:Add permissions="0644" file="./src/.libs/libSDL.a" install="/usr/lib/"/>
          <QPG:Add permissions="0644" file="./src/.libs/libSDL.lai" install="/usr/lib/libSDL.la"/>
-         <QPG:Add permissions="0644" file="./src/main/libSDLmain.a" install="/usr/lib/"/>
+         <QPG:Add permissions="0644" file="./src/.libs/libSDLmain.a" install="/usr/lib/"/>
+         <QPG:Add permissions="0644" file="./src/.libs/libSDLmain.lai" install="/usr/lib/libSDLmain.lai"/>
          <QPG:Add permissions="0644" file="./include/*.h" install="/usr/include/SDL/"/>
          <QPG:Add permissions="0755" file="./sdl-config" install="/usr/bin/"/>
          <QPG:Add permissions="0644" file="./BUGS" install="/usr/share/doc/SDL12/"/>
--- a/build-scripts/makedep.sh	Fri Dec 30 06:54:58 2011 -0500
+++ b/build-scripts/makedep.sh	Fri Dec 30 14:14:45 2011 -0500
@@ -41,13 +41,13 @@
 for src in $SOURCES
 do  echo "Generating dependencies for $src"
     ext=`echo $src | sed 's|.*\.\(.*\)|\1|'`
-    if test x"$ext" = x"rc"; then
-        obj=`echo $src | sed "s|^.*/\([^ ]*\)\..*|\1.o|g"`
-    else
-        obj=`echo $src | sed "s|^.*/\([^ ]*\)\..*|\1.lo|g"`
+    obj=`echo $src | sed "s|^.*/\([^ ]*\)\..*|\1.lo|g"`
+    echo "\$(objects)/$obj: $src \\" >>${output}.new
+
+    # No search to be done with Windows resource files
+    if test x"$ext" != x"rc"; then
+        search_deps $src | sort | uniq >>${output}.new
     fi
-    echo "\$(objects)/$obj: $src \\" >>${output}.new
-    search_deps $src | sort | uniq >>${output}.new
     case $ext in
         c) cat >>${output}.new <<__EOF__
 
@@ -81,7 +81,7 @@
         ;;
         rc) cat >>${output}.new <<__EOF__
 
-	\$(WINDRES) $src \$@
+	\$(LIBTOOL)  --tag=RC --mode=compile \$(WINDRES) $src -o \$@
 
 __EOF__
         ;;
--- a/configure.in	Fri Dec 30 06:54:58 2011 -0500
+++ b/configure.in	Fri Dec 30 14:14:45 2011 -0500
@@ -1556,6 +1556,7 @@
             AC_DEFINE(SDL_VIDEO_DRIVER_QTOPIA)
             SOURCES="$SOURCES $srcdir/src/video/qtopia/*.cc"
             SDLMAIN_SOURCES="$srcdir/src/main/qtopia/*.cc"
+            SDLMAIN_LDFLAGS="-static"
             EXTRA_CFLAGS="$EXTRA_CFLAGS $QTOPIA_FLAGS"
             SDL_CFLAGS="$SDL_CFLAGS -DQWS -Dmain=SDL_main"
             SDL_LIBS="-lSDLmain $SDL_LIBS -L${QPEDIR}/lib -L${QTDIR}/lib/ -lqpe -lqte"
@@ -2548,8 +2549,9 @@
         # The Win32 platform requires special setup
         SOURCES="$SOURCES $srcdir/src/main/win32/*.rc"
         SDLMAIN_SOURCES="$srcdir/src/main/win32/*.c"
+        SDLMAIN_LDFLAGS="-static"
         SDL_CFLAGS="$SDL_CFLAGS -Dmain=SDL_main"
-        SDL_LIBS="-lmingw32 -lSDLmain $SDL_LIBS -mwindows"
+        SDL_LIBS="-lSDLmain $SDL_LIBS -mwindows"
         ;;
     *-wince*)
         ARCH=win32
@@ -2591,6 +2593,7 @@
         EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lcoredll -lcommctrl"
         # The Win32 platform requires special setup
         SDLMAIN_SOURCES="$srcdir/src/main/win32/*.c"
+        SDLMAIN_LDFLAGS="-static"
         SDL_CFLAGS="$SDL_CFLAGS -Dmain=SDL_main -D_WIN32_WCE=0x420"
         SDL_LIBS="-lSDLmain $SDL_LIBS"
         ;;
@@ -2722,6 +2725,7 @@
         fi
         # The Mac OS X platform requires special setup.
         SDLMAIN_SOURCES="$srcdir/src/main/macosx/*.m"
+        SDLMAIN_LDFLAGS="-static"
         EXTRA_CFLAGS="$EXTRA_CFLAGS -fpascal-strings"
         SDL_LIBS="-lSDLmain $SDL_LIBS"
         if test x$enable_video_cocoa = xyes; then
@@ -2858,6 +2862,7 @@
 fi
 if test x$SDLMAIN_SOURCES = x; then
     SDLMAIN_SOURCES="$srcdir/src/main/dummy/*.c"
+    SDLMAIN_LDFLAGS="-static"
 fi
 
 OBJECTS=`echo $SOURCES | sed 's,[[^ ]]*/\([[^ ]]*\)\.asm,$(objects)/\1.lo,g'`
@@ -2865,11 +2870,11 @@
 OBJECTS=`echo $OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.m,$(objects)/\1.lo,g'`
 OBJECTS=`echo $OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.c,$(objects)/\1.lo,g'`
 OBJECTS=`echo $OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.S,$(objects)/\1.lo,g'`
-OBJECTS=`echo $OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.rc,$(objects)/\1.o,g'`
+OBJECTS=`echo $OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.rc,$(objects)/\1.lo,g'`
 
-SDLMAIN_OBJECTS=`echo $SDLMAIN_SOURCES | sed 's,[[^ ]]*/\([[^ ]]*\)\.cc,$(objects)/\1.o,g'`
-SDLMAIN_OBJECTS=`echo $SDLMAIN_OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.m,$(objects)/\1.o,g'`
-SDLMAIN_OBJECTS=`echo $SDLMAIN_OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.c,$(objects)/\1.o,g'`
+SDLMAIN_OBJECTS=`echo $SDLMAIN_SOURCES | sed 's,[[^ ]]*/\([[^ ]]*\)\.cc,$(objects)/\1.lo,g'`
+SDLMAIN_OBJECTS=`echo $SDLMAIN_OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.m,$(objects)/\1.lo,g'`
+SDLMAIN_OBJECTS=`echo $SDLMAIN_OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.c,$(objects)/\1.lo,g'`
 
 # Set runtime shared library paths as needed
 
@@ -2931,6 +2936,7 @@
 AC_SUBST(OBJECTS)
 AC_SUBST(SDLMAIN_SOURCES)
 AC_SUBST(SDLMAIN_OBJECTS)
+AC_SUBST(SDLMAIN_LDFLAGS)
 AC_SUBST(BUILD_CFLAGS)
 AC_SUBST(EXTRA_CFLAGS)
 AC_SUBST(BUILD_LDFLAGS)