Split up configure script

This commit is contained in:
Matthias Schiffer 2013-09-30 19:04:35 +02:00
parent b72ffb1bdb
commit 2f919846c2
5 changed files with 36 additions and 37 deletions

View File

@ -117,6 +117,7 @@ export FEEDS
export GLUON_GENERATE := $(GLUONDIR)/scripts/generate.sh export GLUON_GENERATE := $(GLUONDIR)/scripts/generate.sh
export GLUON_CONFIGURE := $(GLUONDIR)/scripts/configure.pl
feeds: FORCE feeds: FORCE

@ -1 +1 @@
Subproject commit c57f81b7c4a498828e54e8026a9178dbc639d87b Subproject commit 65769f82507c9771de137451aaa2a45c57708dc3

View File

@ -4,37 +4,7 @@ use warnings;
use strict; use strict;
my %config; our $CONFIG = do $ENV{GLUONDIR} . '/site/site.conf';
sub add_config { my $script = shift @ARGV;
my ($prefix, $c) = @_; do $script;
foreach my $key (keys $c) {
my $val = $c->{$key};
if (ref($val) eq 'HASH') {
add_config($key . '.', $val);
}
unless (ref($val)) {
$config{'@' . $prefix . $key . '@'} = $val;
}
}
}
sub read_config {
my $input = shift;
my $CONFIG = do $input;
add_config('', $CONFIG);
}
read_config 'site/site.conf';
my $regex = join '|', map {quotemeta} keys %config;
for (<>) {
s/($regex)/${config{$1}}/g;
print;
}

30
scripts/generate.pl Normal file
View File

@ -0,0 +1,30 @@
use warnings;
my %config;
sub add_config {
my ($prefix, $c) = @_;
foreach my $key (keys $c) {
my $val = $c->{$key};
if (ref($val) eq 'HASH') {
add_config($key . '.', $val);
}
unless (ref($val)) {
$config{'@' . $prefix . $key . '@'} = $val;
}
}
}
add_config('', $CONFIG);
my $regex = join '|', map {quotemeta} keys %config;
for (<>) {
s/($regex)/${config{$1}}/g;
print;
}

View File

@ -4,8 +4,6 @@ set -e
declare -a IN declare -a IN
GLUONDIR="$(dirname "$0")/.."
for ((i = 1; i < $#; i++)); do for ((i = 1; i < $#; i++)); do
IN[$i]="${!i}" IN[$i]="${!i}"
@ -23,7 +21,7 @@ for S in "${IN[@]}"; do (
D="$(dirname "$FILE")" D="$(dirname "$FILE")"
mkdir -p "$OUT/$D" mkdir -p "$OUT/$D"
(cd "$GLUONDIR"; scripts/configure.pl) < "$FILE" > "$OUT/$FILE" (cd "$GLUONDIR"; scripts/configure.pl scripts/generate.pl) < "$FILE" > "$OUT/$FILE"
chmod --reference="$FILE" "$OUT/$FILE" chmod --reference="$FILE" "$OUT/$FILE"
done done
); done ); done