source: main/trunk/package-kits/linux/generate@ 29481

Last change on this file since 29481 was 29481, checked in by Jeremy Symon, 9 years ago

Working on a script for generating build scripts for different packages and systems with minimal code duplication and human intervention. Currently should generate working Makefiles, but doesn't handle the package managers yet. Since both RPM and APT package managers rely on Makefiles, I will change the pacman scripts to also use Makefiles, and see if all the package manager scripts can be automatically generated (at least the metadata)

  • Property svn:executable set to *
File size: 2.8 KB
Line 
1#!/usr/bin/env perl
2
3# Generates Makefiles for different systems and packages
4# Uses a hashmap to do config variables (see readvar for how variables are
5# read in and an example of how they are resolved / used)
6
7use strict;
8use warnings;
9use utf8;
10use File::Basename;
11use File::Path 'make_path';
12use File::Copy;
13use Storable 'dclone';
14
15my $USAGE = "Usage: " . basename($0) . " <platforms> <packages>
16 platforms: A comma separated list of the platforms defined in pkg.in/platforms
17 Or 'all' (for all platforms)
18 packages: A comma separated list of the packages defined in pkg.in/packages
19 Or 'all' (for all platforms)
20";
21
22$#ARGV == 1 or die $USAGE;
23
24sub globbify {
25 my ($dir, $files) = @_;
26 $files =~ /^all$/i and return glob "$dir/*";
27 my @list = glob "$dir/{$files}";
28 for (@list) {
29 -f or die "Could not find '", $_, "'";
30 }
31 return @list;
32}
33
34sub readvar {
35 my ($vars, $line) = @_;
36 my ($var, $val) = split "=", $line;
37 defined $var and defined $val or die "Invalid variable assignment: '$line'";
38 $val =~ s/%([\w]+)%/$vars->{$1}/g;
39 $vars->{$var} = $val;
40}
41
42my @platforms = globbify "pkg.in/platforms", shift;
43my @packages = globbify "pkg.in/packages", shift;
44
45for (@platforms) {
46 my ($platform) = /^pkg\.in\/platforms\/(.*)$/;
47 my %platform_vars = ();
48 open FH, '<', $_ or die "Failed to open '$_' for reading: $!";
49 # read platform variable definitons
50 while (<FH>) {
51 chomp;
52 readvar \%platform_vars, $_;
53 }
54 close FH;
55
56 for (@packages) {
57 my ($package) = /^pkg\.in\/packages\/(.*)$/;
58 my $package_path = "build/$platform/$package";
59 make_path $package_path;
60
61 open FH, '<', $_ or die "Failed to open '$_' for reading: $!";
62
63 # read package file dependencies
64 while (<FH>) {
65 chomp;
66 /^[\s]*$/ and last;
67 -e "pkg.in/files/$_" or die "Could not find '", $_, "'";
68 copy "pkg.in/files/$_", "$package_path/$_" or die "Failed to copy '$_': $!";
69 }
70
71 my %package_vars = %{dclone \%platform_vars};
72 # read package variable definitions
73 while (<FH>) {
74 chomp;
75 /^[\s]*$/ and last;
76 readvar \%package_vars, $_;
77 }
78
79 my $outfile = "$package_path/Makefile";
80 open OUT, '>', $outfile or die "Failed to open '$outfile' for writing: $!";
81 # read package makefile segments
82 while (<FH>) {
83 chomp;
84 open SEG, '<', "pkg.in/segments/$_" or die "Failed to open '$_' for reading: $!";
85 # write the makefile
86 while (<SEG>) {
87 s/%([\w]+)%/$package_vars{$1}/g;
88 print OUT;
89 }
90 close SEG;
91 }
92 close FH;
93 close OUT;
94 }
95 print "Generated $platform build scripts in build/$platform/\n";
96}
Note: See TracBrowser for help on using the repository browser.