Skip to content

Commit

Permalink
update the build system to autodetect system provided libs
Browse files Browse the repository at this point in the history
- uses raw pkg-config to determine include directories
- failover to the old behaviour when errors occur
- fix DT_RPATH when @libdir@ has no / prepended
  • Loading branch information
tomboy64 committed Apr 27, 2016
1 parent 629282f commit 3198112
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
46 changes: 45 additions & 1 deletion Configure.pl
Expand Up @@ -32,7 +32,7 @@
os=s shell=s toolchain=s compiler=s
ar=s cc=s ld=s make=s has-sha has-libuv
static has-libtommath has-libatomic_ops
has-dyncall has-libffi
has-dyncall has-libffi pkgconfig=s
build=s host=s big-endian jit! enable-jit lua=s has-dynasm
prefix=s bindir=s libdir=s mastdir=s make-install asan ubsan),
'no-optimize|nooptimize' => sub { $args{optimize} = 0 },
Expand Down Expand Up @@ -99,6 +99,7 @@
$config{osname} = $^O;
$config{osvers} = $Config{osvers};
$config{lua} = $args{lua} // './3rdparty/dynasm/minilua@exe@';
$config{pkgconfig} = $args{pkgconfig} // '/usr/bin/pkg-config';

# set options that take priority over all others
my @keys = qw( ar cc ld make );
Expand Down Expand Up @@ -164,12 +165,30 @@
system($defaults{make}, 'realclean')
}

# test whether pkg-config works
system("$config{pkgconfig}", "--version");
if ( $? == 0 ) {
$config{pkgconfig_works} = 1;
} else {
$config{pkgconfig_works} = 0;
}

# conditionally set include dirs and install rules
$config{cincludes} //= '';
$config{install} //= '';
if ($args{'has-libuv'}) {
$defaults{-thirdparty}->{uv} = undef;
unshift @{$config{usrlibs}}, 'uv';
if ($config{pkgconfig_works}) {
my $result = `$config{pkgconfig} --cflags libuv`;
if ( $? == 0 ) {
$result =~ s/\n/ /g;
$config{cincludes} .= ' ' . "$result";
print("Adding extra include for libuv: $result\n");
} else {
print("Error occured when running $config{pkgconfig} --cflags libuv.");
}
}
}
else {
$config{cincludes} .= ' ' . $defaults{ccinc} . '3rdparty/libuv/include'
Expand All @@ -181,6 +200,16 @@
if ($args{'has-libatomic_ops'}) {
$defaults{-thirdparty}->{lao} = undef;
unshift @{$config{usrlibs}}, 'atomic_ops';
if ($config{pkgconfig_works}) {
my $result = `$config{pkgconfig} --cflags atomic_ops`;
if ( $? == 0 ) {
$result =~ s/\n/ /g;
$config{cincludes} .= ' ' . "$result";
print("Adding extra include for atomic_ops: $result\n");
} else {
print("Error occured when running $config{pkgconfig} --cflags atomic_ops.");
}
}
}
else {
$config{cincludes} .= ' ' . $defaults{ccinc} . '3rdparty/libatomic_ops/src';
Expand Down Expand Up @@ -232,6 +261,16 @@
$config{nativecall_backend} = 'libffi';
unshift @{$config{usrlibs}}, 'ffi';
push @{$config{defs}}, 'HAVE_LIBFFI';
if ($config{pkgconfig_works}) {
my $result = `$config{pkgconfig} --cflags libffi`;
if ( $? == 0 ) {
$result =~ s/\n/ /g;
$config{cincludes} .= ' ' . "$result";
print("Adding extra include for libffi: $result\n");
} else {
print("Error occured when running $config{pkgconfig} --cflags libffi.");
}
}
}
elsif ($args{'has-dyncall'}) {
unshift @{$config{usrlibs}}, 'dyncall_s', 'dyncallback_s', 'dynload_s';
Expand Down Expand Up @@ -364,6 +403,7 @@
print "\n", <<TERM, "\n";
make: $config{make}
compile: $config{cc} $config{cflags}
includes: $config{cincludes}
link: $config{ld} $config{ldflags}
libs: $config{ldlibs}
Expand Down Expand Up @@ -873,6 +913,10 @@ =head1 OPTIONS
=item --has-libffi
=item --pkgconfig=/path/to/pkgconfig/executable
Provide path to the pkgconfig executable. Default: /usr/bin/pkg-config
=item --no-jit
Disable JIT compiler, which is enabled by default to JIT-compile hot frames.
Expand Down
3 changes: 0 additions & 3 deletions build/Makefile.in
Expand Up @@ -454,9 +454,6 @@ install: all
$(CP) src/strings/*.h $(DESTDIR)$(PREFIX)/include/moar/strings
$(CP) src/jit/*.h $(DESTDIR)$(PREFIX)/include/moar/jit
$(CP) src/instrument/*.h $(DESTDIR)$(PREFIX)/include/moar/instrument
$(MKPATH) $(DESTDIR)$(PREFIX)/include/libuv
$(MKPATH) $(DESTDIR)$(PREFIX)/include/libtommath
$(CP) 3rdparty/libuv/include/*.h $(DESTDIR)$(PREFIX)/include/libuv
@install@

lib: @moar@
Expand Down
2 changes: 1 addition & 1 deletion build/setup.pm
Expand Up @@ -125,7 +125,7 @@ our %TC_POSIX = (
ccshared => '-fPIC',
ldshared => '-shared @ccshared@',
moarshared => '',
ldrpath => '-Wl,-rpath,@libdir@ -Wl,-rpath,@prefix@/share/perl6/site/lib',
ldrpath => '-Wl,-rpath,/@libdir@ -Wl,-rpath,@prefix@/share/perl6/site/lib',

arflags => 'rcs',
arout => '',
Expand Down

0 comments on commit 3198112

Please sign in to comment.