Re: [libav-devel] [PATCH] Add support for building shared libraries with MSVC

2012-10-13 Thread Martin Storsjö

On Sat, 13 Oct 2012, Diego Biurrun wrote:


On Sat, Oct 13, 2012 at 01:46:38PM +0300, Martin Storsjö wrote:


--- a/configure
+++ b/configure
@@ -2778,14 +2778,33 @@ case $target_os in
 shlibdir_default="$bindir_default"
 SLIBPREF=""
 SLIBSUF=".dll"
+if enabled_all msvc shared; then
+# Link to the import library instead of the
+# normal static library.
+LD_LIB='%.lib'
+fi
 SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
 SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
-SLIB_EXTRA_CMD=-'$(DLLTOOL) -m $(LIBTARGET) -d $$(@:$(SLIBSUF)=.def) 
-l $(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib) -D $(SLIBNAME_WITH_MAJOR)'
+if enabled msvc; then
+# The libtarget names for lib.exe differ from the ones for dlltool
+if enabled x86_64; then
+LIBTARGET=x64
+fi
+SLIB_CREATE_DEF_CMD='makedef $(SUBDIR)lib$(NAME).ver $(OBJS) > 
$$(@:$(SLIBSUF)=.def)'
+SLIB_EXTRA_CMD='-lib.exe -machine:$(LIBTARGET) 
-def:$$(@:$(SLIBSUF)=.def) -out:$(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib)'
+else
+SLIB_EXTRA_CMD=-'$(DLLTOOL) -m $(LIBTARGET) -d 
$$(@:$(SLIBSUF)=.def) -l $(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib) -D 
$(SLIBNAME_WITH_MAJOR)'
+fi
 SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
 SLIB_INSTALL_LINKS=
 SLIB_INSTALL_EXTRA_SHLIB='$(SLIBNAME:$(SLIBSUF)=.lib)'
-SLIB_INSTALL_EXTRA_LIB='lib$(SLIBNAME:$(SLIBSUF)=.dll.a) 
$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
-SHFLAGS='-shared -Wl,--output-def,$$(@:$(SLIBSUF)=.def) 
-Wl,--out-implib,$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) 
-Wl,--enable-runtime-pseudo-reloc -Wl,--enable-auto-image-base'
+if enabled msvc; then
+SLIB_INSTALL_EXTRA_LIB='$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
+SHFLAGS='-dll -def:$$(@:$(SLIBSUF)=.def) 
-implib:$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a)'
+else
+SLIB_INSTALL_EXTRA_LIB='lib$(SLIBNAME:$(SLIBSUF)=.dll.a) 
$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
+SHFLAGS='-shared -Wl,--output-def,$$(@:$(SLIBSUF)=.def) 
-Wl,--out-implib,$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) 
-Wl,--enable-runtime-pseudo-reloc -Wl,--enable-auto-image-base'
+fi
 objformat="win32"
 dlltool="${cross_prefix}dlltool"
 ranlib=:


I suggest to separate the MinGW and MSVC sections completely.  That would
be both more readable and more maintainable.  I fear that otherwise
changes for one system will break the other.


@@ -3521,6 +3540,8 @@ elif enabled pathscale; then
 add_cflags -fstrict-overflow -OPT:wrap_around_unsafe_opt=OFF
 elif enabled msvc; then
 enabled x86_32 && disable aligned_stack
+enabled_all shared static &&
+die "Cannot build shared and static libraries at the same time with 
MSVC"


End in a period.


--- a/libavcodec/ac3tab.h
+++ b/libavcodec/ac3tab.h
@@ -24,6 +24,7 @@

 #include "libavutil/common.h"
 #include "ac3.h"
+#include "symbols.h"

@@ -33,7 +34,7 @@

 extern const uint8_t  ff_ac3_channels_tab[8];
-extern const uint16_t avpriv_ac3_channel_layout_tab[8];
+extern AVCODEC_SYMBOL const uint16_t avpriv_ac3_channel_layout_tab[8];
 extern const uint8_t  ff_ac3_enc_channel_map[8][2][6];


What's the verdict wrt cross-library (data) symbols.  What shall we do
about them?


About this, the only ones left now are private ones, so the current 
solution doesn't have to be permanent, since it's not visible in the 
public installed headers (in previous iterations, a flag for whether the 
build is shared had to be added to the installed avconfig.h).


// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] Add support for building shared libraries with MSVC

2012-10-13 Thread Diego Biurrun
On Sat, Oct 13, 2012 at 01:46:38PM +0300, Martin Storsjö wrote:
> 
> --- a/configure
> +++ b/configure
> @@ -2778,14 +2778,33 @@ case $target_os in
>  shlibdir_default="$bindir_default"
>  SLIBPREF=""
>  SLIBSUF=".dll"
> +if enabled_all msvc shared; then
> +# Link to the import library instead of the
> +# normal static library.
> +LD_LIB='%.lib'
> +fi
>  
> SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
>  SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
> -SLIB_EXTRA_CMD=-'$(DLLTOOL) -m $(LIBTARGET) -d $$(@:$(SLIBSUF)=.def) 
> -l $(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib) -D $(SLIBNAME_WITH_MAJOR)'
> +if enabled msvc; then
> +# The libtarget names for lib.exe differ from the ones for 
> dlltool
> +if enabled x86_64; then
> +LIBTARGET=x64
> +fi
> +SLIB_CREATE_DEF_CMD='makedef $(SUBDIR)lib$(NAME).ver $(OBJS) > 
> $$(@:$(SLIBSUF)=.def)'
> +SLIB_EXTRA_CMD='-lib.exe -machine:$(LIBTARGET) 
> -def:$$(@:$(SLIBSUF)=.def) -out:$(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib)'
> +else
> +SLIB_EXTRA_CMD=-'$(DLLTOOL) -m $(LIBTARGET) -d 
> $$(@:$(SLIBSUF)=.def) -l $(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib) -D 
> $(SLIBNAME_WITH_MAJOR)'
> +fi
>  SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
>  SLIB_INSTALL_LINKS=
>  SLIB_INSTALL_EXTRA_SHLIB='$(SLIBNAME:$(SLIBSUF)=.lib)'
> -SLIB_INSTALL_EXTRA_LIB='lib$(SLIBNAME:$(SLIBSUF)=.dll.a) 
> $(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
> -SHFLAGS='-shared -Wl,--output-def,$$(@:$(SLIBSUF)=.def) 
> -Wl,--out-implib,$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) 
> -Wl,--enable-runtime-pseudo-reloc -Wl,--enable-auto-image-base'
> +if enabled msvc; then
> +SLIB_INSTALL_EXTRA_LIB='$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
> +SHFLAGS='-dll -def:$$(@:$(SLIBSUF)=.def) 
> -implib:$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a)'
> +else
> +SLIB_INSTALL_EXTRA_LIB='lib$(SLIBNAME:$(SLIBSUF)=.dll.a) 
> $(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
> +SHFLAGS='-shared -Wl,--output-def,$$(@:$(SLIBSUF)=.def) 
> -Wl,--out-implib,$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) 
> -Wl,--enable-runtime-pseudo-reloc -Wl,--enable-auto-image-base'
> +fi
>  objformat="win32"
>  dlltool="${cross_prefix}dlltool"
>  ranlib=:

I suggest to separate the MinGW and MSVC sections completely.  That would
be both more readable and more maintainable.  I fear that otherwise
changes for one system will break the other.

> @@ -3521,6 +3540,8 @@ elif enabled pathscale; then
>  add_cflags -fstrict-overflow -OPT:wrap_around_unsafe_opt=OFF
>  elif enabled msvc; then
>  enabled x86_32 && disable aligned_stack
> +enabled_all shared static &&
> +die "Cannot build shared and static libraries at the same time with 
> MSVC"

End in a period.

> --- a/libavcodec/ac3tab.h
> +++ b/libavcodec/ac3tab.h
> @@ -24,6 +24,7 @@
>  
>  #include "libavutil/common.h"
>  #include "ac3.h"
> +#include "symbols.h"
>  
> @@ -33,7 +34,7 @@
>  
>  extern const uint8_t  ff_ac3_channels_tab[8];
> -extern const uint16_t avpriv_ac3_channel_layout_tab[8];
> +extern AVCODEC_SYMBOL const uint16_t avpriv_ac3_channel_layout_tab[8];
>  extern const uint8_t  ff_ac3_enc_channel_map[8][2][6];

What's the verdict wrt cross-library (data) symbols.  What shall we do
about them?

Diego
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] Add support for building shared libraries with MSVC

2012-10-13 Thread Måns Rullgård
Hendrik Leppkes  writes:

> On Sat, Oct 13, 2012 at 12:55 PM, Måns Rullgård  wrote:
>> Martin Storsjö  writes:
>>
>>> diff --git a/configure b/configure
>>> index 99830d8..5480ce0 100755
>>> --- a/configure
>>> +++ b/configure
>>> @@ -2778,14 +2778,33 @@ case $target_os in
>>>  shlibdir_default="$bindir_default"
>>>  SLIBPREF=""
>>>  SLIBSUF=".dll"
>>> +if enabled_all msvc shared; then
>>> +# Link to the import library instead of the
>>> +# normal static library.
>>> +LD_LIB='%.lib'
>>> +fi
>>>  
>>> SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
>>>  SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
>>> -SLIB_EXTRA_CMD=-'$(DLLTOOL) -m $(LIBTARGET) -d 
>>> $$(@:$(SLIBSUF)=.def) -l $(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib) -D 
>>> $(SLIBNAME_WITH_MAJOR)'
>>> +if enabled msvc; then
>>> +# The libtarget names for lib.exe differ from the ones for 
>>> dlltool
>>> +if enabled x86_64; then
>>> +LIBTARGET=x64
>>> +fi
>>> +SLIB_CREATE_DEF_CMD='makedef $(SUBDIR)lib$(NAME).ver $(OBJS) > 
>>> $$(@:$(SLIBSUF)=.def)'
>>> +SLIB_EXTRA_CMD='-lib.exe -machine:$(LIBTARGET) 
>>> -def:$$(@:$(SLIBSUF)=.def) -out:$(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib)'
>>> +else
>>> +SLIB_EXTRA_CMD=-'$(DLLTOOL) -m $(LIBTARGET) -d 
>>> $$(@:$(SLIBSUF)=.def) -l $(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib) -D 
>>> $(SLIBNAME_WITH_MAJOR)'
>>> +fi
>>>  SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
>>>  SLIB_INSTALL_LINKS=
>>>  SLIB_INSTALL_EXTRA_SHLIB='$(SLIBNAME:$(SLIBSUF)=.lib)'
>>> -SLIB_INSTALL_EXTRA_LIB='lib$(SLIBNAME:$(SLIBSUF)=.dll.a) 
>>> $(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
>>> -SHFLAGS='-shared -Wl,--output-def,$$(@:$(SLIBSUF)=.def) 
>>> -Wl,--out-implib,$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) 
>>> -Wl,--enable-runtime-pseudo-reloc -Wl,--enable-auto-image-base'
>>> +if enabled msvc; then
>>> +SLIB_INSTALL_EXTRA_LIB='$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
>>> +SHFLAGS='-dll -def:$$(@:$(SLIBSUF)=.def) 
>>> -implib:$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a)'
>>> +else
>>> +SLIB_INSTALL_EXTRA_LIB='lib$(SLIBNAME:$(SLIBSUF)=.dll.a) 
>>> $(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
>>> +SHFLAGS='-shared -Wl,--output-def,$$(@:$(SLIBSUF)=.def) 
>>> -Wl,--out-implib,$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) 
>>> -Wl,--enable-runtime-pseudo-reloc -Wl,--enable-auto-image-base'
>>> +fi
>>>  objformat="win32"
>>>  dlltool="${cross_prefix}dlltool"
>>>  ranlib=:
>>
>> This is insane.  MSVC should not be using mingw32 as target-os.
>>
>
> I agree that it would be great to seperate this, however
> auto-detection uses uname, which sadly reports mingw32.
> Another rule to auto-detect it properly? Require specifying
> --target-os for such builds?

We could make --toolchain=msvc change the default.  I imagine most
people building it will be using that option.

-- 
Måns Rullgård
m...@mansr.com
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] Add support for building shared libraries with MSVC

2012-10-13 Thread Hendrik Leppkes
On Sat, Oct 13, 2012 at 12:55 PM, Måns Rullgård  wrote:
> Martin Storsjö  writes:
>
>> diff --git a/configure b/configure
>> index 99830d8..5480ce0 100755
>> --- a/configure
>> +++ b/configure
>> @@ -2778,14 +2778,33 @@ case $target_os in
>>  shlibdir_default="$bindir_default"
>>  SLIBPREF=""
>>  SLIBSUF=".dll"
>> +if enabled_all msvc shared; then
>> +# Link to the import library instead of the
>> +# normal static library.
>> +LD_LIB='%.lib'
>> +fi
>>  
>> SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
>>  SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
>> -SLIB_EXTRA_CMD=-'$(DLLTOOL) -m $(LIBTARGET) -d 
>> $$(@:$(SLIBSUF)=.def) -l $(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib) -D 
>> $(SLIBNAME_WITH_MAJOR)'
>> +if enabled msvc; then
>> +# The libtarget names for lib.exe differ from the ones for 
>> dlltool
>> +if enabled x86_64; then
>> +LIBTARGET=x64
>> +fi
>> +SLIB_CREATE_DEF_CMD='makedef $(SUBDIR)lib$(NAME).ver $(OBJS) > 
>> $$(@:$(SLIBSUF)=.def)'
>> +SLIB_EXTRA_CMD='-lib.exe -machine:$(LIBTARGET) 
>> -def:$$(@:$(SLIBSUF)=.def) -out:$(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib)'
>> +else
>> +SLIB_EXTRA_CMD=-'$(DLLTOOL) -m $(LIBTARGET) -d 
>> $$(@:$(SLIBSUF)=.def) -l $(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib) -D 
>> $(SLIBNAME_WITH_MAJOR)'
>> +fi
>>  SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
>>  SLIB_INSTALL_LINKS=
>>  SLIB_INSTALL_EXTRA_SHLIB='$(SLIBNAME:$(SLIBSUF)=.lib)'
>> -SLIB_INSTALL_EXTRA_LIB='lib$(SLIBNAME:$(SLIBSUF)=.dll.a) 
>> $(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
>> -SHFLAGS='-shared -Wl,--output-def,$$(@:$(SLIBSUF)=.def) 
>> -Wl,--out-implib,$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) 
>> -Wl,--enable-runtime-pseudo-reloc -Wl,--enable-auto-image-base'
>> +if enabled msvc; then
>> +SLIB_INSTALL_EXTRA_LIB='$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
>> +SHFLAGS='-dll -def:$$(@:$(SLIBSUF)=.def) 
>> -implib:$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a)'
>> +else
>> +SLIB_INSTALL_EXTRA_LIB='lib$(SLIBNAME:$(SLIBSUF)=.dll.a) 
>> $(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
>> +SHFLAGS='-shared -Wl,--output-def,$$(@:$(SLIBSUF)=.def) 
>> -Wl,--out-implib,$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) 
>> -Wl,--enable-runtime-pseudo-reloc -Wl,--enable-auto-image-base'
>> +fi
>>  objformat="win32"
>>  dlltool="${cross_prefix}dlltool"
>>  ranlib=:
>
> This is insane.  MSVC should not be using mingw32 as target-os.
>

I agree that it would be great to seperate this, however
auto-detection uses uname, which sadly reports mingw32.
Another rule to auto-detect it properly? Require specifying
--target-os for such builds?
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] Add support for building shared libraries with MSVC

2012-10-13 Thread Luca Barbato
On 10/13/2012 12:46 PM, Martin Storsjö wrote:
> From: "Ronald S. Bultje" 
> 
> This requires the makedef perl script by Derek, which probably will
> go into the c99-to-c89 repo. That scripts produces a .def file,
> listing the symbols to be exported, based on the gcc version
> scripts and the built object files.
> 
> To properly load non-function symbols from DLL files, the data
> symbol declarations need to have the attribute __declspec(dllimport)
> when building the calling code. (On mingw, the linker can fix this
> up automatically, which is why it has not been an issue so far.)
> 
> The __declspec(dllimport) attribute is added via a macro. Since
> it has to be present when building code that refer to these symbols,
> but not be present while building the library that exports the symbols
> themselves, the makefile is modified to add a define like
> COMPILING_ while building each library. This is used in the
> definition of the AV_SYMBOL macro - on non-MSVC compilers, it is
> empty. On MSVC, it is __declspec(dllimport) for declarations in other
> libraries than the object file currently compiled.
> 
> This also implies that code that is built to link to a certain
> library as a DLL can't link to the same library as a static library.
> Therefore, we only allow building either static or shared but not
> both at the same time.
> 
> Also, linking to DLLs is slightly different from linking to shared
> libraries on other platforms. DLLs use a thing called import
> libraries, which is basically a stub library allowing the linker
> know which symbols exist in the DLL and what name the DLL will
> have at runtime.
> 
> In mingw/gcc, the import library is usually named libfoo.dll.a,
> which goes next to a static library named libfoo.a. This allows gcc
> to pick the dynamic one, if available, from the normal -lfoo switches,
> just as it does for libfoo.a vs libfoo.so on unix. On MSVC however,
> you need to literally specify the name of the import library instead of
> the static library.
> ---
>  configure  |   27 ---
>  libavcodec/ac3tab.h|3 ++-
>  libavcodec/dca.h   |3 ++-
>  libavcodec/mjpeg.h |   15 ---
>  libavcodec/mpeg12data.h|3 ++-
>  libavcodec/mpeg4audio.h|3 ++-
>  libavcodec/mpegaudiodata.h |6 --
>  libavcodec/symbols.h   |   32 
>  library.mak|1 +
>  9 files changed, 77 insertions(+), 16 deletions(-)
>  create mode 100644 libavcodec/symbols.h
> 
> diff --git a/configure b/configure
> index 99830d8..5480ce0 100755
> --- a/configure
> +++ b/configure
> @@ -2778,14 +2778,33 @@ case $target_os in
>  shlibdir_default="$bindir_default"
>  SLIBPREF=""
>  SLIBSUF=".dll"
> +if enabled_all msvc shared; then
> +# Link to the import library instead of the
> +# normal static library.
> +LD_LIB='%.lib'
> +fi
>  
> SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
>  SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
> -SLIB_EXTRA_CMD=-'$(DLLTOOL) -m $(LIBTARGET) -d $$(@:$(SLIBSUF)=.def) 
> -l $(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib) -D $(SLIBNAME_WITH_MAJOR)'
> +if enabled msvc; then
> +# The libtarget names for lib.exe differ from the ones for 
> dlltool
> +if enabled x86_64; then
> +LIBTARGET=x64
> +fi
> +SLIB_CREATE_DEF_CMD='makedef $(SUBDIR)lib$(NAME).ver $(OBJS) > 
> $$(@:$(SLIBSUF)=.def)'
> +SLIB_EXTRA_CMD='-lib.exe -machine:$(LIBTARGET) 
> -def:$$(@:$(SLIBSUF)=.def) -out:$(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib)'
> +else
> +SLIB_EXTRA_CMD=-'$(DLLTOOL) -m $(LIBTARGET) -d 
> $$(@:$(SLIBSUF)=.def) -l $(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib) -D 
> $(SLIBNAME_WITH_MAJOR)'
> +fi
>  SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
>  SLIB_INSTALL_LINKS=
>  SLIB_INSTALL_EXTRA_SHLIB='$(SLIBNAME:$(SLIBSUF)=.lib)'
> -SLIB_INSTALL_EXTRA_LIB='lib$(SLIBNAME:$(SLIBSUF)=.dll.a) 
> $(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
> -SHFLAGS='-shared -Wl,--output-def,$$(@:$(SLIBSUF)=.def) 
> -Wl,--out-implib,$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) 
> -Wl,--enable-runtime-pseudo-reloc -Wl,--enable-auto-image-base'
> +if enabled msvc; then
> +SLIB_INSTALL_EXTRA_LIB='$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
> +SHFLAGS='-dll -def:$$(@:$(SLIBSUF)=.def) 
> -implib:$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a)'
> +else
> +SLIB_INSTALL_EXTRA_LIB='lib$(SLIBNAME:$(SLIBSUF)=.dll.a) 
> $(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
> +SHFLAGS='-shared -Wl,--output-def,$$(@:$(SLIBSUF)=.def) 
> -Wl,--out-implib,$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) 
> -Wl,--enable-runtime-pseudo-reloc -Wl,--enable-auto-image-base'
> +fi
>  objformat="win32"
>  dl

Re: [libav-devel] [PATCH] Add support for building shared libraries with MSVC

2012-10-13 Thread Måns Rullgård
Martin Storsjö  writes:

> diff --git a/configure b/configure
> index 99830d8..5480ce0 100755
> --- a/configure
> +++ b/configure
> @@ -2778,14 +2778,33 @@ case $target_os in
>  shlibdir_default="$bindir_default"
>  SLIBPREF=""
>  SLIBSUF=".dll"
> +if enabled_all msvc shared; then
> +# Link to the import library instead of the
> +# normal static library.
> +LD_LIB='%.lib'
> +fi
>  
> SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
>  SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
> -SLIB_EXTRA_CMD=-'$(DLLTOOL) -m $(LIBTARGET) -d $$(@:$(SLIBSUF)=.def) 
> -l $(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib) -D $(SLIBNAME_WITH_MAJOR)'
> +if enabled msvc; then
> +# The libtarget names for lib.exe differ from the ones for 
> dlltool
> +if enabled x86_64; then
> +LIBTARGET=x64
> +fi
> +SLIB_CREATE_DEF_CMD='makedef $(SUBDIR)lib$(NAME).ver $(OBJS) > 
> $$(@:$(SLIBSUF)=.def)'
> +SLIB_EXTRA_CMD='-lib.exe -machine:$(LIBTARGET) 
> -def:$$(@:$(SLIBSUF)=.def) -out:$(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib)'
> +else
> +SLIB_EXTRA_CMD=-'$(DLLTOOL) -m $(LIBTARGET) -d 
> $$(@:$(SLIBSUF)=.def) -l $(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib) -D 
> $(SLIBNAME_WITH_MAJOR)'
> +fi
>  SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
>  SLIB_INSTALL_LINKS=
>  SLIB_INSTALL_EXTRA_SHLIB='$(SLIBNAME:$(SLIBSUF)=.lib)'
> -SLIB_INSTALL_EXTRA_LIB='lib$(SLIBNAME:$(SLIBSUF)=.dll.a) 
> $(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
> -SHFLAGS='-shared -Wl,--output-def,$$(@:$(SLIBSUF)=.def) 
> -Wl,--out-implib,$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) 
> -Wl,--enable-runtime-pseudo-reloc -Wl,--enable-auto-image-base'
> +if enabled msvc; then
> +SLIB_INSTALL_EXTRA_LIB='$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
> +SHFLAGS='-dll -def:$$(@:$(SLIBSUF)=.def) 
> -implib:$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a)'
> +else
> +SLIB_INSTALL_EXTRA_LIB='lib$(SLIBNAME:$(SLIBSUF)=.dll.a) 
> $(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
> +SHFLAGS='-shared -Wl,--output-def,$$(@:$(SLIBSUF)=.def) 
> -Wl,--out-implib,$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) 
> -Wl,--enable-runtime-pseudo-reloc -Wl,--enable-auto-image-base'
> +fi
>  objformat="win32"
>  dlltool="${cross_prefix}dlltool"
>  ranlib=:

This is insane.  MSVC should not be using mingw32 as target-os.

-- 
Måns Rullgård
m...@mansr.com
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] Add support for building shared libraries with MSVC

2012-10-13 Thread Martin Storsjö
From: "Ronald S. Bultje" 

This requires the makedef perl script by Derek, which probably will
go into the c99-to-c89 repo. That scripts produces a .def file,
listing the symbols to be exported, based on the gcc version
scripts and the built object files.

To properly load non-function symbols from DLL files, the data
symbol declarations need to have the attribute __declspec(dllimport)
when building the calling code. (On mingw, the linker can fix this
up automatically, which is why it has not been an issue so far.)

The __declspec(dllimport) attribute is added via a macro. Since
it has to be present when building code that refer to these symbols,
but not be present while building the library that exports the symbols
themselves, the makefile is modified to add a define like
COMPILING_ while building each library. This is used in the
definition of the AV_SYMBOL macro - on non-MSVC compilers, it is
empty. On MSVC, it is __declspec(dllimport) for declarations in other
libraries than the object file currently compiled.

This also implies that code that is built to link to a certain
library as a DLL can't link to the same library as a static library.
Therefore, we only allow building either static or shared but not
both at the same time.

Also, linking to DLLs is slightly different from linking to shared
libraries on other platforms. DLLs use a thing called import
libraries, which is basically a stub library allowing the linker
know which symbols exist in the DLL and what name the DLL will
have at runtime.

In mingw/gcc, the import library is usually named libfoo.dll.a,
which goes next to a static library named libfoo.a. This allows gcc
to pick the dynamic one, if available, from the normal -lfoo switches,
just as it does for libfoo.a vs libfoo.so on unix. On MSVC however,
you need to literally specify the name of the import library instead of
the static library.
---
 configure  |   27 ---
 libavcodec/ac3tab.h|3 ++-
 libavcodec/dca.h   |3 ++-
 libavcodec/mjpeg.h |   15 ---
 libavcodec/mpeg12data.h|3 ++-
 libavcodec/mpeg4audio.h|3 ++-
 libavcodec/mpegaudiodata.h |6 --
 libavcodec/symbols.h   |   32 
 library.mak|1 +
 9 files changed, 77 insertions(+), 16 deletions(-)
 create mode 100644 libavcodec/symbols.h

diff --git a/configure b/configure
index 99830d8..5480ce0 100755
--- a/configure
+++ b/configure
@@ -2778,14 +2778,33 @@ case $target_os in
 shlibdir_default="$bindir_default"
 SLIBPREF=""
 SLIBSUF=".dll"
+if enabled_all msvc shared; then
+# Link to the import library instead of the
+# normal static library.
+LD_LIB='%.lib'
+fi
 SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
 SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
-SLIB_EXTRA_CMD=-'$(DLLTOOL) -m $(LIBTARGET) -d $$(@:$(SLIBSUF)=.def) 
-l $(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib) -D $(SLIBNAME_WITH_MAJOR)'
+if enabled msvc; then
+# The libtarget names for lib.exe differ from the ones for dlltool
+if enabled x86_64; then
+LIBTARGET=x64
+fi
+SLIB_CREATE_DEF_CMD='makedef $(SUBDIR)lib$(NAME).ver $(OBJS) > 
$$(@:$(SLIBSUF)=.def)'
+SLIB_EXTRA_CMD='-lib.exe -machine:$(LIBTARGET) 
-def:$$(@:$(SLIBSUF)=.def) -out:$(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib)'
+else
+SLIB_EXTRA_CMD=-'$(DLLTOOL) -m $(LIBTARGET) -d 
$$(@:$(SLIBSUF)=.def) -l $(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib) -D 
$(SLIBNAME_WITH_MAJOR)'
+fi
 SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
 SLIB_INSTALL_LINKS=
 SLIB_INSTALL_EXTRA_SHLIB='$(SLIBNAME:$(SLIBSUF)=.lib)'
-SLIB_INSTALL_EXTRA_LIB='lib$(SLIBNAME:$(SLIBSUF)=.dll.a) 
$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
-SHFLAGS='-shared -Wl,--output-def,$$(@:$(SLIBSUF)=.def) 
-Wl,--out-implib,$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) 
-Wl,--enable-runtime-pseudo-reloc -Wl,--enable-auto-image-base'
+if enabled msvc; then
+SLIB_INSTALL_EXTRA_LIB='$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
+SHFLAGS='-dll -def:$$(@:$(SLIBSUF)=.def) 
-implib:$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a)'
+else
+SLIB_INSTALL_EXTRA_LIB='lib$(SLIBNAME:$(SLIBSUF)=.dll.a) 
$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
+SHFLAGS='-shared -Wl,--output-def,$$(@:$(SLIBSUF)=.def) 
-Wl,--out-implib,$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) 
-Wl,--enable-runtime-pseudo-reloc -Wl,--enable-auto-image-base'
+fi
 objformat="win32"
 dlltool="${cross_prefix}dlltool"
 ranlib=:
@@ -3521,6 +3540,8 @@ elif enabled pathscale; then
 add_cflags -fstrict-overflow -OPT:wrap_around_unsafe_opt=OFF
 elif enabled msvc; then
 enabled x86_32 && disable aligned_stack
+enabled_all share