App-AutoBuild
view release on metacpan or search on metacpan
lib/App/AutoBuild.pm view on Meta::CPAN
int main(int argc, char** argv)
{
stuff_function();
return 0;
}
src/stuff.c
#include "stuff.h"
void stuff_function()
{
// hai
}
src/stuff.h
#pragma once
void stuff_function();
Note you don't need to put stuff.c into your build.pl-- it Just Works(tm).
An even shorter example-- instead of a build.pl:
build.sh
#!/bin/sh
export CC="clang"
export CFLAGS="-std=c99 -pedantic -Wall -Wextra -O3"
perl -MApp::AutoBuild -e 'build("main.c");' -- $@
=head1 COMMAND LINE
usage: ./build.pl [-h|--help] [-v] [clean]
-h, --help: dump help
-v: increase verbosity (-vv or more -v's)
0 (default) only show compile/link actions, in shortened form
1 show compile/link actions with full command lines, and at the end a time summary (also shows App::AutoBuild overhead)
2 shows debugging for job numbers (not useful really yet)
-d: increase debugosity (-dd or more -d's)
0 (default) nothing!
1 show which dependencies caused a recompile
2 show stat() calls
-q: be more quiet
--cc=(compiler path): pick a compiler other than gcc
--program=(program): don't compile all targets, just this one
clean: unlink output files/meta file (.autobuild_meta)
=head1 DESCRIPTION
After writing a makefile for my 30th C project, I decided this was dumb and it (the computer) should figure out which object files should be linked in or recompiled. The idea behind this module is you create a build.pl that uses App::AutoBuild and c...
App::AutoBuild will figure out all the object files your C file depends on. A list of included header files (.h) will be computed by GCC and remembered in a cache. At build time, stat() is called on each header file included by your .c file. If an...
This tool isn't supposed to be a make replacement-- there are plenty of those, and at least one great one already in Perl. The idea is that the build system should know enough about the source code to do what you want for you. This replaces all the...
=head1 CAVEATS
For this to work properly, you must have a scheme and follow it. Every .c/.cpp file must have an .h/.hpp file that matches (with the exception of the .c/.cpp file with main()). For now, the .c and .h files must be in the same directory (but this ma...
If you have a .h file and an unrelated .c file with the same name (as in, headers.h and headers.c) in the same folder, the .c file will be compiled and linked in automatically. If this doesn't work well for you, put the .h files without .c files int...
A .autobuild_meta file is created in the current directory so it can remember modification times and dependency lists of files. This will definitely be configurable in a future version!
=head1 SUBROUTINES/METHODS
These are exported by default.
=head2 build()
Pass this function a hashref of parameters for how to build your project. Keys are as follows:
=head3 cflags
An arrayref of cflags
=head3 ldflags
An arrayref of ldflags
=head3 programs
A hashref with binaries as keys, and start-point C files as values.
=head3 rules
An arrayref of rule hashrefs. See L</RULES>.
=head2 shell_config()
This is a helper function that takes a shell command + args (as an array) to pass to system() and splits the STDOUT into an array by whitespace.
I do all this as arrays because the CFLAGS/LDFLAGS can be added or removed per-file with rules.
=head1 RULES
Rules let you have custom build options per-file. For now it only supports adding/removing cflags for a given .c file, or adding/removing ldflags for a given output binary.
{'file'=>'contrib/GLee/GLee.c', 'del_cflags'=>['-pedantic']},
{'file'=>'configtest', 'add_ldflags'=>['-lyaml'], 'del_ldflags'=>['-lGL', '-lGLU', shell_config('sdl-config', '--libs')]},
These definitely need some more work!
=head1 AUTHOR
Joel Jensen, C<< <yobert at gmail.com> >>
=head1 BUGS/TODO
Please email me if it doesn't work! I've only tested with GCC and clang.
lib/App/AutoBuild.pm view on Meta::CPAN
This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
=cut
use Time::HiRes qw(time);
use Storable qw(store retrieve);
use Digest::MD5();
use autodie qw(system);
use Exporter qw(import);
our @EXPORT = qw(build shell_config);
my $meta_file = '.autobuild_meta';
my $next_jid = 0;
my $system_runtime = 0;
sub build
{
my $opts = shift;
if(ref($opts) eq '')
{
my $bin = $opts;
$bin =~ s/\.cp?p?$//;
$opts = {'programs'=>{$bin=>$opts}};
}
my $start = time;
my $ab = App::AutoBuild->new();
$ab->args(\@ARGV);
my @cflags;
my @ldflags;
push @cflags, split(/\s+/, $ENV{'CFLAGS'}) if($ENV{'CFLAGS'});
push @ldflags, split(/\s+/, $ENV{'LDFLAGS'}) if($ENV{'LDFLAGS'});
push @cflags, @{$opts->{'cflags'}} if($opts->{'cflags'});
push @ldflags, @{$opts->{'ldflags'}} if($opts->{'ldflags'});
$ab->cflags(\@cflags);
$ab->ldflags(\@ldflags);
if($ENV{'CC'})
{
$ab->{'cc'} = $ENV{'CC'};
}
for(qw(cc osuffix))
{
$ab->{$_} = $opts->{$_} if($opts->{$_});
}
$ab->{'rules'} = $opts->{'rules'} || []; # HACK for now until I decide the right way to do this
for my $bin (keys %{ $opts->{'programs'} })
{
if($ab->{'clean'} || !$ab->{'default'} || $ab->{'default'}{$bin})
{
$ab->program($opts->{'programs'}{$bin}, $bin);
}
}
my $moar = 1;
while($moar)
{
#$ab->debug_jobs();
#<STDIN>;
$moar = $ab->run();
};
my $end = time;
if($ab->{'verbose'} > 0)
{
printf(
"AutoBuild.pm runtime: %.3fs\n".
" system() runtime: %.3fs\n".
" overhead: %.3fs\n",
$end - $start,
$system_runtime,
($end - $start) - $system_runtime);
}
return;
}
sub shell_config
{
my @cmdline = @_;
# TODO use system() for this
my $run = join(' ', @cmdline);
my $txt = `$run`;
chomp($txt);
return split(/\s+/, $txt);
}
sub new
{
my($class) = @_;
$class = ref($class) || $class;
my $self = bless({}, $class);
if(-e $meta_file)
{
$self->{'meta'} = retrieve($meta_file);
}else
{
$self->{'meta'} = {};
}
( run in 1.061 second using v1.01-cache-2.11-cpan-df04353d9ac )