++ed by:

2 non-PAUSE users.

Author image Ed J
and 1 contributors

NAME

Make - Pure-Perl implementation of a somewhat GNU-like make.

SYNOPSIS

    require Make;
    my $make = Make->new;
    $make->parse($file);
    $make->Make(@ARGV);

    # to see what it would have done
    print $make->Script(@ARGV);

    # to see an expanded version of the makefile
    $make->Print(@ARGV);

    my $targ = $make->target($name);
    my $rule = Make::Rule->new(':', \@prereqs, \@recipe);
    $targ->add_rule($rule);
    my @rules = @{ $targ->rules };

    my @prereqs  = @{ $rule->prereqs };
    my @commands = @{ $rule->recipe };

DESCRIPTION

Implements in pure Perl a somewhat GNU-like make, intended to be highly customisable.

Via pure-perl-make Make has built perl/Tk from the MakeMaker generated Makefiles...

MAKEFILE SYNTAX

Broadly, there are macros, directives, and rules (including recipes).

Macros:

    varname = value

Directives:

    vpath %.c src/%.c
    [-]include otherfile.mk # - means no warn on failure to include

Please note the vpath does not have the GNU-make behaviour of discarding the found path if an inferred target must be rebuilt, since this is too non-deterministic / confusing behaviour for this author.

Rules:

    target : prerequisite1 prerequisite2[; immediate recipe]
    (tab character)follow-on recipe...

Recipe lines can start with @ (do not echo), - (continue on failure).

In addition to traditional

        .c.o :
                $(CC) -c ...

GNU make's 'pattern' rules e.g.

        %.o : %.c
                $(CC) -c ...

The former gets internally translated to the latter.

METHODS

There are other methods (used by parse) which can be used to add and manipulate targets and their prerequites.

new

Class method, takes pairs of arguments in name/value form. Arguments:

Vars

A hash-ref of values that sets variables, overridable by the makefile.

Jobs

Number of concurrent jobs to run while building. Not implemented.

GNU

If true, then GNUmakefile is looked for first.

FunctionPackages

Array-ref of package names to search for GNU-make style functions. Defaults to Make::Functions.

FSFunctionMap

Hash-ref of file-system functions by which to access the file-system. Created to help testing, but might be more widely useful. Defaults to code accessing the actual local filesystem. The various functions are expected to return real Perl filehandles. Relevant keys: glob, fh_open, fh_write, mtime.

parse

Parses the given makefile. If none or undef, these files will be tried, in order: GNUmakefile if "GNU", makefile, Makefile.

If a scalar-ref, will be makefile text.

Make

Given a target-name, builds the target(s) specified, or the first 'real' target in the makefile.

Print

Print to current select'ed stream a form of the makefile with all variables expanded.

Script

Print to current select'ed stream the equivalent bourne shell script that a make would perform i.e. the output of make -n.

set_var

Given a name and value, sets the variable to that.

May gain a "type" parameter to distinguish immediately-expanded from recursively-expanded (the default).

expand

Uses "subsvars" to return its only arg with any macros expanded.

target

Find or create Make::Target for given target-name.

has_target

Find Make::Target for given target-name, or undef.

patrule

Search registered pattern-rules for one matching given target-name. Returns a Make::Rule for that of the given kind, or false.

Uses GNU make's "exists or can be made" algorithm on each rule's proposed requisite to see if that rule matches.

ATTRIBUTES

These are read-only.

vars

Returns a hash-ref of the current set of variables.

function_packages

Returns an array-ref of the packages to search for macro functions.

fsmap

Returns a hash-ref of the "FSFunctionMap".

FUNCTIONS

parse_makefile

Given a file-handle, returns array-ref of Abstract Syntax-Tree (AST) fragments, representing the contents of that file. Each is an array-ref whose first element is the node-type (comment, include, vpath, var, rule), followed by relevant data.

tokenize

Given a line, returns array-ref of the space-separated "tokens". Also splits on any further args.

subsvars

    my $expanded = Make::subsvars(
        'hi $(shell echo there)',
        \@function_packages,
        [ \%vars ],
        $fsmap,
    );
    # "hi there"

Given a piece of text, will substitute any macros in it, either a single-character macro, or surrounded by either {} or (). These can be nested. Uses the array-ref as a list of hashes to search for values.

If the macro is of form $(varname:a=b), then this will be a GNU (and others) make-style "substitution reference". First "varname" will be expanded. Then all occurrences of "a" at the end of words within the expanded text will be replaced with "b". This is intended for file suffixes.

For GNU-make style functions, see Make::Functions.

DEBUGGING

To see debugging messages on STDERR, set environment variable MAKE_DEBUG to a true value;

BUGS

More attention needs to be given to using the package to write makefiles.

The rules for matching 'dot rules' e.g. .c.o and/or pattern rules e.g. %.o : %.c are suspect. For example give a choice of .xs.o vs .xs.c + .c.o behaviour seems a little odd.

SEE ALSO

pure-perl-make

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html POSIX standard for make

https://www.gnu.org/software/make/manual/make.html GNU make docs

AUTHOR

Nick Ing-Simmons

COPYRIGHT AND LICENSE

Copyright (c) 1996-1999 Nick Ing-Simmons.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.