Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for MSYS2 / MinGW64 #27

Open
plicease opened this issue Jan 19, 2016 · 7 comments
Open

Support for MSYS2 / MinGW64 #27

plicease opened this issue Jan 19, 2016 · 7 comments

Comments

@plicease
Copy link
Member

MSYS2 / MinGW64 has .pc files that are relative to the MinGW64 root.

Strawberry Perl

> pkg-config.bat --with-path=C:\msys64\mingw64\lib\pkgconfig --cflags gtk+-3.0
-I/mingw64/include/gtk-3.0 -mms-bitfields -I/mingw64/include/pango-1.0 -I/mingw64/include/glib-2.0 -I/mingw64/lib/glib-2.0/include -I/mingw64/include/cairo -I/mingw64/include/gdk-pixbuf-2.0 -I/mingw64/include/atk-1.0

MSYS2 / MinGW64 shell

$ pkg-config --cflags gtk+-3.0
-mms-bitfields -pthread -mms-bitfields -IC:/msys64/mingw64/include/gtk-3.0 -IC:/msys64/mingw64/include/cairo -IC:/msys64/mingw64/include -IC:/msys64/mingw64/include/pango-1.0 -IC:/msys64/mingw64/include/atk-1.0 -IC:/msys64/mingw64/include/cairo -IC:/msys64/mingw64/include/pixman-1 -IC:/msys64/mingw64/include -I/mingw64/include/freetype2 -I/mingw64/include/libpng16 -I/mingw64/include/harfbuzz -I/mingw64/include/glib-2.0 -I/mingw64/lib/glib-2.0/include -IC:/msys64/mingw64/include -IC:/msys64/mingw64/include/freetype2 -IC:/msys64/mingw64/include -IC:/msys64/mingw64/include/harfbuzz -IC:/msys64/mingw64/include/libpng16 -IC:/msys64/mingw64/include/gdk-pixbuf-2.0 -IC:/msys64/mingw64/include/libpng16 -IC:/msys64/mingw64/include/glib-2.0 -IC:/msys64/mingw64/lib/glib-2.0/include
@plicease
Copy link
Member Author

/cc: @sivoais

@zmughal
Copy link

zmughal commented May 5, 2016

The path problem can be fixed with cygpath which is part of MSYS2 (extended from the Cygwin equivalent).

On my system:

convert-flags-with-cygpath.pl

#!perl

use strict;
use warnings;

use Text::ParseWords;
use v5.016;

my @flags = shellwords(<>);
say( join $/,
    map {
        if( my ($type, $path) = $_ =~ /^(-[IL])(.*)$/ ) {
            my $win_path = qx(C:/msys64/usr/bin/cygpath -w $path);
            chomp $win_path;
            "$type$win_path";
        } else {
            $_;
        }
    } @flags );
> pkg-config.bat --with-path=C:\msys64\mingw64\lib\pkgconfig --cflags gtk+-3.0

-I/mingw64/include/gtk-3.0 -mms-bitfields -I/mingw64/include/pango-1.0 -I/mingw64/include/glib-2.0 -I/mingw64/lib/glib-2.0/include -I/mingw64/include/cairo -I/mingw64/include/gdk-pixbuf-2.0 -I/mingw64/include/atk-1.0

> pkg-config.bat --with-path=C:\msys64\mingw64\lib\pkgconfig --cflags gtk+-3.0 | perl convert-flags-with-cygpath.pl

-IC:\msys64\mingw64\include\gtk-3.0
-mms-bitfields
-IC:\msys64\mingw64\include\pango-1.0
-IC:\msys64\mingw64\include\glib-2.0
-IC:\msys64\mingw64\lib\glib-2.0\include
-IC:\msys64\mingw64\include\cairo
-IC:\msys64\mingw64\include\gdk-pixbuf-2.0
-IC:\msys64\mingw64\include\atk-1.0

@plicease
Copy link
Member Author

plicease commented May 6, 2016

Another difference is that MSYS2 pkg-config seems to default to --static

ollisg@donut MSYS /d/home/ollisg/dev/PkgConfig
$ pkg-config libarchive --libs
-larchive -lnettle -llzo2 -llzma -lbz2 -lz -lxml2 -lz -lpthread -liconv -lm

ollisg@donut MSYS /d/home/ollisg/dev/PkgConfig
$ perl lib/PkgConfig.pm  libarchive --libs
-larchive

ollisg@donut MSYS /d/home/ollisg/dev/PkgConfig
$ perl lib/PkgConfig.pm  --static libarchive --libs
-larchive -lnettle -llzo2 -llzma -lbz2 -lz -lxml2 -lpthread -liconv -lm

update: this seems intentional. --enable-indirect-deps is passed into ./configure:

build() {
  cd ${srcdir}/${pkgname}-${pkgver}
  ./configure \
    --build=${CHOST} \
    --host=${CHOST} \
    --prefix=/usr \
    --with-internal-glib \
    --enable-indirect-deps
  make
}

@plicease
Copy link
Member Author

plicease commented May 6, 2016

32d2ba5

@plicease
Copy link
Member Author

plicease commented May 6, 2016

MSYS2 has a default search path as mentioned in 32d2ba5 .
MSYS2 also sets PKG_CONFIG_PATH so if you want the correct search path from outside of MSYS2 for stuff inside MSYS2 you need to know this:

Adding directory '/usr/lib/pkgconfig' from PKG_CONFIG_PATH
Adding directory '/usr/share/pkgconfig' from PKG_CONFIG_PATH
Adding directory '/lib/pkgconfig' from PKG_CONFIG_PATH
Adding directory '/usr/lib/pkgconfig' from PKG_CONFIG_PATH
Adding directory '/usr/share/pkgconfig' from PKG_CONFIG_PATH

plicease added a commit that referenced this issue May 6, 2016
@zmughal
Copy link

zmughal commented May 6, 2016

It might be useful to note that the search path $PKG_CONFIG_PATH is different depending on which shell you open:

MSYS2: /usr/lib/pkgconfig:/usr/share/pkgconfig:/lib/pkgconfig

MINGW32: /mingw32/lib/pkgconfig:/mingw32/share/pkgconfig

MINGW64: /mingw64/lib/pkgconfig:/mingw64/share/pkgconfig

The reason is that you don't really want to compile against the MSYS2 environment. A good description pulled from the MSYS2 documentation is:

MSYS2 consists of three subsystems and their corresponding package repositories, msys2, mingw32, and mingw64.

The mingw subsystems provide native Windows programs and are the main focus of the project. These programs are built to co-operate well with other Windows programs, independently of the other subsystems.

The msys2 subsystem provides an emulated mostly-POSIX-compliant environment for building software, package management, and shell scripting. These programs live in a virtual single-root filesystem (the root is the MSYS2 installation directory). Some effort is made to have the programs work well with native Windows programs, but it's not seamless.

Each of the subsystems provides its own native (i.e. target=host) compiler toolchain, in msys2-devel, mingw-w64-i686-toolchain, and mingw-w64-x86_64-toolchain. There are also cross compiler toolchains with host={i686,x86_64}-pc-msys and target={i686,x86_64}-w64-mingw32 in mingw-w64-cross-toolchain, but these are of limited use because there are no library packages for them.

Every subsystem has an associated "shell", which is essentially a set of environment variables that allow the subsystems to co-operate properly. These shells can be invoked using scripts in the MSYS2 installation directory or shortcuts in the Start menu. The scripts set the MSYSTEM variable and start a terminal emulator with bash. Bash in turn sources /etc/profile which sets the environment depending on the value of MSYSTEM.

@plicease
Copy link
Member Author

plicease commented May 6, 2016

@zmughal Good background! It makes more sense now. When running PkgConfig.pm with MSYS2 Perl, you should get the same search path with or without the environment variable now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants