No description, website, or topics provided.
Perl 6 Makefile C
Switch branches/tags
Nothing to show
Latest commit 848d6a3 Jun 15, 2017 @retupmoca committed on GitHub Merge pull request #22 from zoffixznet/patch-1
Use modern META filename

module LibraryMake

An attempt to simplify building native code for a perl6 module.

This is effectively a small configure script for a Makefile. It will allow you to use the same tools to build your native code that were used to build perl6 itself.

Typically, this will be used in both (to support panda installs), and in a standalone script in the src directory (to support standalone testing/building). Note that if you need additional custom configure code, you will currently need to add it to both your and to your Configure.pl6

Example Usage

The below files are examples of what you would write in your own project. The src directory is merely a convention, and the will likely be significantly different in your own project.


use Panda::Common;
use Panda::Builder;
use LibraryMake;
use Shell::Command;

class Build is Panda::Builder {
    method build($workdir) {
        my $makefiledir = "$workdir/src";
        my $destdir = "$workdir/resources";
        mkpath $destdir;
        make($makefiledir, $destdir);


# Note that this is *not* run during panda install - it is intended to be
# run manually for testing / recompiling without needing to do a 'panda install'
# The example here is how the 'make' sub generates the makefile in the above file
use LibraryMake;

my $destdir = '../resources';
my %vars = get-vars($destdir);
process-makefile('.', %vars);

say "Configure completed! You can now run '%vars<MAKE>' to build libfoo.";


all: %DESTDIR%/libfoo%SO%

%DESTDIR%/libfoo%SO%: libfoo%O%
    %LD% %LDSHARED% %LDFLAGS% %LIBS% %LDUSR%pam %LDOUT%%DESTDIR%/libfoo%SO% libfoo%O%

libfoo%O%: libfoo.c
    %CC% -c %CCSHARED% %CCFLAGS% %CCOUT%libfoo%O% libfoo.c


# ...

use NativeCall;
use LibraryMake;

# Find our compiled library.
sub library {
    my $so = get-vars('')<SO>;
    return ~(%?RESOURCES{"libfoo$so"});

# we put 'is native(&library)' because it will call the function and resolve the
# library at compile time, while we need it to happen at runtime (because
# this library is installed *after* being compiled).
sub foo() is native(&library) { * };


# include the following section in your
"resources" : [


sub get-vars

sub get-vars(
    Str $destfolder
) returns Hash

Returns configuration variables. Effectively just a wrapper around $*VM.config, as the VM config variables are different for each backend VM.

sub process-makefile

sub process-makefile(
    Str $folder,
) returns Mu

Takes '$folder/' and writes out '$folder/Makefile'. %vars should be the result of get-vars above.

sub make

sub make(
    Str $folder,
    Str $destfolder
) returns Mu

Calls get-vars and process-makefile for you to generate '$folder/Makefile', then runs your system's 'make' to build it.