📄 tmake
字号:
if ( $c eq "unix" ) { return 0 if !$is_unix; } elsif ( $c eq "win32" ) { return 0 if $is_unix; } elsif ( ($c ne $tmake_platform) && !Config($c) ) { return 0; } } return 1;}## Project(strings)## This is a powerful function for setting or reading project variables.# Returns the resulting project variables (joined with space between).## Get a project variable:# $s = Project("TEMPLATE"); -> $s = "TEMPLATE"## Set a project variable:# Project("TEMPLATE = lib"); -> TEMPLATE = lib# Project("CONFIG =";) -> CONFIG empty## Append to a project variable:# Project("CONFIG = qt"); -> CONFIG = qt# Project("CONFIG += debug"); -> CONFIG = qt debug## Append to a project variable if it does not contain the value already:# Project("CONFIG = qt release"); -> CONFIG = qt release# Project("CONFIG *= qt"); -> CONFIG = qt release# Project("CONFIG *= opengl"); -> CONFIG = qt release opengl## Subtract from a project variable:# Project("THINGS = abc xyz"); -> THINGS = abc xyz# Project("THINGS -= abc"); -> THINGS = xyz## Search/replace on a project variable:# Project("CONFIG = tq opengl"); -> CONFIG = tq opengl# Project("CONFIG /= s/tq/qt/"); -> CONFIG = qt opengl## The operations can be performed on several project variables at a time.## Project("TEMPLATE = app", "CONFIG *= opengl", "THINGS += klm");#sub Project { my @settings = @_; my($r,$if_var,$t,$s,$v,$p,$c); $r = ""; foreach ( @settings ) { $v = $_; if ( $v =~ s/^\s*((?:(?:[\w\-]+\s*:\s*){1,10})?)(\w+)\s*(\+=|\*=|\-=|\/=|=)// ) { $if_var = $1; if ( $if_var ne "" ) { $if_var =~ s/\s//g; chop $if_var; return "" if !&project_var_condition($if_var); } $t = $2; $s = $3; if ( ! $notrim_whitespace ) { $v =~ s/^\s+//; # trim white space $v =~ s/\s+$//; } $v = expand_project_var($v); $p = $project{$t}; if ( $s ne "=" && $v eq "" ) { # nothing to append, subtract or sed } elsif ( $s eq "=" ) { # set variable $p = $v; } elsif ( $s eq "+=" ) { # append if ( $p eq "" ) { $p = $v; } else { $p .= " " . $v; } } elsif ( $s eq "*=" ) { # append if not contained if ( !($p =~ /(?:^|\s)\Q$v\E(?:\s|$)/) ) { if ( $p eq "" ) { $p = $v; } else { $p .= " " . $v; } } } elsif ( $s eq "-=" ) { # subtract $p =~ s/$v\s*//g; } elsif ( $s eq "/=" ) { # sed $cmd = '$p =~ ' . $v; eval $cmd; } $project{$t} = expand_project_var($p); } else { $p = expand_project_var($project{$v}); } if ( $p ne "" ) { $r = ($r eq "") ? $p : ($r . " " . $p); } } return $r;}## Substitute(string)## This function substitutes project variables in a text.## Example:# Substitute('The project name is "$$PROJECT"')#sub Substitute { my($subst) = @_; $text = expand_project_var($subst); return $text;}## ScanProject(file)## Scans a project file. Inserts project variables into the global# associative project array.#sub ScanProject { my($file) = @_; my($var,$val,@v,$more,$line,$endmark); $var = ""; $line = 0; open(TMP,&fix_path($file)) || return 0; &tmake_verb("Reading the project file $file"); while ( <TMP> ) { $line++; s/\#.*//; # strip comment s/^\s+//; # strip white space s/\s+$//; if ( /^\s*((?:(?:(?:[\w\-]+\s*:\s*){1,10})?)\w+\s*(\+|\-|\*|\/)?=)/ ) { $var = $1; # var also contains the ".=" s/^.*?=\s*//; if ( /^\<\<(.*)$/ ) { $endmark = $1; $val = ""; while ( <TMP> ) { $line++; if ( /^\Q$endmark\E$/ ) { $endmark = ""; last; } $val .= $_; } if ( $endmark ne "" ) { tmake_error("$file:$line: End marker $endmark not found"); } chop $val if ( $val ne "" ); $notrim_whitespace++; Project( $var . $val ); $notrim_whitespace--; $var = ""; $_ = ""; } } if ( $var ne "" ) { $more = ( $_ =~ s/\s*\\\s*$// ); # more if \ at end of line push( @v, split( /\s+/, $_ ) ); if ( ! $more ) { $val = join(" ",@v); Project( $var . $val ); $var = ""; @v = (); } } elsif ( $_ ne "" ) { tmake_error("$file:$line: Syntax error"); } } close(TMP); &tmake_verb("Done reading the project file $file"); return 1;}## IncludeTemplate(template_name)## Includes and processes a template file.## Below, we read the template file and executes any perl code found.# Perl code comes after "#$". The variable $text contains the text# to replace the perl code that was executed.# Template comments begin with "#!".#sub IncludeTemplate { my($t_name) = @_; my($cmd,$cmd_block,$cmd_end,$is_cmd_block,$saveline,$spaceonly); local($text); local(*T); $t_name = &find_template($t_name); if ( $tmake_template_dict{$t_name} ) { &tmake_error("Cyclic template inclusion for $t_name"); } else { $tmake_template_dict{$t_name} = 1; } $template_base = $t_name; $template_base =~ s-(.*[/\\]).*-$1-; &tmake_verb("Reading the template $t_name"); open(T,&fix_path($t_name)) || &tmake_error("Cannot open template file \"$t_name\""); while ( <T> ) { if ( /\#\!/ ) { # tmake comment s/\s*\#\!.*//; next if /^$/; } if ( /\#\$(\{)?\s*(.*)\n/ ) { # code $cmd = $2; $is_cmd_block = defined($1) && ($1 eq "{"); s/\#\$.*\n//; if ( $is_cmd_block ) { # code block #${ ... $saveline = $_; $cmd_block = $cmd; $cmd_end = 0; while ( <T> ) { $cmd = $_; $cmd =~ s/\s*\#\!.*//; # tmake comment if ( $cmd =~ /^\s*\#\$\}/ ) { $_ = ""; $cmd_end = 1; last; } $cmd =~ s/^\s*\#(\$)?\s*//; $cmd_block .= $cmd; } $cmd_end || &tmake_error('#$} expected but not found'); $cmd = $cmd_block; $_ = $saveline; } $spaceonly = /^\s*$/; $saveline = $_; &tmake_verb("Evaluate: $cmd"); $text = ""; eval $cmd; die $@ if $@; next if $spaceonly && ($text =~ /^\s*$/); print $saveline . $text . "\n" if $output_count <= 0; } else { # something else print if $output_count <= 0; } } close( T );}## Expand(var) - appends to $text## Expands a list of $project{} variables with a space character between them.#sub Expand { my @vars = @_; my($t); $t = Project(@vars); if ( $text eq "" ) { $text = $t; } elsif ( $t ne "" ) { $text .= " " . $t; } return $text;}## ExpandGlue(var,prepend,glue,append) - appends to $text## Expands a $project{} variable, splits on whitespace# and joins with $glue. $prepend is put at the start# of the string and $append is put at the end of the# string. The resulting string becomes "" if the project# var is empty or not defined.## Example:## The project file defines:# SOURCES = a b c## ExpandGlue("SOURCES","<","-",">")## The result:# $text = "<a-b-c>"#sub ExpandGlue { my($var,$prepend,$glue,$append) = @_; my($t,$v); $v = Project($var); if ( $v eq "" ) { $t = ""; } else { $t = $prepend . join($glue,split(/\s+/,$v)) . $append; } if ( $text eq "" ) { $text = $t; } elsif ( $t ne "" ) { $text .= " " . $t; } return $text;}## ExpandList(var) - sets $text.## Suitable for expanding HEADERS = ... etc. in a Makefile#sub ExpandList { my($var) = @_; return ExpandGlue($var,""," ${linebreak}\n\t\t","");}## ExpandPath(var,prepend,glue,append) - appends to $text## Expands a $project{} variable, splits on either ';' or# whitespace and joins with $glue. $prepend is put at the# start of the string and $append is put at the end of the# string. The resulting string becomes "" if the project# variable is empty or not defined.## If the variable contains at least one semicolon or tmake# is running on Windows, the resulting items are put in# double-quotes.## Example:## The project file defines:# INCLUDEPATH = "C:\qt\include;c:\program files\msdev\include## ExpandPath("INCLUDEPATH","-I","-I","")## The result:# $text = -I"c:\qt\include" -I"c:\program files\msdev\include"#sub ExpandPath { my($var,$prepend,$glue,$append) = @_; my($t,$v); my($s); $v = Project($var); if ( $v eq "" ) { $t = ""; } else { if ( $v =~ /;/ || !$is_unix ) { $prepend .= '"'; $glue = '"' . $glue . '"'; $append = '"' . $append; } if ( $v =~ /;/ ) { $t = $prepend . join($glue,split(/;+/,$v)) . $append; } else { $t = $prepend . join($glue,split(/\s+/,$v)) . $append; } } if ( $text eq "" ) { $text = $t; } elsif ( $t ne "" ) { $text .= " " . $t; } return $text;}## TmakeSelf()## Generates makefile rule to regenerate the makefile using tmake.#sub TmakeSelf { my $a = "tmake $project_name"; if ( $nodepend ) { $a .= " -nodepend"; } if ( $outfile ) { $text = "tmake: $outfile\n\n$outfile: $project_name\n\t"; $a .= " -o $outfile"; } else { $text = "tmake:\n\t"; } $text .= $a}## Objects(files)## Replaces any extension with .o ($obj_ext).#sub Objects { local($_) = @_; my(@a); @a = split(/\s+/,$_); foreach ( @a ) { s-\.\w+$-.${obj_ext}-; if ( defined($project{"OBJECTS_DIR"}) ) { s-^.*[\\/]--; $_ = $project{"OBJECTS_DIR"} . $_; } } return join(" ",@a);}## UicImpls(files)## Replaces any extension with .h ($uic_impl).#sub UicImpls { local($_) = @_; my(@a); @a = split(/\s+/,$_); foreach ( @a ) { s-\.\w+$-.${uic_impl}-; } return join(" ",@a);}## UicDecls(files)## Replaces any extension with .cpp ($uic_decl).#sub UicDecls { local($_) = @_; my(@a); @a = split(/\s+/,$_); foreach ( @a ) { s-\.\w+$-.${uic_decl}-; } return join(" ",@a);}## MocSources(files)## Only useful for uic files!## Replaces any extension with .cpp ($cpp_ext) and adds moc_ ($moc_pre)#sub MocSources { local($_) = @_; my( @a, $t, $h, $f ); @a = split(/\s+/,$_); foreach $t ( @a ) { $h = $t; $h =~ s-\.\w+$-.${uic_decl}-; $f = $t; $t =~ s-^(.*[/\\])?([^/\\]*?)\.(\w+)$-$1${moc_pre}$2.${cpp_ext}-; if ( defined($project{"MOC_DIR"}) ) { $t =~ s-^.*[\\/]--; $t = $project{"MOC_DIR"} . $t; } $moc_output{$h} = $t; $moc_input{$t} = $h; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -