diff options
Diffstat (limited to 'Makefile.PL')
-rw-r--r-- | Makefile.PL | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..dadf80b --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,139 @@ +# Copyright (C) all contributors <mwrap-perl@80x24.org> +# License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt> +use v5.12; +use ExtUtils::MakeMaker; +use Config; +my $pkg_config = $ENV{PKG_CONFIG} // 'pkg-config'; +my $LIBS = `$pkg_config --libs liburcu-cds liburcu-bp`; +if ($?) { + print STDERR <<END; +`$pkg_config --libs liburcu-cds` failed (\$?=$?) + +You need to install pkg-config and liburcu <https://liburcu.org/> +before you can build Devel::Mwrap. + +On Debian: + + apt-get install pkg-config liburcu-dev +END + # tell CPAN testing to indicate missing deps + exit 0; +} + +chomp($LIBS); +if ($Config{usemymalloc} eq 'y') { + print STDERR <<END; +Devel::Mwrap requires `usemymalloc=n'. malloc and related functions +must be dynamically-linked for Devel::Mwrap to work. +END + exit 0; +} + +# may be empty +chomp(my $INC = `$pkg_config --cflags liburcu-cds liburcu-bp`); +my @writemakefile_args = (); +my $ccflags = ''; + +print '# checking libxxhash... '; +chomp(my $xxhash_inc = `$pkg_config --cflags libxxhash`); +if ($? == 0) { + $INC .= " $xxhash_inc"; + $ccflags .= ' -DHAVE_XXHASH'; + say 'yes'; +} else { + say 'no'; +} + +use IO::Handle; +STDOUT->autoflush(1); +require ExtUtils::CBuilder; +require File::Temp; +my $cb = ExtUtils::CBuilder->new(quiet => $ENV{V} ? 0 : 1); +my $d = File::Temp->newdir('mwrap-perl-build-XXXX'); +my $olderr; +print '# checking for -lexecinfo... '; +{ + use autodie; + open my $fh, '>', "$d/execinfo.c"; + print $fh <<EOM; +#include <execinfo.h> +int main(void) { return backtrace_symbols_fmt ? 1 : 0; } +EOM + close $fh; + open $olderr, '+>&', *STDERR{IO}; + open STDERR, '>', "$d/err.log"; +} +eval { + my $obj = $cb->compile(source => "$d/execinfo.c"); + $cb->link(objects => $obj, extra_linker_flags => '-lexecinfo'); + $LIBS .= ' -lexecinfo'; + say " yes on $^O"; +}; +say " no on $^O" if $@; +{ + use autodie; + open STDERR, '+>&', $olderr or die "dup stderr: $!"; +} + +# See lib/ExtUtils/MakeMaker.pm for details of how to influence +# the contents of the Makefile that is written. +push @writemakefile_args, ( + NAME => 'Devel::Mwrap', + VERSION_FROM => 'lib/Devel/Mwrap.pm', + CCFLAGS => "$Config{ccflags} $ccflags", + PREREQ_PM => {}, + ABSTRACT_FROM => 'lib/Devel/Mwrap.pm', + EXE_FILES => [qw(script/mwrap-perl script/mwrap-rproxy)], + AUTHOR => 'mwrap hackers <mwrap-perl@80x24.org>', + LIBS => $LIBS, # e.g. -lurcu-cds + LICENSE => 'gpl_2', # GPL-3.0+, CPAN::Meta::Spec limitation + MIN_PERL_VERSION => '5.12.0', + BUILD_REQUIRES => {}, + INC => $INC, + depend => { + Makefile => 'lib/Devel/Mwrap.pm', + }, + META_MERGE => { + resources => { + repository => 'https://80x24.org/mwrap-perl.git', + homepage => 'https://80x24.org/mwrap-perl.git/about', + bugtracker => 'https://80x24.org/mwrap-public/', + }, + }, +); + +WriteMakefile(@writemakefile_args); + +my $tflags = $ccflags; +$tflags .= ' -DHAS_SOCKADDR_SA_LEN ' if $Config{d_sockaddr_sa_len}; +sub MY::postamble { + <<EOF; +N = \$\$(( \$\$(nproc 2>/dev/null || gnproc 2>/dev/null || echo 2) + 1 )) +-include config.mak + +check-manifest :: MANIFEST + if git ls-files >\$?.gen 2>&1; then diff -u \$? \$?.gen; fi + +build.env :: Makefile + echo >\$\@+ extra_linker_flags=$LIBS -lpthread + echo >>\$\@+ extra_compiler_flags=-I. $INC $Config{ccflags} $tflags + mv \$\@+ \$\@ + +pure_all :: build.env + +check:: all check-manifest + prove -bvw -j\$(N) + +# Install symlinks to ~/bin (which is hopefuly in PATH) which point to +# this source tree. +# prefix + bindir matches git.git Makefile: +prefix = \$(HOME) +bindir = \$(prefix)/bin +symlink-install : all + mkdir -p \$(bindir) + exe=\$\$(realpath exe.sh) && cd \$(bindir) && \\ + for x in \$(EXE_FILES); do \\ + ln -sf "\$\$exe" \$\$(basename "\$\$x"); \\ + done +EOF +} |