Hi, I have made some changes to the patch3, including using LN_S instead of `cp -f` (but see below).
First of all, I split it into two different patches. One for Makefile.am and configure.ac, and another for tests/Makefile.am since the changes are not directly related. A few days after I submitted the patch, I have encountered some libtool-related issue. When libtool is used to produce a DLL which depends on another DLL and its LIBNAME.dll.{lib|a} import library is used, libtool searches the linker's runtime search path (that is, PATH on windows) for file named LIBNAME*.dll and if it is not found libtool complains and refuses to produce the DLL. Example of libtool's output is in libtool-complains.txt. This means that creating aliases only for static and import libraries in not sufficient. We also need to provide an alias for the DLL as well. This is getting more complicated given that users may choose to pass libtool's `-avoid-version` to LDFLAGS. (I find using `-avoid-version` convenient for local installations). I figured out that we could use names of library files from libtool's libwinpthread.la and simply replace `winpthread` with `pthread` to build alias names. This is what patch3-1b.txt does. I also find it reasonable to comment out lines of configure.ac which create Automake conditionals COPY_STATIC and COPY_SHARED, since they are no longer used in Makefile.am. Attached patches are: patch3-1a.txt: Makefile.am and configure.ac. Does not use libwinpthread.la to build alias names. Uses hardcoded names. patch3-1b.txt: Makefile.am and configure.ac. Uses libwinpthread.la to build alias names. patch3-2.txt: tests/Makefile.am. I think using LN_S may be problematic if the library is built from Cygwin environment. It will create actual symbolic links, but native (non-cygwin/msys2) programs cannot read them. - Kirill Makurin ________________________________ From: Antonin Décimo <anto...@tarides.com> Sent: Thursday, November 7, 2024 8:36 PM To: mingw-w64-public@lists.sourceforge.net <mingw-w64-public@lists.sourceforge.net>; Kirill Makurin <maiddais...@outlook.com> Subject: Re: [Mingw-w64-public] Building winpthreads with MSVC tools Hi! Patch 1 is obviously correct. Patch 2 seems correct too. I wrote a patch series a while ago that changed the winpthreads testsuite for msvc but didn't get the time to get it merged. See the full thread here: https://sourceforge.net/p/mingw-w64/mailman/mingw-w64-public/thread/20240129165759.19120-1-antonin%40tarides.com/ Patch 3 sounds sensible too. Maybe you could try using LN_S instead of copying. For your last suggestion to detect msvc, maybe we could use AX_COMPILER_VENDOR from the Autoconf Macro Archive, or maybe the configure triplet, or maybe there's already something in Automake. https://www.gnu.org/software/autoconf-archive/ax_compiler_vendor.html Cheers, -- Antonin
*** Warning: linker path does not have real file for library -lpthread. *** 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 pthread and none of the candidates passed a file format test *** using a file magic. Last file checked: I:/x86_64-msvc-windows/lib/pthread.dll.lib *** The inter-library dependencies that have been dropped here will be *** automatically added whenever a program is linked with this library *** or is declared to -dlopen it. *** Since this library must not contain undefined symbols, *** because either the platform does not support them or *** it was explicitly requested with -no-undefined, *** libtool will only create a static version of it.
From 25c67747fab6e5f620ba1f4598799b0e69d2ef7e Mon Sep 17 00:00:00 2001 From: Kirill Makurin <maiddais...@outlook.com> Date: Tue, 12 Nov 2024 05:39:42 +0900 Subject: [PATCH 3/3] Update configure.ac and Makefile.am in mingw-w64-libraries/winpthreads Make alias for winpthread[.dll].{a|lib} as pthread[.dll].{a|lib} work with both mingw-w64 and MSVC (as used by libtool) library names. Old method worked only with mingw-w64 library names (lib*[.dll].a). Signed-off-by: Kirill Makurin <maiddais...@outlook.com> --- mingw-w64-libraries/winpthreads/Makefile.am | 61 +++++++++++++------- mingw-w64-libraries/winpthreads/configure.ac | 8 +-- 2 files changed, 45 insertions(+), 24 deletions(-) diff --git a/mingw-w64-libraries/winpthreads/Makefile.am b/mingw-w64-libraries/winpthreads/Makefile.am index 54eca7b81..f7125120f 100644 --- a/mingw-w64-libraries/winpthreads/Makefile.am +++ b/mingw-w64-libraries/winpthreads/Makefile.am @@ -29,29 +29,50 @@ fakelib_libgcc_s_a_SOURCES = fakelib_libgcc_eh_a_SOURCES = endif -lib_LIBRARIES = - -if COPY_STATIC -lib_LIBRARIES += libpthread.a -libpthread_a_SOURCES = -libpthread_a_DEPENDENCIES = libwinpthread.la -#FIXME: Use cp kludge until a better method presents itself -#libpthread_a_LIBADD = $(LT_OBJDIR)/libwinpthread.a -libpthread_a_AR = cp -f $(LT_OBJDIR)/libwinpthread.a -endif - -if COPY_SHARED -lib_LIBRARIES += libpthread.dll.a -libpthread_dll_a_SOURCES = -libpthread_dll_a_DEPENDENCIES = libwinpthread.la -#FIXME: Use cp kludge until a better method presents itself -#libpthread_dll_a_LIBADD = $(LT_OBJDIR)/libwinpthread.dll.a -libpthread_dll_a_AR = cp -f $(LT_OBJDIR)/libwinpthread.dll.a -endif - # Tell libtool how to use the resource compiler .rc.lo: $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --tag=RC --mode=compile $(RC) $(RCFLAGS) -i $< -o $@ + +# Handle pthread[.dll].{lib|a} alias when installing +install-exec-hook: + if test -f $(DESTDIR)$(bindir)/winpthread-1.dll; then \ + $(LN_S) $(DESTDIR)$(bindir)/winpthread-1.dll $(DESTDIR)$(bindir)/pthread-1.dll; \ + else \ + :; \ + fi + if test -f $(DESTDIR)$(bindir)/winpthread.dll; then \ + $(LN_S) $(DESTDIR)$(bindir)/winpthread.dll $(DESTDIR)$(bindir)/pthread.dll; \ + else \ + :; \ + fi + if test -f $(DESTDIR)$(libdir)/libwinpthread.a; then \ + $(LN_S) $(DESTDIR)$(libdir)/libwinpthread.a $(DESTDIR)$(libdir)/libpthread.a; \ + else \ + :; \ + fi + if test -f $(DESTDIR)$(libdir)/libwinpthread.dll.a; then \ + $(LN_S) $(DESTDIR)$(libdir)/libwinpthread.dll.a $(DESTDIR)$(libdir)/libpthread.dll.a; \ + else \ + :; \ + fi + if test -f $(DESTDIR)$(libdir)/winpthread.lib; then \ + $(LN_S) $(DESTDIR)$(libdir)/winpthread.lib $(DESTDIR)$(libdir)/pthread.lib; \ + else \ + :; \ + fi + if test -f $(DESTDIR)$(libdir)/winpthread.dll.lib; then \ + $(LN_S) $(DESTDIR)$(libdir)/winpthread.dll.lib $(DESTDIR)$(libdir)/pthread.dll.lib; \ + else \ + :; \ + fi + +# Likewise when uninstalling +uninstall-hook: + for file in $(DESTDIR)$(libdir)/libpthread.a $(DESTDIR)$(libdir)/libpthread.dll.a \ + $(DESTDIR)$(libdir)/pthread.lib $(DESTDIR)$(libdir)/pthread.dll.lib \ + $(DESTDIR)$(bindir)/pthread-1.dll $(DESTDIR)$(bindir)/pthread.dll; do \ + rm -f $${file}; \ + done DISTCHECK_CONFIGURE_FLAGS = --host=$(host_triplet) diff --git a/mingw-w64-libraries/winpthreads/configure.ac b/mingw-w64-libraries/winpthreads/configure.ac index 47be2d6cc..1941f93a0 100644 --- a/mingw-w64-libraries/winpthreads/configure.ac +++ b/mingw-w64-libraries/winpthreads/configure.ac @@ -36,10 +36,10 @@ LT_LANG([Windows Resource]) AC_SUBST([LT_OBJDIR],$lt_cv_objdir) -AS_VAR_IF([enable_shared], [yes], [AS_VAR_SET([copy_shared])]) -AS_VAR_IF([enable_static], [yes], [AS_VAR_SET([copy_static])]) -AM_CONDITIONAL( [COPY_SHARED], [AS_VAR_TEST_SET([copy_shared])] ) -AM_CONDITIONAL( [COPY_STATIC], [AS_VAR_TEST_SET([copy_static])] ) +dnl AS_VAR_IF([enable_shared], [yes], [AS_VAR_SET([copy_shared])]) +dnl AS_VAR_IF([enable_static], [yes], [AS_VAR_SET([copy_static])]) +dnl AM_CONDITIONAL( [COPY_SHARED], [AS_VAR_TEST_SET([copy_shared])] ) +dnl AM_CONDITIONAL( [COPY_STATIC], [AS_VAR_TEST_SET([copy_static])] ) # Checks for libraries. # FIXME: Replace `main' with a function in `-lpthread': -- 2.46.1.windows.1
From eb74a9fbf05da8d7eb993ab6ffc4f251bf85806b Mon Sep 17 00:00:00 2001 From: Kirill Makurin <maiddais...@outlook.com> Date: Wed, 13 Nov 2024 02:04:30 +0900 Subject: [PATCH 3/3] Update configure.ac and Makefile.am in mingw-w64-libraries/winpthreads Make alias for winpthread[.dll].{a|lib} as pthread[.dll].{a|lib} work with both mingw-w64 and MSVC (as used by libtool) library names. Old method worked only with mingw-w64 library names (lib*[.dll].a). Signed-off-by: Kirill Makurin <maiddais...@outlook.com> --- mingw-w64-libraries/winpthreads/Makefile.am | 68 ++++++++++++++------ mingw-w64-libraries/winpthreads/configure.ac | 8 +-- 2 files changed, 52 insertions(+), 24 deletions(-) diff --git a/mingw-w64-libraries/winpthreads/Makefile.am b/mingw-w64-libraries/winpthreads/Makefile.am index 54eca7b81..cd18373b8 100644 --- a/mingw-w64-libraries/winpthreads/Makefile.am +++ b/mingw-w64-libraries/winpthreads/Makefile.am @@ -29,29 +29,57 @@ fakelib_libgcc_s_a_SOURCES = fakelib_libgcc_eh_a_SOURCES = endif -lib_LIBRARIES = - -if COPY_STATIC -lib_LIBRARIES += libpthread.a -libpthread_a_SOURCES = -libpthread_a_DEPENDENCIES = libwinpthread.la -#FIXME: Use cp kludge until a better method presents itself -#libpthread_a_LIBADD = $(LT_OBJDIR)/libwinpthread.a -libpthread_a_AR = cp -f $(LT_OBJDIR)/libwinpthread.a -endif - -if COPY_SHARED -lib_LIBRARIES += libpthread.dll.a -libpthread_dll_a_SOURCES = -libpthread_dll_a_DEPENDENCIES = libwinpthread.la -#FIXME: Use cp kludge until a better method presents itself -#libpthread_dll_a_LIBADD = $(LT_OBJDIR)/libwinpthread.dll.a -libpthread_dll_a_AR = cp -f $(LT_OBJDIR)/libwinpthread.dll.a -endif - # Tell libtool how to use the resource compiler .rc.lo: $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --tag=RC --mode=compile $(RC) $(RCFLAGS) -i $< -o $@ +# Handle pthread[.dll].{lib|a} alias when installing +install-exec-hook: + filename=$$(grep '^dlname=' libwinpthread.la | sed -E "s|dlname='(.*)'.*|\1|"); \ + if test -n "$${filename}"; then \ + alias=$$(printf %s "$${filename}" | sed 's|winpthread|pthread|'); \ + $(LN_S) $(DESTDIR)$(bindir)/$${filename} $(DESTDIR)$(bindir)/$${alias}; \ + else \ + :; \ + fi + filename=$$(grep '^library_names=' libwinpthread.la | sed -E "s|library_names='(.*)'.*|\1|"); \ + if test -n "$${filename}"; then \ + alias=$$(printf %s "$${filename}" | sed 's|winpthread|pthread|'); \ + $(LN_S) $(DESTDIR)$(libdir)/$${filename} $(DESTDIR)$(libdir)/$${alias}; \ + else \ + :; \ + fi + filename=$$(grep '^old_library=' libwinpthread.la | sed -E "s|old_library='(.*)'.*|\1|"); \ + if test -n "$${filename}"; then \ + alias=$$(printf %s "$${filename}" | sed 's|winpthread|pthread|'); \ + $(LN_S) $(DESTDIR)$(libdir)/$${filename} $(DESTDIR)$(libdir)/$${alias}; \ + else \ + :; \ + fi + +# Likewise when uninstalling +uninstall-hook: + filename=$$(grep '^dlname=' libwinpthread.la | sed -E "s|dlname='(.*)'.*|\1|"); \ + if test -n "$${filename}"; then \ + alias=$$(printf %s "$${filename}" | sed 's|winpthread|pthread|'); \ + rm -f $(DESTDIR)$(bindir)/$${alias}; \ + else \ + :; \ + fi + filename=$$(grep '^library_names=' libwinpthread.la | sed -E "s|library_names='(.*)'.*|\1|"); \ + if test -n "$${filename}"; then \ + alias=$$(printf %s "$${filename}" | sed 's|winpthread|pthread|'); \ + rm -f $(DESTDIR)$(libdir)/$${alias}; \ + else \ + :; \ + fi + filename=$$(grep '^old_library=' libwinpthread.la | sed -E "s|old_library='(.*)'.*|\1|"); \ + if test -n "$${filename}"; then \ + alias=$$(printf %s "$${filename}" | sed 's|winpthread|pthread|'); \ + rm -f $(DESTDIR)$(libdir)/$${alias}; \ + else \ + :; \ + fi + DISTCHECK_CONFIGURE_FLAGS = --host=$(host_triplet) diff --git a/mingw-w64-libraries/winpthreads/configure.ac b/mingw-w64-libraries/winpthreads/configure.ac index 47be2d6cc..1941f93a0 100644 --- a/mingw-w64-libraries/winpthreads/configure.ac +++ b/mingw-w64-libraries/winpthreads/configure.ac @@ -36,10 +36,10 @@ LT_LANG([Windows Resource]) AC_SUBST([LT_OBJDIR],$lt_cv_objdir) -AS_VAR_IF([enable_shared], [yes], [AS_VAR_SET([copy_shared])]) -AS_VAR_IF([enable_static], [yes], [AS_VAR_SET([copy_static])]) -AM_CONDITIONAL( [COPY_SHARED], [AS_VAR_TEST_SET([copy_shared])] ) -AM_CONDITIONAL( [COPY_STATIC], [AS_VAR_TEST_SET([copy_static])] ) +dnl AS_VAR_IF([enable_shared], [yes], [AS_VAR_SET([copy_shared])]) +dnl AS_VAR_IF([enable_static], [yes], [AS_VAR_SET([copy_static])]) +dnl AM_CONDITIONAL( [COPY_SHARED], [AS_VAR_TEST_SET([copy_shared])] ) +dnl AM_CONDITIONAL( [COPY_STATIC], [AS_VAR_TEST_SET([copy_static])] ) # Checks for libraries. # FIXME: Replace `main' with a function in `-lpthread': -- 2.46.1.windows.1
From 6b27cae5f785de2839554bb9f5f64ba0cad44869 Mon Sep 17 00:00:00 2001 From: Kirill Makurin <maiddais...@outlook.com> Date: Tue, 12 Nov 2024 05:42:26 +0900 Subject: [PATCH 3/3] Update Makefile.am in mingw-w64-libraries/winpthreads/tests Add -L$(top_builddir)/fakelib to AM_LDFLAGS only when NOT using MSVC tools. Signed-off-by: Kirill Makurin <maiddais...@outlook.com> --- mingw-w64-libraries/winpthreads/tests/Makefile.am | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mingw-w64-libraries/winpthreads/tests/Makefile.am b/mingw-w64-libraries/winpthreads/tests/Makefile.am index 19ab5f23e..9dda82f73 100644 --- a/mingw-w64-libraries/winpthreads/tests/Makefile.am +++ b/mingw-w64-libraries/winpthreads/tests/Makefile.am @@ -1,5 +1,11 @@ AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/include -AM_LDFLAGS = -L$(top_builddir)/fakelib -L$(top_builddir) -lwinpthread -static +AM_LDFLAGS = + +if !MSVC +AM_LDFLAGS += -L$(top_builddir)/fakelib +endif + +AM_LDFLAGS += -L$(top_builddir) -lwinpthread -static #FIXME: The test "test.c" is inherently broken currently. check_PROGRAMS = t_clock_getres t_clock_gettime t_clock_nanosleep t_clock_settime t_nanosleep #test -- 2.46.1.windows.1
_______________________________________________ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public