This patch adds a new utility to Parrot and modifies Makefile.in to use
it.  The utility is for wrapping C compilers and other tools we use, so
we can avoid putting the logic in the Makefile and can potentially use
totally different commands on different platforms.

The patch is by no means ready to be applied to the source tree--it
doesn't touch the shared lib stuff, an important test needs to be added
to Configure, and I haven't even tried it on a Unix.  The ability to
create libraries, both static and dynamic, is missing.  But you should
be able to build your basic Parrot with this.

If you have a Unix box and ten spare minutes, please apply this to a
fresh checkout of Parrot, run 'make test', and tell me how well it
works.

As for the tool itself:

pccw.pl is a small script that implements a wrapper around several
tools.  You use it like this:

        perl pccw.pl [--args="(arguments)"] (destination file) (source files)

pccw.pl examines the extension of the destination file and uses that to
pick what to do.  If the extension is '.c', then it examines the source
files and runs either ops2c or pmc2c as appropriate; otherwise it runs
the appropriate compiler or linker incantations.  The --args argument is
used to pass additional flags to the tool.

Patch is attached.  Share and enjoy.

--Brent Dax <[EMAIL PROTECTED]>
@roles=map {"Parrot $_"} qw(embedding regexen Configure)

#define private public
    --Spotted in a C++ program just before a #include
Index: MANIFEST
===================================================================
RCS file: /home/perlcvs/parrot/MANIFEST,v
retrieving revision 1.132
diff -u -r1.132 MANIFEST
--- MANIFEST    20 Mar 2002 06:27:35 -0000      1.132
+++ MANIFEST    30 Mar 2002 09:53:36 -0000
@@ -250,6 +250,7 @@
 packout.c
 parrot.c
 pbc2c.pl
+pccw.pl
 pdump.c
 platforms/generic.c
 platforms/generic.h
Index: Makefile.in
===================================================================
RCS file: /home/perlcvs/parrot/Makefile.in,v
retrieving revision 1.141
diff -u -r1.141 Makefile.in
--- Makefile.in 21 Mar 2002 23:47:22 -0000      1.141
+++ Makefile.in 30 Mar 2002 09:53:37 -0000
@@ -112,6 +112,8 @@
 LD = ${ld}
 PERL = ${perl}
 
+PCCW = $(PERL) pccw.pl
+
 
 ###############################################################################
 #
@@ -141,17 +143,17 @@
 ${make_set_make}
 
 .c$(O):
-       $(CC) $(CFLAGS) ${cc_o_out}$@ -c $<
+       $(PCCW) $@ $<
 
 all : $(TEST_PROG) docs
 
 mops: examples/assembly/mops${exe} examples/mops/mops${exe}
 
 libparrot$(A) : $(O_FILES)
-       $(AR_CRS) $@ $(O_FILES)
+       $(PCCW) $@ $(O_FILES)
 
 $(TEST_PROG): test_main$(O) $(GEN_HEADERS) $(O_FILES) lib/Parrot/OpLib/core.pm 
lib/Parrot/PMC.pm
-       $(LD) ${ld_out}$(TEST_PROG) $(LDFLAGS) $(O_FILES) test_main$(O) $(C_LIBS)
+       $(PCCW) $(TEST_PROG) $(O_FILES) test_main$(O) $(C_LIBS)
 
 lib_deps_object: $(O_FILES)
        $(PERL) lib_deps.pl object $(O_FILES)
@@ -253,7 +255,7 @@
        $(PERL) pbc2c.pl examples/assembly/mops.pbc > examples/assembly/mops.c
 
 examples/assembly/mops${exe}: examples/assembly/mops$(O) $(O_FILES)
-       $(LD) $(LDFLAGS) ${ld_out}examples/assembly/mops${exe} 
examples/assembly/mops$(O) $(O_FILES) $(C_LIBS)
+       $(PCCW) examples/assembly/mops${exe} examples/assembly/mops$(O) $(O_FILES) 
+$(C_LIBS)
 
 examples/assembly/life.pbc: examples/assembly/life.pasm assemble.pl
        cd examples && cd assembly && $(MAKE) life.pbc PERL=$(PERL) && cd .. && cd ..
@@ -262,7 +264,7 @@
        $(PERL) pbc2c.pl examples/assembly/life.pbc > examples/assembly/life.c
 
 examples/assembly/life${exe}: examples/assembly/life$(O) $(O_FILES)
-       $(LD) $(LDFLAGS) ${ld_out}examples/assembly/life${exe} 
examples/assembly/life$(O) $(O_FILES) $(C_LIBS)
+       $(PCCW) examples/assembly/life${exe} examples/assembly/life$(O) $(O_FILES) 
+$(C_LIBS)
 
 ###############################################################################
 #
@@ -273,7 +275,7 @@
 examples/mops/mops$(O): examples/mops/mops.c
 
 examples/mops/mops${exe}: examples/mops/mops$(O) platform$(O)
-       $(LD) $(LDFLAGS) ${ld_out}examples/mops/mops${exe} examples/mops/mops$(O) 
platform$(O) $(C_LIBS)
+       $(PCCW) examples/mops/mops${exe} examples/mops/mops$(O) platform$(O) $(C_LIBS)
 
 
 ###############################################################################
@@ -345,12 +347,12 @@
 core_ops$(O): $(GENERAL_H_FILES) core_ops.c
 
 core_ops.c $(INC)/oplib/core_ops.h: $(OPS_FILES) ops2c.pl lib/Parrot/OpsFile.pm 
lib/Parrot/Op.pm
-       $(PERL) ops2c.pl C $(OPS_FILES)
+       $(PCCW) --args="C" core_ops.c $(OPS_FILES)
 
 core_ops_prederef$(O): $(GENERAL_H_FILES) core_ops_prederef.c
 
 core_ops_prederef.c $(INC)/oplib/core_ops_prederef.h: $(OPS_FILES) ops2c.pl 
lib/Parrot/OpsFile.pm lib/Parrot/Op.pm
-       $(PERL) ops2c.pl CPrederef $(OPS_FILES)
+       $(PCCW) --args="CPrederef" core_ops_prederef.c $(OPS_FILES)
 
 warnings$(O): $(H_FILES)
 
--- /dev/null   Sat Mar 30 02:01:34 2002
+++ pccw.pl     Sat Mar 30 01:54:20 2002
@@ -0,0 +1,74 @@
+#Parrot C Compiler Wrapper
+#Initial version by Brent Dax ([EMAIL PROTECTED])
+
+#Usage:
+#    perl pccw.pl --args="(args)" (destfile) (sourcefiles)
+
+use strict;
+use warnings;
+
+use lib 'lib';
+use Parrot::Config;
+
+my($args, $destfile, @sourcefiles);
+
+if($ARGV[0] =~ /--args="(.*)"/) {
+       $args=$1;
+       shift;
+}
+else {
+       $args="";
+}
+
+($destfile, @sourcefiles)=@ARGV;
+
+my %destmap=(
+       $PConfig{o}             => sub { System("$PConfig{cc} $PConfig{ccflags} 
+$PConfig{cc_warn} $PConfig{cc_inc} $args $PConfig{cc_o_out}$destfile -c 
+@sourcefiles") },
+       $PConfig{exe}           => sub { System("$PConfig{ld} 
+$PConfig{ld_out}$destfile $PConfig{ldflags} $args @sourcefiles") },
+       $PConfig{a}||'.a'       => \&handle_library,
+       $PConfig{so}||'.so'     => \&handle_shared_lib, 
+       '.c'                    => \&handle_generated_files
+);
+
+eval {
+       $destfile =~ /(\.\w+)$/;
+       $destmap{$1}->();
+};
+
+if($@) {
+       if($@ =~ /Undefined subroutine/) {
+               print "Don't know how to convert '$sourcefiles[0]' to '$destfile'!\n";
+       }
+       else {
+               die $@, "\n";
+       }
+
+       exit(-1);
+}
+
+exit($?);
+
+sub handle_generated_files {
+       if($sourcefiles[0] =~ /ops$/) {
+               system("$^X ops2c.pl $args @sourcefiles");
+       }
+       elsif($sourcefiles[0] =~ /pmc$/) {
+               system("$^X classes/pmc2c.pl $args @sourcefiles");
+       }
+       else {
+               print "Don't know how to convert '$sourcefiles[0]' to '$destfile'!\n";
+       }
+}
+       
+sub handle_shared_lib {
+       print "NYI";
+}
+
+sub handle_library {
+       print "NYI";
+}
+
+sub System {
+       print "$_[0]\n";
+       system(@_);
+}
\ No newline at end of file

Reply via email to