fixed minor bugs in demo scripts and run_stem
[urisagit/Stem.git] / BuildStem.pm
CommitLineData
b3407611 1package BuildStem;
4536f655 2
3use strict;
b3407611 4use warnings;
4536f655 5
4536f655 6use Config;
b3407611 7use File::Basename;
8use File::Spec;
9use IO::File;
4536f655 10
b3407611 11use Module::Build;
4536f655 12
b3407611 13use vars qw(@ISA);
14@ISA = qw(Module::Build);
4536f655 15
4536f655 16
17sub process_script_files {
4536f655 18 my ( $self ) = @_ ;
b3407611 19 my $files = $self->find_script_files();
20 return unless keys %$files;
21
22 my $script_dir = File::Spec->catdir($self->blib, 'script');
23 my $demo_dir = File::Spec->catdir($self->blib, 'demo');
24 File::Path::mkpath( $script_dir );
25 File::Path::mkpath( $demo_dir );
26
27 foreach my $file (keys %$files) {
28 my $dest_dir = $file =~ /_demo$/ ? $demo_dir : $script_dir ;
29 my $result = $self->copy_if_modified($file, $dest_dir, 'flatten') or next;
30 $self->fix_shebang_line($result) if $self->is_unixish();
31 $self->make_executable($result);
32 my $demo_run_dir = File::Spec->catdir($self->base_dir(), 'demo');
33 if ( $result =~ /(?:run_stem$)|(?:_demo$)/ ) {
34 my $result2 = $self->copy_if_modified($result, $demo_run_dir, 'flatten') or next;
35 $self->add_to_cleanup($result2);
4536f655 36 }
37 }
b3407611 38 return 1;
4536f655 39}
40
b3407611 41sub process_conf_files {
4536f655 42 my ( $self ) = @_ ;
b3407611 43 my $files = $self->_find_file_by_type('stem','conf');
44 return unless keys %$files;
4536f655 45
b3407611 46 my $conf_dir = File::Spec->catdir($self->blib, 'conf');
47 File::Path::mkpath( $conf_dir );
4536f655 48
b3407611 49 foreach my $file (keys %$files) {
50 my $result = $self->copy_if_modified($file, $conf_dir, 'flatten') or next;
51 $self->fix_shebang_line($result) if $self->is_unixish();
4536f655 52 }
b3407611 53 return 1;
4536f655 54}
55
b3407611 56sub find_binary {
57 my ( $self, $prog ) = @_ ;
58 if ( $self->do_system( "which $prog >/dev/null" ) ) {
59 return `which $prog` ;
4536f655 60 }
4536f655 61 return;
62}
63
4536f655 64
b3407611 651;