📄 tmake
字号:
#!/usr/bin/perl############################################################################# $Id: tmake,v 1.3 2003/07/21 12:08:52 pfremy Exp $## Creates a Makefile from a template and a project file.## Copyright (C) 1996-2000 by Trolltech AS. All rights reserved.## Permission to use, copy, modify, and distribute this software and its# documentation for any purpose and without fee is hereby granted, provided# that this copyright notice appears in all copies.# No representations are made about the suitability of this software for any# purpose. It is provided "as is" without express or implied warranty.### Some important, global variables in tmake:# cpp_ext C++ extension added to moc output (.cpp)# obj_ext Object file extension (.o on Unix, .obj otherwise)# moc_aware Will scan for files containing Qt signals/slots# moc_pre Moc prefix for generated moc file: x.h -> moc_x.cpp# moc_ext Moc extension for generated moc file: x.cpp -> x.moc# moc_cmd The moc command in your makefile, $(MOC)# uic_decl Uic extension for generated declaration file: x.ui -> x.h# uic_impl Uic extension for generated implementation file: x.ui -> x.cpp# uic_cmd The uic command in your makefile, $(UIC)# uic_decl_path The path where the generated decl files from uic files are created, $(INTERFACE_DECL_PATH)# linebreak Line break character (\)# dir_sep Directory separator (/ on Unix, \ on Windows)# is_unix Autodetected. If not Unix, assume Windows (Win32).## If you need to customize any of these settings, do it before# calling StdInit() in the template file.#############################################################################$TMAKE_VERSION = "1.11";if ($] < 5.0) { &tmake_error("This program requires perl version 5 or newer");}$cpp_ext = "cpp";$moc_aware = 0;$moc_pre = "moc_";$moc_ext = "moc";$moc_cmd = '$(MOC)';$uic_decl = "h";$uic_impl = "cpp";$uic_cmd = '$(UIC)';$uic_decl_path = '$(INTERFACE_DECL_PATH)';%uic_dependency = ();$linebreak = "\\";$really_unix = &check_unix();$is_unix = $really_unix;$dir_sep = $is_unix ? "/" : "\\";$obj_ext = $is_unix ? "o" : "obj";$depend_path = "";$nodepend = 0;$output_count = 0;$notrim_whitespace = 0;$read_tmakeconf = 0;$template_name = "";$project_name = "";$outfile = "";%project = ();$eval_quit = 0;$project{"TMAKEPATH"} = $ENV{"TMAKEPATH"} . ";" . $ENV{"HOME"} . "/.tmake/";while ( @ARGV ) { # parse command line args $_ = shift @ARGV; if ( s/^-// ) { if ( /^e(.*)/ ) { if ( ! $read_tmakeconf ) { $read_tmakeconf = 1; &ScanProject( &find_template("tmake.conf") ); } $text = ""; eval( ($1 eq "") ? shift @ARGV : $1 ); die $@ if $@; print $text . "\n" if ($text ne ""); $eval_quit = 1; } elsif ( /^t(.*)/ ) { $template_name = ($1 eq "") ? shift @ARGV : $1; } elsif ( /^o(.*)/ ) { $outfile = ($1 eq "") ? shift @ARGV : $1; ($outfile eq "-") && ($outfile = ""); if ( $outfile ne "" ) { open(STDOUT,">" . &fix_path($outfile)) || &tmake_error("Cannot create \"$outfile\": $!"); } $project{"OUTFILE"} = $outfile; } elsif ( /^p(.*)/ ) { # # The -p option is obsolete and will be removed in the next # tmake release. # &tmake_warning( "-p option obsolete, instead use \"tmake file1.pro file2.pro ...\""); my($pf) = ($1 eq "") ? shift @ARGV : $1; if ( ! $read_tmakeconf ) { $read_tmakeconf = 1; &ScanProject( &find_template("tmake.conf") ); } if ( ! ($pf =~ /\.pro$/i) && -f &fix_path($pf . ".pro") ) { $pf .= ".pro"; } if ( $project_name eq "" ) { $project_name = $pf; $project{"PROJECT"} = $project_name; $project{"PROJECT"} =~ s/\.pro$//i; $project{"TARGET"} = $project{"PROJECT"}; } if ( !&ScanProject($pf) ) { &tmake_error("Cannot open project file \"$pf\""); } } elsif ( /^unix$/ ) { $is_unix = 1; $dir_sep = "/"; $obj_ext = "o"; } elsif ( /^win32$/ ) { $is_unix = 0; $dir_sep = "\\"; $obj_ext = "obj"; } elsif ( /^nodepend$/ ) { $nodepend = 1; # don't generate dependencies } elsif ( /^v$/ ) { $verbose = 1; } else { &tmake_usage(); } } elsif ( /^\s*((?:[^:\s]*?:)?)(\w+)\s*(\+=|\*=|\-=|\/=|=)/ ) { my($arg) = $_; if ( ! $read_tmakeconf && ! (/^\s*TMAKEPATH/) ) { $read_tmakeconf = 1; &ScanProject( &find_template("tmake.conf") ); } Project( $arg ); # manual project setting } else { my($pf) = $_; if ( ! $read_tmakeconf ) { $read_tmakeconf = 1; &ScanProject( &find_template("tmake.conf") ); } if ( ! ($pf =~ /\.pro$/i) && -f &fix_path($pf . ".pro") ) { $pf .= ".pro"; } if ( $project_name eq "" ) { $project_name = $pf; $project{"PROJECT"} = $project_name; $project{"PROJECT"} =~ s/\.pro$//i; $project{"TARGET"} = $project{"PROJECT"}; } if ( !&ScanProject($pf) ) { &tmake_error("Cannot open project file \"$pf\""); } }}&tmake_verb("Version $TMAKE_VERSION (runtime environment: " . ($really_unix ? "Unix" : "Win32") . ")\n" );if ( $eval_quit ) { &tmake_verb("Done!"); exit 0;}($project_name eq "") && &tmake_usage();if ( $template_name eq "" ) { $template_name = $project{"TEMPLATE"} ? $project{"TEMPLATE"} : "default.t";}$template_name = &find_template($template_name);&IncludeTemplate($template_name);&tmake_verb("Done!");exit 0; # finished!############################################################################### Subroutines from here################################################################################ tmake_usage()## Prints a message about program usage and exits#sub tmake_usage { print STDERR "Usage:\n tmake [options] project-files\n"; print STDERR "Options:\n"; print STDERR " -e expr Evaluate expression, ignore template file\n"; print STDERR " -nodepend Don't generate dependency information\n"; print STDERR " -o file Write output to file\n"; print STDERR " -t file Specify a template file\n"; print STDERR " -unix Create output for Unix (auto detects)\n"; print STDERR " -v Verbose/debug mode\n"; print STDERR " -win32 Create output for Win32 (auto detects)\n"; exit 1;}## tmake_error(msg)## Prints the message and exits#sub tmake_error { my($msg) = @_; print STDERR "tmake error: " . $msg . "\n"; exit 1;}## tmake_warning(msg)## Prints the warning message#sub tmake_warning { my($msg) = @_; print STDERR "tmake warning: " . $msg . "\n";}## tmake_verb()## Prints a verbose message#sub tmake_verb { my($msg) = @_; $verbose && print STDERR "tmake: " . $msg . "\n";}## check_unix()## Returns 1 if this is a Unix, 0 otherwise.#sub check_unix { my($r); $r = 0; if ( -f "/bin/uname" ) { $r = 1; (-f "\\bin\\uname") && ($r = 0); } if ( -f "/usr/bin/uname" ) { $r = 1; (-f "\\usr\\bin\\uname") && ($r = 0); } return $r;}## find_template(filename)## Looks for the template file.# 1. search the current directory# 2. search the directories in TMAKEPATH# 3. search in $HOME/.tmake#sub find_template { my($filename) = @_; my($tb,$d,$p,@dirs); if ( !defined($template_base) || ($template_base eq "") ) { $tb = ""; } else { $tb = $template_base . ";"; } $d = $tb . $project{"TMAKEPATH"}; @dirs = (""); push @dirs, &split_path( $d ); $filename .= ".t" unless ($filename =~ /\.\w+$/); for $d ( @dirs ) { $p = $d . $filename; if ( -f &fix_path($p) ) { if ( $filename eq "tmake.conf" ) { $tmake_platform = $d; $tmake_platform =~ s-.*[/\\]([^/\\]*)[/\\]-$1-; &tmake_verb("Detected platform $tmake_platform"); } return $p; } return ($d . $filename) if ( -f &fix_path($d . $filename) ); } &tmake_error("Template file " . $filename . " not found");}############################################################################### User functions################################################################################ StdInit()## Standard initialization#sub StdInit { my($p); return if $stdinit_done; $stdinit_done = 1; if ( defined($project{"OBJECTS_DIR"}) ) { $project{"OBJECTS_DIR"} = FixPath($project{"OBJECTS_DIR"}); &mkdirp($project{"OBJECTS_DIR"},0777); } if ( defined($project{"MOC_DIR"}) ) { $project{"MOC_DIR"} = FixPath($project{"MOC_DIR"}); &mkdirp($project{"MOC_DIR"},0777); } if ( defined($project{"DESTDIR"}) ) { $project{"DESTDIR"} = FixPath($project{"DESTDIR"}); &mkdirp($project{"DESTDIR"},0777); } $project{"OBJECTS"} = &Objects($project{"SOURCES"}); $project{"UICDECLS"}= &UicDecls($project{"INTERFACES"}); $project{"UICIMPLS"}= &UicImpls($project{"INTERFACES"}); $project{"UICOBJECTS"}= &Objects($project{"INTERFACES"}); # $project{"HEADERS"}.= " " . &UicDecls($project{"INTERFACES"}); # $project{"SOURCES"}.= " " . &UicImpls($project{"INTERFACES"}); $project{"OBJECTS"}.= " " . &Objects($project{"INTERFACES"}); foreach $m ( $project{"INTERFACES"} ) { $decl = $m; $decl =~ s/\.ui$/\.$uic_decl/; $impl = $m; $impl =~ s/\.ui$/\.$uic_impl/; $uic_dependency{ $impl } = $decl . " ${linebreak}\n\t\t" . $m; } if ( $moc_aware ) { $project{"_HDRMOC"} = &list_moc($project{"HEADERS"},$moc_pre,$cpp_ext); $project{"_SRCMOC"} = &list_moc($project{"SOURCES"},"",$moc_ext); $project{"OBJMOC"} = &Objects($project{"_HDRMOC"}); $p = $project{"OBJMOC"} . " " . &Objects( &MocSources($project{"INTERFACES"} ) ); $p =~ s/^\s+//; $p =~ s/\s+$//; $project{"OBJMOC"} = $p; #$p = $project{"SRCMOC"} . " " . &MocSources($project{"INTERFACES"} ); $p = $project{"_HDRMOC"} . " " . &MocSources($project{"INTERFACES"} ) . " " . $project{"_SRCMOC"}; $p =~ s/^\s+//; $p =~ s/\s+$//; $project{"SRCMOC"} = $p; } &AddIncludePath("");}sub FixPath { my($p) = @_; if ( !defined($p) || ($p eq "") || ($p eq ".") ) { $p = ""; } else { $p .= $dir_sep; $p =~ s-[\\/]+-${dir_sep}-g; } return $p;}## Config(name)## Returns true if the project variable CONFIG contains the# configuration name.#sub Config { my($name) = @_; return $project{"CONFIG"} =~ /\b\Q$name\E\b/;}## DisableOutput()## Disables tmake output. Must be restored by calling a corresponding# EnableOutput().#sub DisableOutput { $output_count++;}## EnableOutput()## Enables tmake output again after DisableOutput() has been called.#sub EnableOutput { $output_count--;}## Now() - sets $text## Sets $text to the current date and time.#sub Now { my($sec,$min,$hour,$mday,$mon,$year); ($sec,$min,$hour,$mday,$mon,$year) = localtime(time()); $text = sprintf("%02d:%02d, %4d/%02d/%02d", $hour, $min, 1900+$year, 1+$mon, $mday);}## expand_project_var(var)## Internal function for Project().# Expands a project value string.#sub expand_project_var { my($v) = @_; my($c); return "" if !defined($v); $c = 0; while ( $c < 100 ) { # expand $$ if ( $v =~ s/(\$\$\w+)/\035/ ) { $_ = $1; s/\$\$//g; if ( !defined($project{$_}) ) { $v =~ s/\035//g; } else { $v =~ s/\035/$project{$_}/g; } $c++; } else { $c = 100; } } return $v;}## project_var_condition(cond)## Internal function for Project().# Checks the condition and returns 1 if it is met, otherwise 0.# The condition can be a platform decriptor (e.g. win32,unix), a# possible CONFIG item (e.g. release) or several condition vars# ANDed (':') together.## Examples:# win32:SOURCES += win32specific.cpp# unix:debug:SOURCES += unixdebug.cppsub project_var_condition { my($c) = @_; return 1 if !defined($c) || ($c eq ""); if ( $c =~ /(^.*?):(.*$)/ ) { my($c1,$c2) = ($1,$2); return &project_var_condition($c1) && &project_var_condition($c2); } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -