2008/8/3 Reini Urban via RT <[EMAIL PROTECTED]>:
> First patch was wrong, this is ok. (conf arg was missing)
And this patch actually implements this feature for 90%. (and or not mult.keys)
Just the parenthesis grouping is missing. (and key (not key))
I'll commit more useful examples later, where I actually need them.
For now just
the root Makefile is changed.
--
Reini Urban
http://phpwiki.org/ http://murbreak.at/
Index: parrot-svn/lib/Parrot/Configure/Compiler.pm
===================================================================
--- parrot-svn.orig/lib/Parrot/Configure/Compiler.pm
+++ parrot-svn/lib/Parrot/Configure/Compiler.pm
@@ -181,17 +181,41 @@ to '#', C<replace_slashes> to enabled, a
If the name of the file being generated ends in C<Makefile>, this option
defaults to true.
-=item conditioned_lines
+=item conditioned_lines and #+(): #-():
-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<#+(expr):> are skipped if the expr condition is false.
+Lines that begin with C<#-(var):> are skipped if the expr condition is true.
+For legacy the old syntax #CONDITIONED_LINE(var): and
+#INVERSE_CONDITIONED_LINE(var): is also supported.
+
+A condition expr 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 expr1 expr2...) or (or expr1 expr2...) or
+(not expr) as in the common lisp reader, 'OR' being the default for multiple keys.
+Multiple keys are space seperated.
+
+TODO: 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
@@ -320,12 +344,20 @@ sub genfile {
last;
}
if ( $options{conditioned_lines} ) {
- if ( $line =~ m/^#CONDITIONED_LINE\(([^)]+)\):(.*)/s ) {
- next unless $conf->data->get($1);
+ # allow multiple keys and 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;
}
}
@@ -425,6 +457,42 @@ sub genfile {
move_if_diff( "$target.tmp", $target, $options{ignore_pattern} );
}
+# Just checks the logical truth of the hash value (exists and not empty).
+# Also check the platform name if the hash key does not exist.
+# Recursive, evaluate AND, OR, NOT with multiple keys.
+# Check for key=value, like #+(ld=gcc)
+sub cond_eval {
+ my $conf = shift;
+ my $expr = shift;
+ # TODO: parse parenthesis groups, "(and (not win32) has_glut)"
+ $expr =~ s/[\(\)]/ /g; # currently ignored
+ my @keys = split /\s+/, $expr;
+ my $key = $expr;
+ if (@keys > 1) { # multiple keys: recurse into
+ my $truth;
+ my $op = pop @keys;
+ if ($key =~ /^(or|and|not)$/i) {
+ $op = lc($key);
+ $key = pop @keys;
+ }
+ while (!$truth and $key) {
+ $truth = cond_eval($conf, $key);
+ if ($op eq 'not') { $truth = $truth ? 0 : 1; }
+ elsif ($op eq 'and') { $truth = (@keys<1) if $truth; }
+ $key = pop @keys;
+ }
+ return $truth;
+ }
+ if ($key =~ /^(\w+)=(.+)$/) {
+ return $conf->data->get($1) eq $2;
+ } else {
+ #FIXME: return $conf->data()->exists($key)
+ return exists($conf->data->{c}->{$key})
+ ? $conf->data()->get($key)
+ : $key eq $^O;
+ }
+}
+
sub append_configure_log {
my $conf = shift;
my $target = shift;
@@ -452,6 +520,6 @@ sub append_configure_log {
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
-# fill-column: 100
+# fill-column: 80
# End:
# vim: expandtab shiftwidth=4:
Index: parrot-svn/lib/Parrot/Configure/Data.pm
===================================================================
--- parrot-svn.orig/lib/Parrot/Configure/Data.pm
+++ parrot-svn/lib/Parrot/Configure/Data.pm
@@ -236,6 +236,32 @@ sub keys {
return keys %{ $self->{c} };
}
+=item * C<exists()>
+
+=over 4
+
+=item * Purpose
+
+Check if a Parrot::Configure::Data key exists.
+
+=item * Arguments
+
+Name of the key.
+
+=item * Return Value
+
+Defined or undef.
+
+=back
+
+=cut
+
+sub exists {
+ my $self = shift;
+
+ return exists($self->{c}->{shift});
+}
+
=item * C<slurp()>
=over 4
Index: parrot-svn/config/gen/makefiles/root.in
===================================================================
--- parrot-svn.orig/config/gen/makefiles/root.in
+++ parrot-svn/config/gen/makefiles/root.in
@@ -102,10 +102,10 @@ LINK = @link@
LINKFLAGS = @linkflags@ @link_debug@ @ld_debug@
LD = @ld@
LDFLAGS = @ldflags@ @ld_debug@
-RECONFIGURE = $(PERL) tools/dev/reconfigure.pl
+RECONFIGURE = $(PERL) -Ilib tools/dev/reconfigure.pl
INNO_SETUP = iscc
JIT_BUILD_TOOL = $(BUILD_TOOLS_DIR)/jit2c.pl
-#CONDITIONED_LINE(darwin):export MACOSX_DEPLOYMENT_TARGET := @osx_version@
+#+(darwin):export MACOSX_DEPLOYMENT_TARGET := @osx_version@
###############################################################################
#
@@ -138,7 +138,7 @@ NONGEN_HEADERS = @TEMP_nongen_headers@
GEN_MAKEFILES = \
Makefile \
-#CONDITIONED_LINE(has_perldoc): docs/Makefile \
+#+(has_perldoc): docs/Makefile \
compilers/nqp/Makefile \
compilers/pct/Makefile \
compilers/pge/Makefile \
@@ -163,9 +163,9 @@ GEN_CONFIGS = \
lib/Parrot/PMC.pm \
runtime/parrot/include/config.fpmc \
$(SRC_DIR)/platform.c \
-#CONDITIONED_LINE(platform_asm): $(SRC_DIR)/platform_asm.s \
-#CONDITIONED_LINE(has_opengl): config/gen/call_list/opengl.in \
-#CONDITIONED_LINE(has_glut): $(SRC_DIR)/glut_callbacks.c \
+#+(platform_asm): $(SRC_DIR)/platform_asm.s \
+#+(has_opengl): config/gen/call_list/opengl.in \
+#+(has_glut): $(SRC_DIR)/glut_callbacks.c \
$(SRC_DIR)/core_pmcs.c \
CFLAGS \
$(IMCC_DIR)/CFLAGS \
@@ -182,8 +182,8 @@ GEN_CONFIGS = \
GEN_PASM_INCLUDES = \
runtime/parrot/include/signal.pasm \
-#CONDITIONED_LINE(has_opengl): runtime/parrot/include/opengl_defines.pasm \
-#CONDITIONED_LINE(has_opengl): runtime/parrot/library/OpenGL_funcs.pir \
+#+(has_opengl): runtime/parrot/include/opengl_defines.pasm \
+#+(has_opengl): runtime/parrot/library/OpenGL_funcs.pir \
@TEMP_gen_pasm_includes@
CONFIGURE_GENERATED_FILES = \
@@ -251,7 +251,7 @@ GEN_LIBRARY = \
$(LIBRARY_DIR)/MIME/Base64.pbc \
$(LIBRARY_DIR)/NCI/call_toolkit_init.pbc \
$(LIBRARY_DIR)/ncurses.pbc \
-#CONDITIONED_LINE(has_opengl): $(LIBRARY_DIR)/OpenGL.pbc \
+#+(has_opengl): $(LIBRARY_DIR)/OpenGL.pbc \
$(LIBRARY_DIR)/P6object.pbc \
$(LIBRARY_DIR)/parrotlib.pbc \
$(LIBRARY_DIR)/pcre.pbc \
@@ -369,7 +369,7 @@ INTERP_O_FILES = \
$(OPS_DIR)/core_ops$(O) \
$(OPS_DIR)/core_ops_switch$(O) \
\
-#CONDITIONED_LINE(i386_has_gcc_cmpxchg): $(SRC_DIR)/atomic/gcc_x86$(O) \
+#+(i386_has_gcc_cmpxchg): $(SRC_DIR)/atomic/gcc_x86$(O) \
$(SRC_DIR)/builtin$(O) \
$(SRC_DIR)/byteorder$(O) \
$(SRC_DIR)/charset$(O) \
@@ -442,7 +442,7 @@ INTERP_O_FILES = \
@TEMP_atomic_o@ \
@TEMP_jit_o@ \
@TEMP_gc_o@ \
-#CONDITIONED_LINE(platform_asm): $(SRC_DIR)/platform_asm$(O) \
+#+(platform_asm): $(SRC_DIR)/platform_asm$(O) \
O_FILES = \
$(INTERP_O_FILES) \
@@ -484,14 +484,14 @@ INSTALLABLEPDB = $(CUR_DIR)/install
# Libraries
LIBPARROT_STATIC = @blib_dir@/@libparrot_static@
-#CONDITIONED_LINE(darwin):export DYLD_LIBRARY_PATH := @blib_dir@:$(DYLD_LIBRARY_PATH)
-#CONDITIONED_LINE(win32):LIBPARROT_SHARED = @libparrot_shared@
-#INVERSE_CONDITIONED_LINE(win32):LIBPARROT_SHARED = @blib_dir@/@libparrot_shared@
+#+(darwin):export DYLD_LIBRARY_PATH := @blib_dir@:$(DYLD_LIBRARY_PATH)
+#+(win32):LIBPARROT_SHARED = @libparrot_shared@
+#-(win32):LIBPARROT_SHARED = @blib_dir@/@libparrot_shared@
# This line controls whether a static or shared library is built
LIBPARROT = @libparrot@
-#CONDITIONED_LINE(has_icu):ICU_SHARED = @icu_shared@
+#+(has_icu):ICU_SHARED = @icu_shared@
ALL_PARROT_LIBS = @libparrot_ldflags@ $(ICU_SHARED) $(C_LIBS)
# dynamic extensions
@@ -548,13 +548,14 @@ MAKE = @make_c@
all : \
flags_dummy \
+ Makefile \
PARROT_LIBS \
$(PARROT) \
runtime/parrot/include/parrotlib.pbc \
runtime/parrot/include/config.fpmc \
docs \
$(LIBNCI_TEST_SO) \
-#CONDITIONED_LINE(has_glut): $(LIBGLUTCB_SO) \
+#+(has_glut): $(LIBGLUTCB_SO) \
$(GEN_LIBRARY) \
dynpmc \
dynoplibs \
@@ -617,6 +618,10 @@ PMC2CV = $(PERL) $(BUILD_TOOLS_DIR)/pmc2
vtable.dump : src/vtable.tbl
$(PMC2CV)
+# regenerate the Makefile
+Makefile: config/gen/makefiles/root.in
+ $(RECONFIGURE) --step=gen::makefiles --target=Makefile
+
# This is a listing of all targets meant to be called by users
help :
@echo ""
@@ -790,7 +795,7 @@ $(PARROT_CONFIG) : tools/util/parrot-con
$(PARROT) pbc_to_exe.pir parrot_config.pbc
# HLL Executable targets
-#CONDITIONED_LINE(win32):perl6 : $(PERL6)
+#+(win32):perl6 : $(PERL6)
$(PERL6) : compilers $(PBC_TO_EXE)
$(MAKE) languages/perl6 perl6$(EXE)
@@ -868,8 +873,8 @@ check_source : $(GENERAL_H_FILES)
# so always delete the lib -leo
PARROT_LIBS: \
-#CONDITIONED_LINE(has_static_linking): $(LIBPARROT_STATIC) \
-#CONDITIONED_LINE(has_dynamic_linking): $(LIBPARROT_SHARED)
+#+(has_static_linking): $(LIBPARROT_STATIC) \
+#+(has_dynamic_linking): $(LIBPARROT_SHARED)
$(LIBPARROT_STATIC) : $(O_FILES)
$(MKPATH) @blib_dir@
@@ -881,7 +886,7 @@ $(LIBPARROT_SHARED) : $(O_FILES)
$(LD) $(LD_SHARE_FLAGS) $(LDFLAGS) @[EMAIL PROTECTED]@ @libparrot_soname@ \
#+(cygchkdll): -Wl,--out-implib=blib/lib/libparrot.dll.a \
$(O_FILES) $(C_LIBS) $(ICU_SHARED)
-#CONDITIONED_LINE(libparrot_shared_alias): ( cd @blib_dir@ ; ln -sf @libparrot_shared@ @libparrot_shared_alias@ )
+#+(libparrot_shared_alias): ( cd @blib_dir@ ; ln -sf @libparrot_shared@ @libparrot_shared_alias@ )
#
@@ -1068,8 +1073,8 @@ $(SRC_DIR)/hll$(O) : $(GENERAL_H_FILES)
$(SRC_DIR)/platform$(O) : $(GENERAL_H_FILES)
-#CONDITIONED_LINE(platform_asm):$(SRC_DIR)/platform_asm$(O) : $(GENERAL_H_FILES)
-#CONDITIONED_LINE(platform_asm):
+#+(platform_asm):$(SRC_DIR)/platform_asm$(O) : $(GENERAL_H_FILES)
+#+(platform_asm):
$(SRC_DIR)/core_pmcs$(O) : $(GENERAL_H_FILES)
$(SRC_DIR)/trace$(O) : $(GENERAL_H_FILES)
@@ -1260,11 +1265,11 @@ $(IMCC_O_FILES) : $(IMCC_H_FILES) $(ALL_
#
###############################################################################
-#CONDITIONED_LINE(has_perldoc):docs : docs.dummy
-#INVERSE_CONDITIONED_LINE(has_perldoc):docs : docs.stub
+#+(has_perldoc):docs : docs.dummy
+#-(has_perldoc):docs : docs.stub
-#CONDITIONED_LINE(has_perldoc):html : html.dummy
-#INVERSE_CONDITIONED_LINE(has_perldoc):html : html.stub
+#+(has_perldoc):html : html.dummy
+#-(has_perldoc):html : html.stub
html.stub:
@echo "Perldoc is required, but not detected."
@@ -1460,10 +1465,10 @@ check : test
# when the needed runcores are available
fulltest :
[EMAIL PROTECTED]@ testb
-#CONDITIONED_LINE(cg_flag): [EMAIL PROTECTED]@ testC
+#+(cg_flag): [EMAIL PROTECTED]@ testC
[EMAIL PROTECTED]@ testf
-#CONDITIONED_LINE(cg_flag): [EMAIL PROTECTED]@ testg
-#CONDITIONED_LINE(cg_flag): [EMAIL PROTECTED]@ testj
+#+(cg_flag): [EMAIL PROTECTED]@ testg
+#+(cg_flag): [EMAIL PROTECTED]@ testj
[EMAIL PROTECTED]@ testr
[EMAIL PROTECTED]@ testS
[EMAIL PROTECTED]@ src_tests
@@ -1575,15 +1580,15 @@ clean : \
prog-clean \
dynext-clean \
languages-clean \
-#CONDITIONED_LINE(has_perldoc): docs-clean \
-#CONDITIONED_LINE(has_perldoc): html-clean \
+#+(has_perldoc): docs-clean \
+#+(has_perldoc): html-clean \
dynpmc-clean \
dynoplibs-clean \
examples-clean \
imcc-clean \
compilers-clean \
smoke-clean \
-#INVERSE_CONDITIONED_LINE(win32): cover-clean \
+#-(win32): cover-clean \
editor-clean
@TEMP_cg_r@
$(RM_F) chartypes "*.s" "*~"
@@ -2040,10 +2045,10 @@ COVER_DIRS = \
cover: \
cover.dummy \
cover-testb \
-#CONDITIONED_LINE(cg_flag): cover-testC \
+#+(cg_flag): cover-testC \
cover-testf \
-#CONDITIONED_LINE(cg_flag): cover-testg \
-#CONDITIONED_LINE(jitcapable): cover-testj \
+#+(cg_flag): cover-testg \
+#+(jitcapable): cover-testj \
cover-testr \
cover-testS \
cover-src \