📄 genmake.pl
字号:
# Description:
#\*___________________________________________________________________________*/
sub target
{
( $filehandle ) = @_;
@subdirs = ();
local( $name, $begin_build, $end_build, $objs, $depends, @objlist,
@libraries, $tmp );
while( <$filehandle> )
{
$_ = &processline( $_ );
if ( /^#if\s*(.*)/ )
{
(!$ifstate) || die
"Nested '#if' statements are not supported!\n";
$condition = eval $1;
$ifstate = 1;
}
elsif ( /^#elsif\s*$/ )
{
($ifstate eq 1) || die
"Syntax error: '#elsif' without '#if' statement!\n";
$ifstate = 2;
$condition = !$condition;
}
elsif ( /^#endif\s*$/ )
{
($ifstate) || die
"Syntax error: '#endif' without '#if' or '#elsif' statement!\n";
$ifstate = 0;
$condition = 1;
}
elsif ( /^(\s)*#/ )
{ next; }
elsif ( /\<subdirs\>*/i )
{
$condition || next;
print OUT &canonical($name).'_'."SUBDIRS:\n";
&subdirectories( INP, $name );
}
elsif ( /\<\/target\>*/i )
{ $condition || next; last; }
elsif ( /\<\/.*/ )
{ die "Expecting </target> at line $line\n"; }
elsif ( /^name*=*/i )
{
$condition || next;
s/^name*=//i; $name = $_;
print OUT "#\n# Target: \'$_\'\n#\n";
# print OUT &canonical($name).'_'."SUBDIRS:\n";
}
elsif ( /^build.*=.*/i )
{
$condition || next;
s/^build.*=//i;
if ($begin_build ne "")
{
$begin_build .= "\n\t";
}
$begin_build .= $_;
}
elsif ( /^executable[\w|\s]*=.*/i )
{
$condition || next;
s/^executable[\w|\s]*=//i;
$tmp=&mergepattern( $config_ld, $_ );
$begin_build=$tmp.' '.$libpath.' ';
$end_build = '$(CONFIG_EXTRALIBS)';
}
elsif ( /^source*=*/i )
{
$condition || next;
s/^source*=//i;
local( @tmp, $src_suffix, $obj_suffix, @filepatterns, $tmp2 );
@tmp = split( /\s/, $_ );
$src_suffix = @tmp[0];
@filepatterns = splice( @tmp, 1, $#tmp );
$tmp2 = &dosources( $name, $src_suffix, $config_objextn,
@filepatterns );
push( @objlist, ( "\$\(".$tmp2."\)" ) );
}
elsif ( /^objs*=*/i )
{ $condition || next; s/^objs*=//i; $objs = $_; }
elsif ( /^depends*=*/i )
{ $condition || next; s/^depends*=//i; $depends = $_; }
elsif ( /^libraries*=*/i )
{ $condition || next; s/^libraries\s*=//i;
push( @libraries, split( /\s/, $_ ) ); }
elsif ( /^staticlibdeps.*=.*$/i )
{
$condition || next;
s/^staticlibdeps\s*=//i;
foreach $tmp ( split( /\s/, $_ ) )
{
push( @libraries, ( $tmp ) );
};
}
elsif ( /^staticlib[\w|\s]*=.*/i )
{
$condition || next;
s/^staticlib[\w|\s]*=//i;
$tmp=&mergepattern( $config_fulllib, $_ );
$_=$config_archive; s/^(.*)__substme(.*)$/$1/;
$begin_build = $_.$tmp;
}
elsif ( /^sharedlib[\w|\s]*=.*/i )
{
$condition || next;
s/^sharedlib[\w|\s]*=//i;
$begin_build = &mergepattern( $config_ld_shared, $_ );
$begin_build=$begin_build.' '.$libpath.' ';
$end_build = '$(CONFIG_EXTRALIBS)';
}
elsif ( /^AddToAll/i )
{ $condition || next; push( @all_targets, ( $name ) ); }
elsif ( /^AddToClean/i )
{ $condition || next; push( @clean_targets, ( $name ) ); }
elsif ( /^AddToGenmake/i )
{ $condition || next; push( @genmake_targets, ( $name ) ); }
else
{ print OUT "$_\n"; };
# { die "Unknown target attribute $_\n"; };
next;
};
print OUT "$name: $depends $objs @objlist ";
if ( ($#subdirs) >= 0 )
{ print OUT &canonical($name)."_SUBDIRS"; };
print OUT "\n";
print OUT "\t$begin_build $objs @objlist ";
foreach $tmp ( @libraries )
{ print OUT &mergepattern($config_linklib, $tmp).' '; };
print OUT " $end_build\n";
return;
};
#/*___________________________________________________________________________*\
# *
# Function:
# Synopsis:
# Description:
#\*___________________________________________________________________________*/
sub dosources
{
( $name, $src_suffix, $obj_suffix, @filepatterns ) = @_;
local( $filepattern, $target, @sources, $src, $obj );
foreach $filepattern ( @filepatterns )
{
push( @sources, <${filepattern}> );
};
$target = &canonical( $name );
$_ = $src_suffix; tr/a-z/_/cs;
$src = $target."_".$_;
$_ = $obj_suffix; tr/a-z/_/cs;
$obj = $src."_OBJS";
print OUT $src."=";
foreach $file ( @sources )
{ print OUT "$file "; };
print OUT "\n".$obj."=\$(".$src.":$src_suffix=$obj_suffix)\n";
return $obj;
}
#/*___________________________________________________________________________*\
# *
# Function:
# Synopsis:
# Description:
#\*___________________________________________________________________________*/
sub verbose_canonical
{
( $_ ) = @_;
tr/a-zA-Z0-9/\_/c;
tr/a-z/A-Z/;
return $_;
};
#/*___________________________________________________________________________*\
# *
# Function:
# Synopsis:
# Description:
# The canonical name generated by canonical is really big and ugly, makefiles
# are almost impossible to read. Instead the a unique canonical name
# like "TARG1", "TARG2" will be created and associated with the
# canonical name via a hash table.
#\*___________________________________________________________________________*/
sub canonical
{
( $_ ) = @_;
local( $can ) = &verbose_canonical( $_ );
if ( length( $Names{$can} )==0 )
{
# new name
$Names{$can} = "TARG".$name_index;
$name_index++;
};
return $Names{$can};
};
#/*___________________________________________________________________________*\
# *
# Function:
# Synopsis:
# Description:
#\*___________________________________________________________________________*/
sub global
{
( $filehandle ) = @_;
local( @includes, @local_cflags, @local_cxxflags, $ifstate );
while( <$filehandle> )
{
$_ = &processline( $_ );
if ( /^#if\s*(.*)/ )
{
(!$ifstate) || die
"Nested '#if' statements are not supported!\n";
$condition = eval $1;
$ifstate = 1;
}
elsif ( /^#elsif\s*$/ )
{
($ifstate eq 1) || die
"Syntax error: '#elsif' without '#if' statement!\n";
$ifstate = 2;
$condition = !$condition;
}
elsif ( /^#endif\s*$/ )
{
($ifstate) || die
"Syntax error: '#endif' without '#if' or '#elsif' statement!\n";
$ifstate = 0;
$condition = 1;
}
elsif ( /^(\s)*#/ )
{ next; }
elsif ( /\<\/global\>*/i )
{ $condition || next; last; }
elsif ( /\<\/.*/ )
{ die "Expecting </global> at line $line\n"; }
elsif ( /^libpath.*=.*/i )
{
$condition || next;
$libpath='';
s/^libpath*=//i;
local( $tmp, $begin, $end, @thislines );
@thisline=split( /\s/, $_ );
$_=$config_libpath; s/^(.*)__substme(.*)$/$1/; $begin=$_;
$_=$config_libpath; s/^(.*)__substme(.*)$/$2/; $end=$_;
foreach $tmp ( @thisline )
{ $libpath=$libpath.$begin.$tmp.$end.' '; };
}
elsif ( /^includes*=*/i )
{ $condition || next; s/^includes*=//i; @includes = split( /\s/, $_ ); }
elsif ( /^local_cxxflags*=*/i )
{ $condition || next; s/^local_cxxflags*=//i; @local_cxxflags = split( /\s/, $_ ); }
elsif ( /^local_cflags*=*/i )
{ $condition || next; s/^local_cflags*=//i; @local_cflags = split( /\s/, $_ ); }
elsif ( /\<subdirs\>*/i )
{ $condition || next; &subdirectories( INP, '' ); }
else
{
$condition || next; print OUT "$_\n";
};
next;
};
print OUT "PIINCLUDE=@includes\n";
print OUT "LOCAL_CFLAGS=@local_cflags\n";
print OUT "LOCAL_CXXFLAGS=@local_cxxflags\n";
print OUT "\n";
return;
};
#/*___________________________________________________________________________*\
# *
# Function:
# Synopsis:
# Description:
#\*___________________________________________________________________________*/
sub dosubdir
{
( $subdir ) = @_;
print OUT 'Subdirectory '.$subdir."\n";
`cd $subdir; perl $scriptdir/genmake.pl; cd ..`
|| die 'Genmake failed for $subdir\n';
return;
};
#/*___________________________________________________________________________*\
# *
# Function:
# Synopsis:
# Description:
#\*___________________________________________________________________________*/
sub mergepattern
{
( $pattern, $value ) = @_;
$_=$pattern; s/(.*)__substme(.*)/$1/;
$tmp=$_;
$_=$pattern; s/(.*)__substme(.*)/$2/;
$_=$tmp.$value.$_;
if ( /(.*)__substme(.*)/ )
{ return &mergepattern( $_, $value ); }
else
{ return $_; }
}
#/*___________________________________________________________________________*\
# *
# Function:
# Synopsis:
# Description:
#\*___________________________________________________________________________*/
sub processline
{
( $newline ) = @_;
$_ = $newline;
$line++;
s/^[\s*]//g; # remove leading whitespace
s/[\s*]$//g; # remove trailing whitespace
return $_;
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -