kicad-devel 6.23 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#!/usr/bin/perl -w
my $vernr = "0.0.2";
my $monthshort = "Mar";
my $monthlong = "March";
my $year = "2009";


use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;

###
# User defined settings
###
my $svn_path_remote  = 'https://kicad.svn.sourceforge.net/svnroot/kicad/trunk';
my $svn_path_local   = '/media/data/projects/applications/kicad/subversion/kicad-core';
my $build_path = '/home/jerry/builds/kicad';


##  TODO 
##  Add debian package generation
##	dh_make -e jerkejacobs@gmail.com -s -n
##  debuild -us -uc
##  TODO


###
# Commandline options
###
my $option_about              = 0;
my $option_manual             = 0;
my $option_help               = 0;
my $option_build_binaries     = 0;
my $option_svn_update         = 0;
my $option_verbose            = 1;
my $option_version            = 0;
my $option_generate_makefiles = 0;
my $option_no_clear           = 0;
my $option_install_binaries   = 0;
my $no_options                = 0; # No options given

###
# Commands
###
my $command_silent     = '&> /dev/null';          # Nullify stderr and stdout from commands
47
my $command_cmake      = "cmake -DCMAKE_BUILD_TYPE=Debug -DwxWidgets_USE_DEBUG=ON -DKICAD_AUIMANAGER=ON -DKICAD_AUITOOLBAR=ON $svn_path_local"; # Where cmake looks for CMakeLists.txt
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
my $command_svn_update = 'svn update';            # Subversion update command

###
# Help and about messages
###
my $about_message = "KiCad Devel, version $vernr, $monthshort $year, jerkejacobs\@gmail.org\n";
my $short_help = "No options given try `kicad_devel.pl --help' for more information.\n";


###########################################
########### Commandline options ###########
###########################################
if (@ARGV == 0) 
{
    print $short_help;
}
else 
{
    GetOptions('help|?'                   => \$option_help,
               'man'                      => \$option_manual,
               'build-binaries|compile'   => \$option_build_binaries,
               'svn-update'               => \$option_svn_update,
               'about'                    => \$option_about,
               'version'                  => \$option_version,
               'generate-makefiles'       => \$option_generate_makefiles,
               'install|install-binaries' => \$option_install_binaries,
               'no-clear'                 => \$option_no_clear,

               # Verbose settings
               'quiet|noverbose'          => sub { $option_verbose = 0 });

       pod2usage(1) if $option_help;
       pod2usage(-verbose => 2) if $option_manual;
}


###########################
########### Main ##########
###########################

# Init main function
main();

sub
main
{
    # No commandline options given
    if ($no_options) {
        print $short_help;
        exit(0);
    }

    # Option svn update given
	if ($option_svn_update) {
        svn_update();
    }

    # Generate makefiles
    if ($option_generate_makefiles) {
        generate_makefiles();
    }

    # Option build binaries given
    if ($option_build_binaries) {
        build_binaries();
    }

    # Install compiled binaries
    if ($option_install_binaries) {
        install_binaries();
    }
    exit(0);
}

###
# Clear the console screen
###
sub
clear_screen {

  # Clear screen if no clear option is false
  if ($option_no_clear == 0)
  {
    print `clear`;
  }
  else
  {
    print "\n\n";
  }
}

###
# Print line of $_[1] char
#  $_[0] = Number of chars before newline
#  $_[1] = Char to print line of
###
sub
print_line {
    for(my $i = 0; $i < $_[0]; ++$i) {
        print $_[1];
    }
    print "\n";
}

###
# Execute cmake on svn_path_local to generate makefiles
#   on build_path
###
sub
generate_makefiles {

  # Print settings to output
  if ($option_verbose == 1) 
  {
      clear_screen();

      print_line(80, '#');

      print " Generating makefiles\n";

      print_line(80, '#');

      print " SVN Path      : $svn_path_local\n";
      print " Build Path    : $build_path\n";
      print " CMake Command : $command_cmake\n";

      print_line(80, '#');
  }

  ###
  # Execute cmake command with correct verbose level output
  ###

  # Execute command and dump output to console
  if ($option_verbose == 0)
  {
      chdir $build_path;
      `$command_cmake $command_silent`;
  }

  # Execute command and display output to console
  if ($option_verbose == 1)
  {
      chdir $build_path
          or die "Can't cd to $build_path";
      print `$command_cmake`;
  }

  # Print output
  if ($option_verbose == 1)
  {
      print_line(80, '#');
  }
}

###
# Update local subversion repository on $svn_path_local
###
sub
svn_update 
{  
    if ($option_verbose)
    {
        clear_screen();
        print_line(80, '#');
        print "Updating local subversion repository\n";
        print_line(80, '#');
        print "Repository path : $svn_path_local\n";
        print "SVN Command     : $command_svn_update\n";
        print_line(80, '#');
        chdir $svn_path_local
            or die "Can't cd to $svn_path_local";
        print `$command_svn_update`;
        print_line(80, '#');
    }
    else
    {
        chdir $svn_path_local;
        `$command_svn_update $command_silent`;
    } 
}

###
# Build the binaries on $build_path
###
sub
build_binaries
{
	chdir $build_path
		or die "Can't cd to $build_path";
	system("make -j 4");
}

###
# Install the compiled binaries from $build_path
###
sub
install_binaries
{
  chdir $build_path
    or die "Can't cd to $build_path";
  system("make install");
}

######## Begin of POD manual page ########
__END__

=head1 NAME

kicad_devel - KiCad development helper program

=head1 SYNOPSIS

kicad_devel [options]

Options:

  --help               -?         brief help message
  --man                -M         full program manual
  --verbose            -V         set verbosity level
  --about                         about information
  --version            -v         display version information
  --svn-update         -svn-up    update kicad subversion path
  --build-binaries     -compile   compile sourcecode in build path
  --install-binaries   -install   install compiled binaries
  --no-clear                      dont clear the console screen after every command is executed

=head1 OPTIONS

=head2 HELP

=head1 DESCRIPTION

B<This program> will read the given input file(s) and do something
useful with the contents thereof.

=cut