summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelliott_c <ocielliottc@users.noreply.github.com>2006-02-16 19:56:16 +0000
committerelliott_c <ocielliottc@users.noreply.github.com>2006-02-16 19:56:16 +0000
commitbf84f8b8982c942d3e357535f05c0c78aa3a3ff9 (patch)
tree4ef8c167caf391ac41dd8bddda88f564f945678d
parent555e83360bb0f0292652f66e8d4c2acd07662fbb (diff)
downloadMPC-bf84f8b8982c942d3e357535f05c0c78aa3a3ff9.tar.gz
ChangeLogTag: Thu Feb 16 19:53:13 UTC 2006 Chad Elliott <elliott_c@ociweb.com>
-rw-r--r--ChangeLog24
-rwxr-xr-xhighlight_template.pl228
-rw-r--r--modules/Driver.pm2
-rw-r--r--modules/HTMLWorkspaceCreator.pm6
-rw-r--r--templates/make.mpd42
5 files changed, 264 insertions, 38 deletions
diff --git a/ChangeLog b/ChangeLog
index b43f9416..824a3c74 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+Thu Feb 16 19:53:13 UTC 2006 Chad Elliott <elliott_c@ociweb.com>
+
+ * highlight_template.pl:
+
+ Added a tool which can be helpful in debugging MPC template code.
+ This utility will color highlight an MPC template and output html.
+
+ * modules/Driver.pm:
+
+ Perl 5.8.8 has a "feature" where basename('') returns './' instead
+ of '' as all other versions do. In the case where we may call
+ basename() with an empty string, avoid calling basename() and just
+ use '' instead. Thanks to Johnny Willemsen for helping me debug
+ this one.
+
+ * modules/HTMLWorkspaceCreator.pm:
+
+ Output the projects in build order instead of alphabetical order.
+
+ * templates/make.mpd:
+
+ Greatly simplified this template by removing many little foreach's
+ and enclose most of the template in two big foreach's.
+
Wed Feb 15 19:41:59 2006 J.T. Conklin <jtc@acorntoolworks.com>
* templates/automake.mpd:
diff --git a/highlight_template.pl b/highlight_template.pl
new file mode 100755
index 00000000..52f16e6e
--- /dev/null
+++ b/highlight_template.pl
@@ -0,0 +1,228 @@
+eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}'
+ & eval 'exec perl -w -S $0 $argv:q'
+ if 0;
+
+# ******************************************************************
+# Author: Chad Elliott
+# Date: 2/16/2006
+# $Id$
+# ******************************************************************
+
+# ******************************************************************
+# Pragma Section
+# ******************************************************************
+
+use strict;
+use FileHandle;
+use File::Basename;
+
+# ******************************************************************
+# Data Section
+# ******************************************************************
+
+my(%keywords) = (## These correspond to those in TemplateParser.pm
+ 'if' => 1,
+ 'else' => 1,
+ 'endif' => 1,
+ 'noextension' => 0,
+ 'dirname' => 0,
+ 'basename' => 0,
+ 'basenoextension' => 0,
+ 'foreach' => 2,
+ 'forfirst' => 2,
+ 'fornotfirst' => 2,
+ 'fornotlast' => 2,
+ 'forlast' => 2,
+ 'endfor' => 2,
+ 'eval' => 0,
+ 'comment' => 0,
+ 'marker' => 0,
+ 'uc' => 0,
+ 'lc' => 0,
+ 'ucw' => 0,
+ 'normalize' => 0,
+ 'flag_overrides' => 0,
+ 'reverse' => 0,
+ 'sort' => 0,
+ 'uniq' => 0,
+ 'multiple' => 0,
+ 'starts_with' => 0,
+ 'ends_with' => 0,
+ 'contains' => 0,
+ 'compares' => 0,
+ 'duplicate_index' => 0,
+ 'transdir' => 0,
+
+ ## These correspond to those in ProjectCreator.pm
+ 'cat' => 0,
+ 'cmp' => 0,
+ 'cp' => 0,
+ 'mkdir' => 0,
+ 'mv' => 0,
+ 'os' => 0,
+ 'rm' => 0,
+ 'nul' => 0,
+ 'gt' => 0,
+ 'lt' => 0,
+ 'and' => 0,
+ 'or' => 0,
+ 'quote' => 0,
+ );
+
+my($ifmod) = 0;
+my($formod) = 0;
+my($cmod) = 50;
+my(%keycolors) = (0 => [160, 32, 240],
+ 1 => [255, 50, 50],
+ 2 => [50, 50, 255],
+ );
+my($version) = '$Id$';
+$version =~ s/.*\s+(\d+[\.\d]+)\s+.*/$1/;
+
+# ******************************************************************
+# Subroutine Section
+# ******************************************************************
+
+sub convert_to_html {
+ my($line) = shift;
+ $line =~ s/&/&amp;/g;
+ $line =~ s/</&lt;/g;
+ $line =~ s/>/&gt;/g;
+ $line =~ s/"/&quot;/g;
+ $line =~ s/ /&nbsp;/g;
+ $line =~ s/\t/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/g;
+ $line =~ s/\n/<br>/;
+ return $line;
+}
+
+
+sub usageAndExit {
+ print "highlight_template.pl v$version\n",
+ "Usage: ", basename($0), " <template> [html output]\n\n",
+ "This script will color highlight the template provided using\n",
+ "varying colors for the different keywords, variables and text.\n",
+ "Nested if's and foreach's will have slightly different colors.\n";
+ exit(0);
+}
+
+# ******************************************************************
+# Main Section
+# ******************************************************************
+
+my($status) = 0;
+my($fh) = new FileHandle();
+my($input) = $ARGV[0];
+my($output) = $ARGV[1];
+
+if (!defined $input || $input =~ /^-/) {
+ usageAndExit();
+}
+
+if (!defined $output) {
+ $output = $input;
+ $output =~ s/\.mpd$//;
+ $output .= '.html';
+}
+
+if (open($fh, $input)) {
+ my($deftxt) = 'black';
+ my(@codes) = ();
+ while(<$fh>) {
+ my($len) = length($_);
+ for(my $start = 0; $start < $len;) {
+ my($sindex) = index($_, '<%', $start);
+ if ($sindex >= 0) {
+ my($left) = substr($_, $start, $sindex - $start);
+ if ($left ne '') {
+ push(@codes, [$deftxt, $left]);
+ }
+ my($eindex) = index($_, '%>', $sindex);
+ if ($eindex >= $sindex) {
+ $eindex += 2;
+ }
+ else {
+ $eindex = $len;
+ }
+
+ my($part) = substr($_, $sindex, $eindex - $sindex);
+ my($key) = substr($part, 2, length($part) - 4);
+ my($name) = $key;
+ my($color) = 'green';
+ my(@entry) = ();
+ if ($key =~ /^([^\(]+)\(.*\)/) {
+ $name = $1;
+ if (defined $keywords{$name}) {
+ @entry = @{$keycolors{$keywords{$1}}};
+ }
+ }
+ elsif (defined $keywords{$key}) {
+ @entry = @{$keycolors{$keywords{$key}}};
+ }
+
+ if (defined $entry[0]) {
+ if ($name eq 'if') {
+ $ifmod++;
+ $entry[0] -= ($cmod * ($ifmod - 1));
+ }
+ elsif ($name eq 'endif') {
+ $entry[0] -= ($cmod * ($ifmod - 1));
+ $ifmod-- if ($ifmod > 0);
+ }
+ elsif (defined $keywords{$name} &&
+ $keywords{$name} == $keywords{'if'}) {
+ $entry[0] -= ($cmod * ($ifmod - 1));
+ }
+ elsif ($name eq 'foreach') {
+ $formod++;
+ $entry[2] -= ($cmod * ($formod - 1));
+ }
+ elsif ($name eq 'endfor') {
+ $entry[2] -= ($cmod * ($formod - 1));
+ $formod-- if ($formod > 0);
+ }
+ elsif (defined $keywords{$name} &&
+ $keywords{$name} == $keywords{'foreach'}) {
+ $entry[2] -= ($cmod * ($formod - 1));
+ }
+ foreach my $entry (@entry) {
+ $entry = 0 if ($entry < 0);
+ }
+ $color = '#' . sprintf("%02x%02x%02x", @entry);
+ }
+
+ push(@codes, [$color, $part]);
+ $start = $eindex;
+ }
+ else {
+ my($part) = substr($_, $start, $len - $start);
+ push(@codes, [$deftxt, $part]);
+ $start += ($len - $start);
+ }
+ }
+ }
+ close($fh);
+
+ if (open($fh, ">$output")) {
+ print $fh "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n",
+ "<html><head><title>", basename($input), "</title></head>\n",
+ "<body>\n";
+ foreach my $code (@codes) {
+ $$code[1] = convert_to_html($$code[1]);
+ my($newline) = ($$code[1] =~ s/<br>//);
+ print $fh ($$code[1] ne '' ?
+ "<font color=\"$$code[0]\">$$code[1]</font>" : ''),
+ ($newline ? "<br>\n" : '');
+ }
+ print $fh "</body></html>\n";
+ }
+ else {
+ print STDERR "ERROR: Unable to open $output for writing\n";
+ ++$status;
+ }
+}
+else {
+ print STDERR "ERROR: Unable to open $input for reading\n";
+ ++$status;
+}
+
+exit($status); \ No newline at end of file
diff --git a/modules/Driver.pm b/modules/Driver.pm
index dba90516..82e51b02 100644
--- a/modules/Driver.pm
+++ b/modules/Driver.pm
@@ -275,7 +275,7 @@ sub run {
foreach my $cfile (@{$options->{'input'}}) {
## To correctly reference any pathnames in the input file, chdir to
## its directory if there's any directory component to the specified path.
- my($base) = basename($cfile);
+ my($base) = ($cfile eq '' ? '' : basename($cfile));
if (-d $cfile) {
$base = '';
diff --git a/modules/HTMLWorkspaceCreator.pm b/modules/HTMLWorkspaceCreator.pm
index 5e72bbea..e213a747 100644
--- a/modules/HTMLWorkspaceCreator.pm
+++ b/modules/HTMLWorkspaceCreator.pm
@@ -55,7 +55,6 @@ sub write_comps {
my($self) = shift;
my($fh) = shift;
my($creator) = shift;
- my($projects) = $self->get_projects();
my($project_info) = $self->get_project_info();
my($crlf) = $self->crlf();
@@ -63,11 +62,12 @@ sub write_comps {
"summary=\"MPC Projects\">$crlf" .
"<col style=\"background-color: darkcyan;\">$crlf" .
"<thead>$crlf" .
- "<tr><td>Projects</td></tr>$crlf" .
+ "<tr><td>Projects In Build Order</td></tr>$crlf" .
"</thead>$crlf" .
"<tbody>$crlf";
- foreach my $project (sort { $creator->file_sorter($a, $b) } @$projects) {
+ ## Sort the projects in build order instead of alphabetical order
+ foreach my $project ($self->sort_dependencies($self->get_projects(), 0)) {
my($name) = $$project_info{$project}->[0];
print $fh "<tr><td>" .
"<a href='$project'>$name</a>" .
diff --git a/templates/make.mpd b/templates/make.mpd
index e150b913..828cb636 100644
--- a/templates/make.mpd
+++ b/templates/make.mpd
@@ -3,13 +3,14 @@
#----------------------------------------------------------------------------
<%marker(top)%>
<%foreach(compilers)%>
+<%foreach(platforms)%>
CXX = <%cxx%>
<%if(ld)%>
LD = <%ld%>
<%else%>
LD = $(CXX) $(CCFLAGS) $(CPPFLAGS)
<%endif%>
-AR = <%if(ar)%><%ar%><%else%>ar<%endif%>
+AR = <%ar("ar")%>
<%if(nm)%>
NM = <%nm%>
<%endif%>
@@ -22,11 +23,10 @@ CPU = <%cpu%>
<%if(pic)%>
PICFLAGS = <%pic%>
<%endif%>
-CPPFLAGS = $(PICFLAGS) $(GENFLAGS)<%if(compile_flags)%> <%compile_flags%><%endif%><%if(cpu)%> -DCPU=$(CPU)<%endif%><%if(tempincopt)%> <%tempincopt%>$(TEMPINCDIR)<%endif%><%if(compilerflags)%> <%compilerflags%><%endif%><%if(build64bit && compilerflags64)%> <%compilerflags64%><%endif%><%if(pch_source && pchsupport)%><%foreach(pch_defines)%> -D<%pch_define%><%endfor%><%endif%><%foreach(platforms)%><%if(extracppflags)%> <%extracppflags%><%endif%><%endfor%><%if(includes)%><%foreach(includes)%> -I"<%include%>"<%endfor%><%endif%><%if(macros)%><%foreach(macros)%> -D<%macro%><%endfor%><%endif%>
+CPPFLAGS = $(PICFLAGS) $(GENFLAGS)<%if(compile_flags)%> <%compile_flags%><%endif%><%if(cpu)%> -DCPU=$(CPU)<%endif%><%if(tempincopt)%> <%tempincopt%>$(TEMPINCDIR)<%endif%><%if(compilerflags)%> <%compilerflags%><%endif%><%if(build64bit && compilerflags64)%> <%compilerflags64%><%endif%><%if(pch_source && pchsupport)%><%foreach(pch_defines)%> -D<%pch_define%><%endfor%><%endif%><%if(extracppflags)%> <%extracppflags%><%endif%><%if(includes)%><%foreach(includes)%> -I"<%include%>"<%endfor%><%endif%><%if(macros)%><%foreach(macros)%> -D<%macro%><%endfor%><%endif%>
OBJEXT = <%obj_ext%>
OUTPUT_OPTION = <%output_option(-o \"$@\")%>
COMPILE.cc = $(CXX) $(CCFLAGS) $(CPPFLAGS) <%compile_option("-c")%>
-<%foreach(platforms)%>
<%if(rc)%>
RESEXT = <%res_ext%>
<%endif%>
@@ -37,17 +37,13 @@ ARFLAGS = <%if(extraarflags)%><%extraarflags%> <%endif%><%arflags64%>
ARFLAGS = <%if(extraarflags)%><%extraarflags%> <%endif%><%arflags%>
<%endif%>
<%endif%>
-<%endfor%>
<%if(tempinc)%>
TEMPINCDIR = <%tempinc%><%if(tempincopt)%><%slash%><%project_name%><%endif%>
<%endif%>
LDFLAGS =<%if(libpaths)%><%foreach(libpaths)%> <%libpathopt(-L)%>"<%libpath%>"<%endfor%><%endif%><%if(linkflags)%> <%linkflags%><%endif%><%if(build64bit && linkflags64)%> <%linkflags64%><%endif%>
-<%endfor%>
CCC = $(CXX)
MAKEFILE = <%project_file%>
DEPENDENCIES = .depend.$(MAKEFILE)
-<%foreach(compilers)%>
-<%foreach(platforms)%>
<%if(exename)%>
BTARGETDIR = <%if(install)%><%install%><%else%>.<%endif%><%slash%><%targetoutdir%>
BIN = $(BTARGETDIR)<%exename%>$(EXESUFFIX)$(EXEEXT)
@@ -94,8 +90,6 @@ SHFLAGS = <%shflags%>
<%endif%>
<%endif%>
<%endif%>
-<%endfor%>
-<%endfor%>
SRC =<%if(pch_source && pchsupport)%> <%pch_source%><%endif%> <%source_files%>
LINK.cc = $(LD) $(LDFLAGS)
<%if(dynamicflags)%>
@@ -104,7 +98,7 @@ DYNAMICFLAGS =<%foreach(dynamicflags)%> -D<%dynamicflag%><%endfor%>
<%if(staticflags)%>
STATICFLAGS =<%foreach(staticflags)%> -D<%staticflag%><%endfor%>
<%endif%>
-EXPORTFLAGS = <%if(exename)%><%if(need_staticflags)%>$(STATICFLAGS)<%endif%><%else%><%foreach(compilers)%><%foreach(platforms)%><%if(dll_ext && sharedname)%>$(DYNAMICFLAGS)<%else%>$(STATICFLAGS)<%endif%><%endfor%><%endfor%><%endif%>
+EXPORTFLAGS = <%if(exename)%><%if(need_staticflags)%>$(STATICFLAGS)<%endif%><%else%><%if(dll_ext && sharedname)%>$(DYNAMICFLAGS)<%else%>$(STATICFLAGS)<%endif%><%endif%>
<%marker(macros)%>
#----------------------------------------------------------------------------
@@ -114,8 +108,6 @@ EXPORTFLAGS = <%if(exename)%><%if(need_staticflags)%>$(STATICFLAGS)<%endif%><%
<%if(exename)%>
all: $(BIN)<%if(postbuild)%> __postbuild__<%endif%>
-<%foreach(compilers)%>
-<%foreach(platforms)%>
<%if(specialscript)%>
specialscript:
@echo '<%specialscript%>' > specialscript
@@ -132,17 +124,13 @@ specialscript:
@$(RM) <%prelink%>
<%endif%>
-<%endfor%>
-<%endfor%>
$(BTARGETDIR):
@$(MKDIR) "$@"
-$(BIN): $(BTARGETDIR)<%foreach(compilers)%><%if(tempinc)%> $(TEMPINCDIR)<%endif%><%foreach(platforms)%><%if(prelink)%> <%targetoutdir%><%noextension(prelink)%>$(OBJEXT)<%endif%><%endfor%><%endfor%> $(OBJS)
+$(BIN): $(BTARGETDIR)<%if(tempinc)%> $(TEMPINCDIR)<%endif%><%if(prelink)%> <%targetoutdir%><%noextension(prelink)%>$(OBJEXT)<%endif%> $(OBJS)
$(LINK.cc) $(OBJS) $(LDLIBS) $(OUTPUT_OPTION)
<%endif%>
-<%foreach(compilers)%>
-<%foreach(platforms)%>
<%if(dll_ext)%>
<%if(sharedname)%>
all:<%if(version && versupport)%> $(SHLIB).<%version%><%endif%> $(SHLIB)<%if(postbuild)%> __postbuild__<%endif%>
@@ -157,14 +145,12 @@ $(SHLIB):
cd $(SHTARGETDIR) && ln -s $(SHLIB_BASE).<%version%> $(SHLIB_BASE)
<%endif%>
-$(SHLIB)<%if(version && versupport)%>.<%version%><%endif%>: $(SHTARGETDIR) <%foreach(compilers)%><%if(tempinc)%>$(TEMPINCDIR) <%endif%><%endfor%>$(OBJS)
-<%foreach(compilers)%>
+$(SHLIB)<%if(version && versupport)%>.<%version%><%endif%>: $(SHTARGETDIR) <%if(tempinc)%>$(TEMPINCDIR) <%endif%>$(OBJS)
<%if(dmclink)%>
link /impl <%if(pch_source && pchsupport)%><%targetoutdir%><%noextension(pch_source)%>$(OBJEXT)+<%endif%><%foreach(source_files)%><%targetoutdir%><%noextension(source_file)%>$(OBJEXT)<%fornotlast("+")%><%endfor%>,$@,<%foreach(platforms)%><%ldlibs%><%endfor%><%if(rc)%><%foreach(resource_files)%><%forfirst(",,")%><%targetoutdir%><%resource_file%>$(RESEXT)<%fornotlast("+")%><%endfor%><%endif%>
<%else%>
<%foreach(platforms)%><%if(dld)%><%dld%> $(LDFLAGS)<%else%>$(LINK.cc)<%endif%><%endfor%> $(SHFLAGS) $(OBJS) $(LDLIBS) $(OUTPUT_OPTION)
<%endif%>
-<%endfor%>
<%else%>
<%if(staticname)%>
all: $(LIB)<%if(postbuild)%> __postbuild__<%endif%>
@@ -177,23 +163,17 @@ all: $(LIB)<%if(postbuild)%> __postbuild__<%endif%>
<%endif%>
<%endif%>
-<%endfor%>
-<%endfor%>
<%if(!exename)%>
$(LTARGETDIR):
@$(MKDIR) "$@"
<%endif%>
<%if(staticname)%>
-$(LIB): $(LTARGETDIR) <%foreach(compilers)%><%if(tempinc)%>$(TEMPINCDIR) <%endif%><%endfor%>$(OBJS)
-<%foreach(compilers)%>
-<%foreach(platforms)%>
+$(LIB): $(LTARGETDIR) <%if(tempinc)%>$(TEMPINCDIR) <%endif%>$(OBJS)
$(AR) $(ARFLAGS) $(LIB) $(OBJS)<%if(tempinc)%> `find $(TEMPINCDIR) -name \*.o\*`<%endif%>
<%if(ranlib)%>
ranlib $(LIB)
<%endif%>
-<%endfor%>
-<%endfor%>
<%endif%>
<%if(custom_types)%>
@@ -248,7 +228,6 @@ all: $(GENERATED_DIRTY)<%if(postbuild)%> __postbuild__<%endif%>
generated: $(GENERATED_DIRTY)
@-:
-<%foreach(compilers)%>
<%if(tempinc)%>
$(TEMPINCDIR):
@-test -d $(TEMPINCDIR) || $(MKDIR) $(TEMPINCDIR) 2> $(NUL) || true
@@ -270,9 +249,7 @@ $(TEMPINCDIR):
$(COMPILE.cc) <%if(pchuse && pch_source && pchsupport)%><%pchuse%><%pch_header%><%pchext%> <%if(pchstop)%><%pchstop%><%pch_header%><%endif%><%endif%>$(EXPORTFLAGS) $(OUTPUT_OPTION) <%source_file%>
<%endfor%>
-<%endfor%>
<%if(resource_files)%>
-<%foreach(platforms)%>
<%if(rc)%>
<%foreach(resource_files)%>
<%targetoutdir%><%resource_file%>$(RESEXT):
@@ -280,18 +257,15 @@ $(TEMPINCDIR):
<%endfor%>
<%endif%>
-<%endfor%>
<%endif%>
clean:
-$(RM) $(OBJS)
-<%foreach(compilers)%>
<%if(pch_source && pchsupport)%>
-$(RM) <%pch_header%><%pchext%>
<%endif%>
<%if(clean)%>
-$(RM) <%clean%>
<%endif%>
-<%endfor%>
realclean: clean
-$(RM) <%if(exename)%>$(BIN)<%else%><%if(version && versupport)%>$(SHLIB).<%version%> <%endif%>$(SHLIB) $(LIB)<%endif%>
@@ -305,7 +279,6 @@ __postbuild__:
<%endif%>
<%marker(local)%>
-<%foreach(compilers)%>
<%if(dependencies)%>
#----------------------------------------------------------------------------
# Dependencies
@@ -324,4 +297,5 @@ depend:
include $(DEPENDENCIES)
<%endif%>
<%endfor%>
+<%endfor%>
<%marker(bottom)%>