First patch was wrong, this is ok. (conf arg was missing) -- Reini Urban
Index: parrot-svn/lib/Parrot/Configure/Compiler.pm =================================================================== --- parrot-svn.orig/lib/Parrot/Configure/Compiler.pm +++ parrot-svn/lib/Parrot/Configure/Compiler.pm @@ -183,15 +183,38 @@ defaults to true. =item conditioned_lines -If conditioned_lines is true, then lines in the file that begin with: -C<#CONDITIONED_LINE(var):> are skipped if the var condition is false. Lines -that begin with C<#INVERSE_CONDITIONED_LINE(var):> are skipped if -the var condition is true. For instance: +If conditioned_lines is true, then lines in the file that begin with +C<#+(var):> are skipped if the var condition is false. +Lines that begin with C<#-(var):> are skipped if the var condition is true. +For legacy the old syntax #CONDITIONED_LINE(var): and #INVERSE_CONDITIONED_LINE(var): +is also supported. + +A condition var may be a single keyword, which is true if a config key is true +or equal to the platform name, +or a logical combination or (and var1 var2...) or (or var1 var2...) or (not var1...) +as in common lisp macro expansion, OR being the default for multiple keys. +Keys are space seperated. +Keys may also consist of key=value pairs, where the key is checked for equalness +to the value. Note that values may contain no spaces here. (TODO: support quotes +in values) - #CONDITIONED_LINE(win32): $(SRC_DIR)/atomic/gcc_x86$(O) + #+(var1 var2...) defaults to #+(or var1 var2...) + #-(var1 var2...) defaults to #-(or var1 var2...) + +For instance: + + #+(win32): $(SRC_DIR)/atomic/gcc_x86$(O) will be processed if the platform is win32. + #-(win32 cygwin): $(SRC_DIR)/atomic/gcc_x86$(O) + +will be skipped if the platform is win32 or cygwin. + + #+(and win32 glut (not cygwin)): + +will be used on win32 and if glut is defined, but not on cygwin. + =item comment_type This option takes has two possible values, C<#> or C</*>. If present and @@ -321,12 +344,20 @@ sub genfile { last; } if ( $options{conditioned_lines} ) { - if ( $line =~ m/^#CONDITIONED_LINE\(([^)]+)\):(.*)/s ) { - next unless $conf->data->get($1); + # allow nested parens here + if ( $line =~ m/^#([-+])\((.+)\):(.*)/s ) { + my $truth = cond_eval($conf, $2); + next if ($1 eq '-') and $truth; + next if ($1 eq '+') and not $truth; + $line = $3; + } + # but here not (legacy) + elsif ( $line =~ m/^#CONDITIONED_LINE\(([^)]+)\):(.*)/s ) { + next unless cond_eval($conf, $1); $line = $2; } elsif ( $line =~ m/^#INVERSE_CONDITIONED_LINE\(([^)]+)\):(.*)/s ) { - next if $conf->data->get($1); + next if cond_eval($conf, $1); $line = $2; } } @@ -426,6 +457,18 @@ sub genfile { move_if_diff( "$target.tmp", $target, $options{ignore_pattern} ); } +# Just checks the logical truth of the hash value (exists and not empty) +# TODO: also check the platform name if the hash key does not exist +# TODO: recursive (), evaluate AND, OR, NOT with multiple keys +# TODO: check for key=value, like #+(ld=gcc) +sub cond_eval { + my $conf = shift; + my $expr = shift; + # TODO: parse for parens and multiple keys in the expression and + # evaluate it recursively. + return $conf->data->get($expr); +} + sub append_configure_log { my $conf = shift; my $target = shift;