From e16ea21dc8a710237ade8413207f58d403c616a3 Mon Sep 17 00:00:00 2001 From: Joe Ludwig Date: Wed, 17 Jul 2013 18:26:59 -0700 Subject: * Added support for building shaders in your mod * Added nav mesh support * fixed many warnings and misc bugs * Fixed the create*projects scripts in mp * Added a bunch of stuff to .gitignore --- sp/src/devtools/bin/buildshaderlist.pl | 22 + sp/src/devtools/bin/checkshaderchecksums.pl | 116 +++ sp/src/devtools/bin/copyshaderincfiles.pl | 75 ++ sp/src/devtools/bin/copyshaders.pl | 172 ++++ sp/src/devtools/bin/d3dx9_33.dll | Bin 0 -> 3495784 bytes sp/src/devtools/bin/fix_particle_operator_names.pl | 110 +++ sp/src/devtools/bin/linux/ccache | Bin 308586 -> 197505 bytes sp/src/devtools/bin/osx32/ccache | Bin 89116 -> 132512 bytes sp/src/devtools/bin/shaderinfo.pl | 36 + sp/src/devtools/bin/splitdiff3.pl | 54 ++ sp/src/devtools/bin/uniqifylist.pl | 6 + sp/src/devtools/bin/valve_perl_helpers.pl | 558 +++++++++++ sp/src/devtools/bin/vpc.exe | Bin 1129472 -> 1129472 bytes sp/src/devtools/bin/vpc_linux | Bin 1184893 -> 1184893 bytes sp/src/devtools/bin/vpc_osx | Bin 1102944 -> 1102944 bytes sp/src/devtools/makefile_base_posix.mak | 1012 ++++++++++---------- 16 files changed, 1658 insertions(+), 503 deletions(-) create mode 100644 sp/src/devtools/bin/buildshaderlist.pl create mode 100644 sp/src/devtools/bin/checkshaderchecksums.pl create mode 100644 sp/src/devtools/bin/copyshaderincfiles.pl create mode 100644 sp/src/devtools/bin/copyshaders.pl create mode 100644 sp/src/devtools/bin/d3dx9_33.dll create mode 100644 sp/src/devtools/bin/fix_particle_operator_names.pl create mode 100644 sp/src/devtools/bin/shaderinfo.pl create mode 100644 sp/src/devtools/bin/splitdiff3.pl create mode 100644 sp/src/devtools/bin/uniqifylist.pl create mode 100644 sp/src/devtools/bin/valve_perl_helpers.pl (limited to 'sp/src/devtools') diff --git a/sp/src/devtools/bin/buildshaderlist.pl b/sp/src/devtools/bin/buildshaderlist.pl new file mode 100644 index 00000000..57790ace --- /dev/null +++ b/sp/src/devtools/bin/buildshaderlist.pl @@ -0,0 +1,22 @@ +use File::DosGlob; +@ARGV = map { + my @g = File::DosGlob::glob($_) if /[*?]/; + @g ? @g : $_; + } @ARGV; + +open FILE, ">__tmpshaderlist.txt"; + +foreach $arg (@ARGV) +{ + if( $arg =~ m/\.fxc$/i || $arg =~ m/\.vsh$/i || $arg =~ m/\.psh$/i ) + { + print $arg . "\n"; + print FILE $arg . "\n"; + } +} + +close FILE; + +system "buildshaders.bat __tmpshaderlist"; + +unlink "__tmpshaderlist.txt"; \ No newline at end of file diff --git a/sp/src/devtools/bin/checkshaderchecksums.pl b/sp/src/devtools/bin/checkshaderchecksums.pl new file mode 100644 index 00000000..e41509f2 --- /dev/null +++ b/sp/src/devtools/bin/checkshaderchecksums.pl @@ -0,0 +1,116 @@ +use String::CRC32; +BEGIN {use File::Basename; push @INC, dirname($0); } +require "valve_perl_helpers.pl"; + +sub GetShaderType +{ + my $shadername = shift; + my $shadertype; + if( $shadername =~ m/\.vsh/i ) + { + $shadertype = "vsh"; + } + elsif( $shadername =~ m/\.psh/i ) + { + $shadertype = "psh"; + } + elsif( $shadername =~ m/\.fxc/i ) + { + $shadertype = "fxc"; + } + else + { + die; + } + return $shadertype; +} + +sub GetShaderSrc +{ + my $shadername = shift; + if ( $shadername =~ m/^(.*)-----/i ) + { + return $1; + } + else + { + return $shadername; + } +} + +sub GetShaderType +{ + my $shadername = shift; + my $shadertype; + if( $shadername =~ m/\.vsh/i ) + { + $shadertype = "vsh"; + } + elsif( $shadername =~ m/\.psh/i ) + { + $shadertype = "psh"; + } + elsif( $shadername =~ m/\.fxc/i ) + { + $shadertype = "fxc"; + } + else + { + die; + } + return $shadertype; +} + +sub GetShaderBase +{ + my $shadername = shift; + if ( $shadername =~ m/-----(.*)$/i ) + { + return $1; + } + else + { + my $shadertype = &GetShaderType( $shadername ); + $shadername =~ s/\.$shadertype//i; + return $shadername; + } +} + +$g_x360 = 0; +$g_vcsext = ".vcs"; + +while( 1 ) +{ + $inputbase = shift; + + if( $inputbase =~ m/-x360/ ) + { + $g_x360 = 1; + $g_vcsext = ".360.vcs"; + } + else + { + last; + } +} + +# rip the txt off the end if it's there. +$inputbase =~ s/\.txt//i; + +my @srcfiles = &LoadShaderListFile( $inputbase ); + +foreach $srcfile ( @srcfiles ) +{ + my $shadertype = &GetShaderType( $srcfile ); + my $shaderbase = &GetShaderBase( $srcfile ); + my $shadersrc = &GetShaderSrc( $srcfile ); + my $vcsFileName = "..\\..\\..\\game\\hl2\\shaders\\$shadertype\\$shaderbase" . $g_vcsext; +# print "shadersrc: $shadersrc vcsFileName: $vcsFileName\n"; + + if( $g_x360 && ( $shaderbase =~ m/_ps20$/i ) ) + { + next; # skip _ps20 files for 360 + } + + &CheckCRCAgainstTarget( $shadersrc, $vcsFileName, 1 ); +} diff --git a/sp/src/devtools/bin/copyshaderincfiles.pl b/sp/src/devtools/bin/copyshaderincfiles.pl new file mode 100644 index 00000000..21702d8f --- /dev/null +++ b/sp/src/devtools/bin/copyshaderincfiles.pl @@ -0,0 +1,75 @@ +BEGIN {use File::Basename; push @INC, dirname($0); } +require "valve_perl_helpers.pl"; +use Cwd; +use String::CRC32; + +my $txtfilename = shift; +my $arg = shift; + +my $is360 = 0; +my $platformextension = ""; +if( $arg =~ m/-x360/i ) +{ + $is360 = 1; + $platformextension = ".360"; +} + +open TXTFILE, "<$txtfilename"; + +my $src; +my $dst; +while( $src = ) +{ + # get rid of comments + $src =~ s,//.*,,g; + + # skip blank lines + if( $src =~ m/^\s*$/ ) + { + next; + } + + # Get rid of newlines. + $src =~ s/\n//g; + + # Save off the shader source filename. + my $dst = $src; + + $dst =~ s/_tmp//gi; + + # Does the dst exist? + my $dstexists = -e $dst; + my $srcexists = -e $src; + # What are the time stamps for the src and dst? + my $srcmodtime = ( stat $src )[9]; + my $dstmodtime = ( stat $dst )[9]; + + # Open for edit or add if different than what is in perforce already. + if( !$dstexists || ( $srcmodtime != $dstmodtime ) ) + { + # Make the target writable if it exists + if( $dstexists ) + { + MakeFileWritable( $dst ); + } + + my $dir = $dst; + $dir =~ s,([^/\\]*$),,; # rip the filename off the end + my $filename = $1; + + # create the target directory if it doesn't exist + if( !$dstexists ) + { + &MakeDirHier( $dir, 0777 ); + } + + # copy the file to its targets. . . we want to see STDERR here if there is an error. + my $cmd = "copy $src $dst > nul"; +# print STDERR "$cmd\n"; + system $cmd; + + MakeFileReadOnly( $dst ); + } +} + +close TXTFILE; diff --git a/sp/src/devtools/bin/copyshaders.pl b/sp/src/devtools/bin/copyshaders.pl new file mode 100644 index 00000000..53839298 --- /dev/null +++ b/sp/src/devtools/bin/copyshaders.pl @@ -0,0 +1,172 @@ +BEGIN {use File::Basename; push @INC, dirname($0); } +require "valve_perl_helpers.pl"; +use Cwd; +use String::CRC32; + +sub ReadInputFileWithIncludes +{ + local( $filename ) = shift; + + local( *INPUT ); + local( $output ); + + open INPUT, "<$filename" || die; + + local( $line ); + local( $linenum ) = 1; + while( $line = ) + { + if( $line =~ m/\#include\s+\"(.*)\"/i ) + { + $output.= ReadInputFileWithIncludes( $1 ); + } + else + { + $output .= $line; + } + } + + close INPUT; + return $output; +} + +sub PatchCRC +{ + my $filename = shift; + my $crc = shift; +# print STDERR "PatchCRC( $filename, $crc )\n"; + local( *FP ); + open FP, "+<$filename" || die; + binmode( FP ); + seek FP, 6 * 4, 0; + my $uInt = "I"; + if( $filename =~ m/360/ ) + { + $uInt = "N"; + } + print FP pack $uInt, $crc; + close FP; +} + +my $txtfilename = shift; +my $arg = shift; + +my $is360 = 0; +my $platformextension = ""; +if( $arg =~ m/-x360/i ) +{ + $is360 = 1; + $platformextension = ".360"; +} + +# Get the changelist number for the Shader Auto Checkout changelist. Will create the changelist if it doesn't exist. +my $changelistnumber = `valve_p4_create_changelist.cmd ..\\..\\..\\game\\hl2\\shaders \"Shader Auto Checkout VCS\"`; +# Get rid of the newline +$changelistnumber =~ s/\n//g; + +my $changelistarg = ""; +if( $changelistnumber != 0 ) +{ + $changelistarg = "-c $changelistnumber" +} + +open TXTFILE, "<$txtfilename"; + +my $src; +my $dst; +while( $src = ) +{ + # get rid of comments + $src =~ s,//.*,,g; + + # skip blank lines + if( $src =~ m/^\s*$/ ) + { + next; + } + + # Get rid of newlines. + $src =~ s/\n//g; + + # Save off the shader source filename. + my $shadersrcfilename = $src; + $shadersrcfilename =~ s/-----.*$//; + # use only target basename. + $src =~ s/^.*-----//; + + # where the binary vcs file is + my $spath = ""; + + if ( $shadersrcfilename =~ m@\.fxc@i ) + { + $spath = "shaders\\fxc\\"; + } + if ( $shadersrcfilename =~ m@\.vsh@i ) + { + $spath = "shaders\\vsh\\"; + } + if ( $shadersrcfilename =~ m@\.psh@i ) + { + $spath = "shaders\\psh\\"; + } + + # make the source have path and extension + $src = $spath . $src . $platformextension . ".vcs"; + + # build the dest filename. + $dst = $src; + + $dst =~ s/shaders\\/..\\..\\..\\game\\hl2\\shaders\\/i; + + # Does the dst exist? + my $dstexists = -e $dst; + my $srcexists = -e $src; + # What are the time stamps for the src and dst? + my $srcmodtime = ( stat $src )[9]; + my $dstmodtime = ( stat $dst )[9]; + + # Write $dst to a file so that we can do perforce stuff to it later. + local( *VCSLIST ); + open VCSLIST, ">>vcslist.txt" || die; + print VCSLIST $dst . "\n"; + close VCSLIST; + + # Open for edit or add if different than what is in perforce already. + if( !$dstexists || ( $srcmodtime != $dstmodtime ) ) + { + if ( $srcexists && $shadersrcfilename =~ m@\.fxc@i ) + { + # Get the CRC for the source file. + my $srccode = ReadInputFileWithIncludes( $shadersrcfilename ); + my $crc = crc32( $srccode ); + + # Patch the source VCS file with the CRC32 of the source code used to build that file. + PatchCRC( $src, $crc ); + } + + # Make the target vcs writable if it exists + if( $dstexists ) + { + MakeFileWritable( $dst ); + } + + my $dir = $dst; + $dir =~ s,([^/\\]*$),,; # rip the filename off the end + my $filename = $1; + + # create the target directory if it doesn't exist + if( !$dstexists ) + { + &MakeDirHier( $dir, 0777 ); + } + + # copy the file to its targets. . . we want to see STDERR here if there is an error. + my $cmd = "copy $src $dst > nul"; +# print STDERR "$cmd\n"; + system $cmd; + + MakeFileReadOnly( $dst ); + } +} + +close TXTFILE; diff --git a/sp/src/devtools/bin/d3dx9_33.dll b/sp/src/devtools/bin/d3dx9_33.dll new file mode 100644 index 00000000..a005f8fa Binary files /dev/null and b/sp/src/devtools/bin/d3dx9_33.dll differ diff --git a/sp/src/devtools/bin/fix_particle_operator_names.pl b/sp/src/devtools/bin/fix_particle_operator_names.pl new file mode 100644 index 00000000..86fd0f0f --- /dev/null +++ b/sp/src/devtools/bin/fix_particle_operator_names.pl @@ -0,0 +1,110 @@ +#!perl +use File::Find; + +&BuildRemapTable; + +find(\&convert, "." ); + + +sub convert + { + return unless (/\.pcf$/i); + return if (/^tmp\.pcf$/i); + return if (/^tmp2\.pcf$/i); + return if (/360\.pcf$/i); + print STDERR "process ", $File::Find::name," ($_) dir=",`cd`," \n"; + my $fname=$_; + print `p4 edit $fname`; + print `dmxconvert -i $_ -o tmp.pcf -oe keyvalues2`; + open(TMP, "tmp.pcf" ) || return; + open(OUT, ">tmp2.pcf" ) || die; + while() + { + s/[\n\r]//g; + if ( (/^(\s*\"functionName\"\s*\"string\"\s*\")(.*)\"(.*)$/) && + length($map{$2}) ) + { + $_=$1.$map{$2}.'"'.$3; + } + if ( (/^(\s*\"name\"\s*\"string\"\s*\")(.*)\"(.*)$/) && + length($map{$2}) ) + { + $_=$1.$map{$2}.'"'.$3; + } + print OUT "$_\n"; + } + close OUT; + close TMP; + print `dmxconvert -i tmp2.pcf -o $fname -ie keyvalues2 -oe binary`; + unlink "tmp.pcf"; + unlink "tmp2.pcf"; +} + + + + + + + + + + + + +sub BuildRemapTable +{ + $map{"alpha_fade"}= "Alpha Fade and Decay"; + $map{"alpha_fade_in_random"}= "Alpha Fade In Random"; + $map{"alpha_fade_out_random"}= "Alpha Fade Out Random"; + $map{"basic_movement"}= "Movement Basic"; + $map{"color_fade"}= "Color Fade"; + $map{"controlpoint_light"}= "Color Light From Control Point"; + $map{"Dampen Movement Relative to Control Point"}= "Movement Dampen Relative to Control Point"; + $map{"Distance Between Control Points Scale"}= "Remap Distance Between Two Control Points to Scalar"; + $map{"Distance to Control Points Scale"}= "Remap Distance to Control Point to Scalar"; + $map{"lifespan_decay"}= "Lifespan Decay"; + $map{"lock to bone"}= "Movement Lock to Bone"; + $map{"postion_lock_to_controlpoint"}= "Movement Lock to Control Point"; + $map{"maintain position along path"}= "Movement Maintain Position Along Path"; + $map{"Match Particle Velocities"}= "Movement Match Particle Velocities"; + $map{"Max Velocity"}= "Movement Max Velocity"; + $map{"noise"}= "Noise Scalar"; + $map{"vector noise"}= "Noise Vector"; + $map{"oscillate_scalar"}= "Oscillate Scalar"; + $map{"oscillate_vector"}= "Oscillate Vector"; + $map{"Orient Rotation to 2D Direction"}= "Rotation Orient to 2D Direction"; + $map{"radius_scale"}= "Radius Scale"; + $map{"Random Cull"}= "Cull Random"; + $map{"remap_scalar"}= "Remap Scalar"; + $map{"rotation_movement"}= "Rotation Basic"; + $map{"rotation_spin"}= "Rotation Spin Roll"; + $map{"rotation_spin yaw"}= "Rotation Spin Yaw"; + $map{"alpha_random"}= "Alpha Random"; + $map{"color_random"}= "Color Random"; + $map{"create from parent particles"}= "Position From Parent Particles"; + $map{"Create In Hierarchy"}= "Position In CP Hierarchy"; + $map{"random position along path"}= "Position Along Path Random"; + $map{"random position on model"}= "Position on Model Random"; + $map{"sequential position along path"}= "Position Along Path Sequential"; + $map{"position_offset_random"}= "Position Modify Offset Random"; + $map{"position_warp_random"}= "Position Modify Warp Random"; + $map{"position_within_box"}= "Position Within Box Random"; + $map{"position_within_sphere"}= "Position Within Sphere Random"; + $map{"Inherit Velocity"}= "Velocity Inherit from Control Point"; + $map{"Initial Repulsion Velocity"}= "Velocity Repulse from World"; + $map{"Initial Velocity Noise"}= "Velocity Noise"; + $map{"Initial Scalar Noise"}= "Remap Noise to Scalar"; + $map{"Lifespan from distance to world"}= "Lifetime from Time to Impact"; + $map{"Pre-Age Noise"}= "Lifetime Pre-Age Noise"; + $map{"lifetime_random"}= "Lifetime Random"; + $map{"radius_random"}= "Radius Random"; + $map{"random yaw"}= "Rotation Yaw Random"; + $map{"Randomly Flip Yaw"}= "Rotation Yaw Flip Random"; + $map{"rotation_random"}= "Rotation Random"; + $map{"rotation_speed_random"}= "Rotation Speed Random"; + $map{"sequence_random"}= "Sequence Random"; + $map{"second_sequence_random"}= "Sequence Two Random"; + $map{"trail_length_random"}= "Trail Length Random"; + $map{"velocity_random"}= "Velocity Random"; +} + diff --git a/sp/src/devtools/bin/linux/ccache b/sp/src/devtools/bin/linux/ccache index 9846e22d..3ef6b8e9 100755 Binary files a/sp/src/devtools/bin/linux/ccache and b/sp/src/devtools/bin/linux/ccache differ diff --git a/sp/src/devtools/bin/osx32/ccache b/sp/src/devtools/bin/osx32/ccache index 36a7081d..86afc048 100755 Binary files a/sp/src/devtools/bin/osx32/ccache and b/sp/src/devtools/bin/osx32/ccache differ diff --git a/sp/src/devtools/bin/shaderinfo.pl b/sp/src/devtools/bin/shaderinfo.pl new file mode 100644 index 00000000..ae0b96c8 --- /dev/null +++ b/sp/src/devtools/bin/shaderinfo.pl @@ -0,0 +1,36 @@ +#! perl + +my $fname=shift || die "format is shaderinfo blah.vcs"; + +open(SHADER, $fname) || die "can't open $fname"; +binmode SHADER; + +read(SHADER,$header,20); +($ver,$ntotal,$ndynamic,$flags,$centroidmask)=unpack("LLLLL",$header); + +#print "Version $ver total combos=$ntotal, num dynamic combos=$ndynamic,\n flags=$flags, centroid mask=$centroidmask\n"; + +read(SHADER,$refsize,4); +$refsize=unpack("L",$refsize); +#print "Size of reference shader for diffing=$refsize\n"; + +seek(SHADER,$refsize,1); + +$nskipped_combos=0; +for(1..$ntotal) + { + read(SHADER,$combodata,8); + ($ofs,$combosize)=unpack("LL",$combodata); + if ( $ofs == 0xffffffff) + { + $nskipped_combos++; + } + else + { + } + } +#print "$nskipped_combos skipped, for an actual total of ",$ntotal-$nskipped_combos,"\n"; +#print "Real to skipped ratio = ",($ntotal-$nskipped_combos)/$ntotal,"\n"; +# csv output - name, real combos, virtual combos, dynamic combos +my $real_combos=$ntotal-$nskipped_combos; +print "$fname,$real_combos,$ntotal,$ndynamic\n"; diff --git a/sp/src/devtools/bin/splitdiff3.pl b/sp/src/devtools/bin/splitdiff3.pl new file mode 100644 index 00000000..e38b493a --- /dev/null +++ b/sp/src/devtools/bin/splitdiff3.pl @@ -0,0 +1,54 @@ +$infilename = shift; +$outfilename1 = shift; +$outfilename2 = shift; +open INPUT, $infilename || die; +@input = ; +close INPUT; + +open MERGEDMINE, ">$outfilename1" || die; +open MERGEDTHEIRS, ">$outfilename2" || die; + +for( $i = 0; $i < scalar( @input ); $i++ ) +{ + $line = $input[$i]; + + if( $line =~ m/^(.*)<<<<<<>>>>>>/ ) + { + $first = $second = 0; + print MERGEDTHEIRS $1; + next; + } + + if( $first ) + { + print MERGEDMINE $line; + } + elsif( $second ) + { + print MERGEDTHEIRS $line; + } + else + { + print MERGEDMINE $line; + print MERGEDTHEIRS $line; + } +} + +close MERGEDMINE; +close MERGEDTHEIRS; diff --git a/sp/src/devtools/bin/uniqifylist.pl b/sp/src/devtools/bin/uniqifylist.pl new file mode 100644 index 00000000..d8d40afd --- /dev/null +++ b/sp/src/devtools/bin/uniqifylist.pl @@ -0,0 +1,6 @@ +foreach $_ (sort <> ) +{ + next if( defined( $prevline ) && $_ eq $prevline ); + $prevline = $_; + print; +} diff --git a/sp/src/devtools/bin/valve_perl_helpers.pl b/sp/src/devtools/bin/valve_perl_helpers.pl new file mode 100644 index 00000000..5cd2aa04 --- /dev/null +++ b/sp/src/devtools/bin/valve_perl_helpers.pl @@ -0,0 +1,558 @@ +sub BackToForwardSlash +{ + my( $path ) = shift; + $path =~ s,\\,/,g; + return $path; +} + +sub RemoveFileName +{ + my( $in ) = shift; + $in = &BackToForwardSlash( $in ); + $in =~ s,/[^/]*$,,; + return $in; +} + +sub RemovePath +{ + my( $in ) = shift; + $in = &BackToForwardSlash( $in ); + $in =~ s,^(.*)/([^/]*)$,$2,; + return $in; +} + +sub MakeDirHier +{ + my( $in ) = shift; +# print "MakeDirHier( $in )\n"; + $in = &BackToForwardSlash( $in ); + my( @path ); + while( $in =~ m,/, ) # while $in still has a slash + { + my( $end ) = &RemovePath( $in ); + push @path, $end; +# print $in . "\n"; + $in = &RemoveFileName( $in ); + } + my( $i ); + my( $numelems ) = scalar( @path ); + my( $curpath ); + for( $i = $numelems - 1; $i >= 0; $i-- ) + { + $curpath .= "/" . $path[$i]; + my( $dir ) = $in . $curpath; + if( !stat $dir ) + { +# print "mkdir $dir\n"; + mkdir $dir, 0777; + } + } +} + +sub FileExists +{ + my $filename = shift; + my @statresult = stat $filename; + my $iswritable = @statresult != 0; + return $iswritable; +} + +sub MakeFileWritable +{ + my $filename = shift; + if ( &FileExists( $filename ) ) + { + chmod 0666, $filename || die; + } +} + +sub MakeFileReadOnly +{ + my $filename = shift; + chmod 0444, $filename || die; +} + +# Run a command and get stdout and stderr to an array +sub RunCommand +{ + my $cmd = shift; +# print STDERR "command: $cmd\n"; + system "$cmd > cmdout.txt 2>&1" || die; + local( *FILE ); + open FILE, "; +# print STDERR "command output: @output\n"; + close FILE; + unlink "cmdout.txt" || die; + return @output; +} + +sub PerforceEditOrAdd +{ + return; + my $filename = shift; + my $changelistarg = shift; + + # Is the file on the client? + my $cmd = "p4 fstat \"$filename\""; + my @p4output = &RunCommand( $cmd ); + my $p4output = join "", @p4output; + if( $p4output =~ m/no such file/ ) + { + # not on client. . add + my $cmd = "p4 add $changelistarg $filename"; + my @p4output = &RunCommand( $cmd ); + my $p4output = join "", @p4output; + if( $p4output =~ m/opened for add/ ) + { + print $p4output; + return; + } + print "ERROR: $p4output"; + return; + } + + # The file is known to be on the client at this point. + + # Is it open for edit? + if( $p4output =~ m/action edit/ ) + { + # Is is open for edit, let's see if it's still different. + # check for opened files that are not different from the revision in the depot. + my $cmd = "p4 diff -sr \"$filename\""; + my @p4output = &RunCommand( $cmd ); + my $outputstring = join "", @p4output; + # check for empty string + if( !( $outputstring =~ m/^\s*$/ ) ) + { + my $cmd = "p4 revert \"$filename\""; + my @p4output = &RunCommand( $cmd ); + my $outputstring = join "", @p4output; + print $outputstring; + return; + } + } + + # check for unopened files that are different from the revision in the depot. + my $cmd = "p4 diff -se \"$filename\""; + my @p4output = &RunCommand( $cmd ); + my $outputstring = join "", @p4output; + # check for empty string + if( $outputstring =~ m/^\s*$/ ) + { + &MakeFileReadOnly( $filename ); + return; + } + + # We need to edit the file since it is known to be different here. + my $cmd = "p4 edit $changelistarg \"$filename\""; + my @p4output = &RunCommand( $cmd ); + + my $line; + foreach $line ( @p4output ) + { + if( $line =~ m/not on client/ ) + { + #print "notonclient..."; + print "ERROR: @p4output\n"; + return; + } + if( $line =~ m/currently opened for edit/ ) + { + return; + } + if( $line =~ m/opened for edit/ ) + { + print $line; + } + } +} + +sub FileIsWritable +{ + local( $filename ) = shift; + local( @statresult ) = stat $filename; + local( $mode, $iswritable ); + $mode = oct( $statresult[2] ); + $iswritable = ( $mode & 2 ) != 0; + return $iswritable; +} + +sub TouchFile +{ + my $filename = shift; + if( !&FileExists( $filename ) ) + { + if( !open FILE, ">$filename" ) + { + die; + } + close FILE; + } + my $now = time; + local( *FILE ); + utime $now, $now, $filename; +} + +sub FileExistsInPerforce +{ + my $filename = shift; + my @output = &RunCommand( "p4 fstat $filename" ); + my $line; + foreach $line (@output) + { + if( $line =~ m/no such file/ ) + { + return 0; + } + } + return 1; +} + +sub PerforceWriteFile +{ + my $filename = shift; + my $filecontents = shift; +# my $changelistname = shift; + + # Get the changelist number for the Shader Auto Checkout changelist. Will create the changelist if it doesn't exist. +# my $changelistnumber = `valve_p4_create_changelist.cmd . \"$changelistname\"`; + # Get rid of the newline +# $changelistnumber =~ s/\n//g; + +# my $changelistarg = ""; +# if( $changelistnumber != 0 ) +# { +# $changelistarg = "-c $changelistnumber" +# } + + # Make the target vcs writable if it exists + MakeFileWritable( $filename ); + + # Write the file. + local( *FP ); + open FP, ">$filename"; + print FP $filecontents; + close FP; + + # Do whatever needs to happen with perforce for this file. +# &PerforceEditOrAdd( $filename, $changelistarg ); +} + +sub WriteFile +{ + my $filename = shift; + my $filecontents = shift; + + # Make the target vcs writable if it exists + MakeFileWritable( $filename ); + + # Write the file. + local( *FP ); + open FP, ">$filename"; + print FP $filecontents; + close FP; +} + +sub PrintCleanPerforceOutput +{ + my $line; + while( $line = shift ) + { + if( $line =~ m/currently opened/i ) + { + next; + } + if( $line =~ m/already opened for edit/i ) + { + next; + } + if( $line =~ m/also opened/i ) + { + next; + } + if( $line =~ m/add of existing file/i ) + { + next; + } + print $line; + } +} + +# HACK!!!! Need to pass something in to do this rather than hard coding. +sub NormalizePerforceFilename +{ + my $line = shift; + + # remove newlines. + $line =~ s/\n//; + # downcase. + $line =~ tr/[A-Z]/[a-z]/; + # backslash to forwardslash + $line =~ s,\\,/,g; + + # for inc files HACK! + $line =~ s/^.*(fxctmp9.*)/$1/i; + $line =~ s/^.*(vshtmp9.*)/$1/i; + + # for vcs files. HACK! + $line =~ s,^.*game/hl2/shaders/,,i; + + return $line; +} + +sub MakeSureFileExists +{ + local( $filename ) = shift; + local( $testexists ) = shift; + local( $testwrite ) = shift; + + local( @statresult ) = stat $filename; + if( !@statresult && $testexists ) + { + die "$filename doesn't exist!\n"; + } + local( $mode, $iswritable ); + $mode = oct( $statresult[2] ); + $iswritable = ( $mode & 2 ) != 0; + if( !$iswritable && $testwrite ) + { + die "$filename isn't writable!\n"; + } +} + +sub LoadShaderListFile_GetShaderType +{ + my $shadername = shift; + my $shadertype; + if( $shadername =~ m/\.vsh/i ) + { + $shadertype = "vsh"; + } + elsif( $shadername =~ m/\.psh/i ) + { + $shadertype = "psh"; + } + elsif( $shadername =~ m/\.fxc/i ) + { + $shadertype = "fxc"; + } + else + { + die; + } + return $shadertype; +} + +sub LoadShaderListFile_GetShaderSrc +{ + my $shadername = shift; + if ( $shadername =~ m/^(.*)-----/i ) + { + return $1; + } + else + { + return $shadername; + } +} + +sub LoadShaderListFile_GetShaderBase +{ + my $shadername = shift; + if ( $shadername =~ m/-----(.*)$/i ) + { + return $1; + } + else + { + my $shadertype = &LoadShaderListFile_GetShaderType( $shadername ); + $shadername =~ s/\.$shadertype//i; + return $shadername; + } +} + +sub LoadShaderListFile +{ + my $inputbase = shift; + + my @srcfiles; + &MakeSureFileExists( "$inputbase.txt", 1, 0 ); + + open SHADERLISTFILE, "<$inputbase.txt" || die; + my $line; + while( $line = ) + { + $line =~ s/\/\/.*$//; # remove comments "//..." + $line =~ s/^\s*//; # trim leading whitespace + $line =~ s/\s*$//; # trim trailing whitespace + next if( $line =~ m/^\s*$/ ); + if( $line =~ m/\.fxc/ || $line =~ m/\.vsh/ || $line =~ m/\.psh/ ) + { + my $shaderbase = &LoadShaderListFile_GetShaderBase( $line ); + + if( $ENV{"DIRECTX_FORCE_MODEL"} =~ m/^30$/i ) # forcing all shaders to be ver. 30 + { + my $targetbase = $shaderbase; + $targetbase =~ s/_ps2x/_ps30/i; + $targetbase =~ s/_ps20b/_ps30/i; + $targetbase =~ s/_ps20/_ps30/i; + $targetbase =~ s/_vs20/_vs30/i; + $targetbase =~ s/_vsxx/_vs30/i; + push @srcfiles, ( $line . "-----" . $targetbase ); + } + else + { + if( $shaderbase =~ m/_ps2x/i ) + { + my $targetbase = $shaderbase; + $targetbase =~ s/_ps2x/_ps20/i; + push @srcfiles, ( $line . "-----" . $targetbase ); + + $targetbase = $shaderbase; + $targetbase =~ s/_ps2x/_ps20b/i; + push @srcfiles, ( $line . "-----" . $targetbase ); + } + elsif( $shaderbase =~ m/_vsxx/i ) + { + my $targetbase = $shaderbase; + $targetbase =~ s/_vsxx/_vs11/i; + push @srcfiles, ( $line . "-----" . $targetbase ); + + $targetbase = $shaderbase; + $targetbase =~ s/_vsxx/_vs20/i; + push @srcfiles, ( $line . "-----" . $targetbase ); + } + else + { + push @srcfiles, ( $line . "-----" . $shaderbase ); + } + } + } + } + close SHADERLISTFILE; + return @srcfiles; +} + +sub ReadInputFileWithIncludes +{ + local( $filename ) = shift; +# print STDERR "ReadInputFileWithIncludes: $filename\n"; + + local( *INPUT ); + local( $output ); + +# print STDERR "before open\n"; + open INPUT, "<$filename" || die; +# print STDERR "after open\n"; + + local( $line ); + while( $line = ) + { +# print STDERR $line; + if( $line =~ m/\#include\s+\"(.*)\"/i ) + { + $output.= ReadInputFileWithIncludes( $1 ); + } + else + { + $output .= $line; + } + } + + close INPUT; + return $output; +} + +sub GetCRCFromSourceFile +{ + my $filename = shift; + my $data = &ReadInputFileWithIncludes( $filename ); +# print STDERR $data; + $crc = crc32( $data ); +# print STDERR "GetCRCFromSourceFile: $crc\n"; + return $crc; +} + +sub GetCRCFromVCSFile +{ + my $filename = shift; +# print STDERR "GetCRCFromVCSFile $filename\n"; + local( *FP ); + open FP, "<$filename" || die "GetCRCFromVCSFile: can't open file $filename\n"; + binmode( FP ); + + # unpack arguments + my $sInt = "i"; + my $uInt = "I"; + if( $filename =~ m/\.360\./ ) + { + # Change arguments to "big endian long" + $sInt = "N"; + $uInt = "N"; + } + + my $header; + read FP, $header, 7 * 4 || die "updateshaders.pl:GetCRCFromVCSFile: can't read header for $filename\n"; + my $version,$numCombos,$numDynamicCombos,$flags,$centroidMask,$refSize,$crc; + ($version,$numCombos,$numDynamicCombos,$flags,$centroidMask,$refSize,$crc) = unpack "$sInt$sInt$sInt$uInt$uInt$uInt$uInt", $header; + unless( $version == 4 || $version == 5 || $version == 6 ) + { + print STDERR "ERROR: GetCRCFromVCSFile: $filename is version $version\n"; + return 0; + } +# print STDERR "version: $version\n"; +# print STDERR "numCombos: $numCombos\n"; +# print STDERR "numDynamicCombos: $numDynamicCombos\n"; +# print STDERR "flags: $flags\n"; +# print STDERR "centroidMask: $centroidMask\n"; +# print STDERR "refSize: $refSize\n"; +# print STDERR "GetCRCFromVCSFile: $crc\n"; + close( FP ); + return $crc; +} + +sub CheckCRCAgainstTarget +{ + my $srcFileName = shift; + my $vcsFileName = shift; + my $warn = shift; + + # Make sure both files exist. +# print STDERR "$srcFileName doesn't exist\n" if( !( -e $srcFileName ) ); +# print STDERR "$vcsFileName doesn't exist\n" if( !( -e $vcsFileName ) ); + if( !( -e $srcFileName ) ) + { + if( $warn ) + { + print "$srcFileName missing\n"; + } + return 0; + } + if( !( -e $vcsFileName ) ) + { + if( $warn ) + { + print "$vcsFileName missing\n"; + } + return 0; + } +# print STDERR "CheckCRCAgainstTarget( $srcFileName, $vcsFileName );\n"; +# print STDERR "vcsFileName: $vcsFileName\n"; +# print STDERR "vcsFileName: $srcFileName\n"; + my $vcsCRC = &GetCRCFromVCSFile( $vcsFileName ); + my $srcCRC = &GetCRCFromSourceFile( $srcFileName ); + if( $warn && ( $vcsCRC != $srcCRC ) ) + { + print "$vcsFileName checksum ($vcsCRC) != $srcFileName checksum: ($srcCRC)\n"; + } + +# return 0; # use this to skip crc checking. +# if( $vcsCRC == $srcCRC ) +# { +# print STDERR "CRC passed for $srcFileName $vcsFileName $vcsCRC\n"; +# } + return $vcsCRC == $srcCRC; +} + +1; diff --git a/sp/src/devtools/bin/vpc.exe b/sp/src/devtools/bin/vpc.exe index 0c084858..ddc1328c 100644 Binary files a/sp/src/devtools/bin/vpc.exe and b/sp/src/devtools/bin/vpc.exe differ diff --git a/sp/src/devtools/bin/vpc_linux b/sp/src/devtools/bin/vpc_linux index 31263d23..21679b4f 100755 Binary files a/sp/src/devtools/bin/vpc_linux and b/sp/src/devtools/bin/vpc_linux differ diff --git a/sp/src/devtools/bin/vpc_osx b/sp/src/devtools/bin/vpc_osx index 65058d46..0ca6b8c4 100755 Binary files a/sp/src/devtools/bin/vpc_osx and b/sp/src/devtools/bin/vpc_osx differ diff --git a/sp/src/devtools/makefile_base_posix.mak b/sp/src/devtools/makefile_base_posix.mak index f4689c4b..7ad95035 100644 --- a/sp/src/devtools/makefile_base_posix.mak +++ b/sp/src/devtools/makefile_base_posix.mak @@ -1,503 +1,509 @@ -# -# Base makefile for Linux and OSX -# -# !!!!! Note to future editors !!!!! -# -# before you make changes, make sure you grok: -# 1. the difference between =, :=, +=, and ?= -# 2. how and when this base makefile gets included in the generated makefile(s) -# ( see http://www.gnu.org/software/make/manual/make.html#Flavors ) -# -# Command line prefixes: -# - errors are ignored -# @ command is not printed to stdout before being executed -# + command is executed even if Make is invoked in "do not exec" mode - -OS := $(shell uname) -HOSTNAME := $(shell hostname) - --include $(SRCROOT)/devtools/steam_def.mak --include $(SRCROOT)/devtools/sourcesdk_def.mak - -# To build with clang, set the following in your environment: -# CC = clang -# CXX = clang++ - -ifeq ($(CFG), release) - # With gcc 4.6.3, engine.so went from 7,383,765 to 8,429,109 when building with -O3. - # There also was no speed difference running at 1280x1024. May 2012, mikesart. - # tonyp: The size increase was likely caused by -finline-functions and -fipa-cp-clone getting switched on with -O3. - # -fno-omit-frame-pointer: need this for stack traces with perf. - OptimizerLevel_CompilerSpecific = -O2 -fno-strict-aliasing -ffast-math -fno-omit-frame-pointer -ftree-vectorize -fpredictive-commoning -funswitch-loops -else - OptimizerLevel_CompilerSpecific = -O0 - #-O1 -finline-functions -endif - -# CPPFLAGS == "c/c++ *preprocessor* flags" - not "cee-plus-plus flags" -ARCH_FLAGS = -BUILDING_MULTI_ARCH = 0 -CPPFLAGS = $(DEFINES) $(addprefix -I, $(abspath $(INCLUDEDIRS) )) -CFLAGS = $(ARCH_FLAGS) $(CPPFLAGS) $(WARN_FLAGS) -fvisibility=$(SymbolVisibility) $(OptimizerLevel) -pipe $(GCC_ExtraCompilerFlags) -Usprintf -Ustrncpy -UPROTECTED_THINGS_ENABLE -CXXFLAGS = $(CFLAGS) -DEFINES += -DVPROF_LEVEL=1 -DGNUC -DNO_HOOK_MALLOC -DNO_MALLOC_OVERRIDE -LDFLAGS = $(CFLAGS) $(GCC_ExtraLinkerFlags) $(OptimizerLevel) -GENDEP_CXXFLAGS = -MD -MP -MF $(@:.o=.P) -MAP_FLAGS = -Srv_GAMEOUTPUTFILE = -COPY_DLL_TO_SRV = 0 - - -ifeq ($(STEAM_BRANCH),1) - WARN_FLAGS = -Wall -Wextra -Wshadow -Wno-invalid-offsetof -else - WARN_FLAGS = -Wno-write-strings -Wno-multichar -endif - -WARN_FLAGS += -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-value -Wno-missing-field-initializers -Wno-sign-compare -Wno-reorder -Wno-invalid-offsetof -Wno-float-equal -Werror=return-type -fdiagnostics-show-option -Wformat -Wformat-security - - -ifeq ($(OS),Linux) - # We should always specify -Wl,--build-id, as documented at: - # http://linux.die.net/man/1/ld and http://fedoraproject.org/wiki/Releases/FeatureBuildId.http://fedoraproject.org/wiki/Releases/FeatureBuildId - LDFLAGS += -Wl,--build-id - # Set USE_VALVE_BINDIR to build with /Steam/tools/linux in the /valve/bin path. - # Dedicated server uses this. - ifeq ($(USE_VALVE_BINDIR),1) - # dedicated server flags - ifeq ($(TARGET_PLATFORM),linux64) - VALVE_BINDIR = /valve/bin64/ - MARCH_TARGET = nocona - else - VALVE_BINDIR = /valve/bin/ - MARCH_TARGET = pentium4 - endif - STRIP_FLAGS = - else - # linux desktop client flags - VALVE_BINDIR = - # If the steam-runtime is available, use it. We should just default to using it when - # buildbot and everyone has a bit of time to get it installed. - ifneq "$(wildcard /valve/steam-runtime/bin/)" "" - # The steam-runtime is incompatible with clang at this point, so disable it - # if clang is enabled. - ifneq ($(CXX),clang++) - VALVE_BINDIR = /valve/steam-runtime/bin/ - endif - endif - GCC_VER = - MARCH_TARGET = pentium4 - # On dedicated servers, some plugins depend on global variable symbols in addition to functions. - # So symbols like _Z16ClearMultiDamagev should show up when you do "nm server_srv.so" in TF2. - STRIP_FLAGS = -x - endif - - ifeq ($(CXX),clang++) - # Clang does not support -mfpmath=sse because it uses whatever - # instruction set extensions are available by default. - SSE_GEN_FLAGS = -msse2 - else - SSE_GEN_FLAGS = -msse2 -mfpmath=sse - endif - - CCACHE := $(SRCROOT)/devtools/bin/linux/ccache - - ifeq ($(origin GCC_VER), undefined) - GCC_VER=-4.6 - endif - ifeq ($(origin AR), default) - AR = $(VALVE_BINDIR)ar crs - endif - ifeq ($(origin CC),default) - CC = $(CCACHE) $(VALVE_BINDIR)gcc$(GCC_VER) - endif - ifeq ($(origin CXX), default) - CXX = $(CCACHE) $(VALVE_BINDIR)g++$(GCC_VER) - endif - # Support ccache with clang. Add -Qunused-arguments to avoid excessive warnings due to - # a ccache quirk. Could also upgrade ccache. - # http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html - ifeq ($(CC),clang) - CC = $(CCACHE) $(VALVE_BINDIR)clang -Qunused-arguments - endif - ifeq ($(CXX),clang++) - CXX = $(CCACHE) $(VALVE_BINDIR)clang++ -Qunused-arguments - endif - LINK ?= $(CC) - - ifeq ($(TARGET_PLATFORM),linux64) - # nocona = pentium4 + 64bit + MMX, SSE, SSE2, SSE3 - no SSSE3 (that's three s's - added in core2) - ARCH_FLAGS += -march=$(MARCH_TARGET) -mtune=core2 - LD_SO = ld-linux-x86_64.so.2 - LIBSTDCXX := $(shell $(CXX) -print-file-name=libstdc++.a) - LIBSTDCXXPIC := $(shell $(CXX) -print-file-name=libstdc++-pic.a) - else - # pentium4 = MMX, SSE, SSE2 - no SSE3 (added in prescott) # -msse3 -mfpmath=sse - ARCH_FLAGS += -m32 -march=$(MARCH_TARGET) -mtune=core2 $(SSE_GEN_FLAGS) - LD_SO = ld-linux.so.2 - LIBSTDCXX := $(shell $(CXX) $(ARCH_FLAGS) -print-file-name=libstdc++.so) - LIBSTDCXXPIC := $(shell $(CXX) $(ARCH_FLAGS) -print-file-name=libstdc++.so) - LDFLAGS += -m32 - endif - - GEN_SYM ?= $(SRCROOT)/devtools/gendbg.sh - ifeq ($(CFG),release) - STRIP ?= strip $(STRIP_FLAGS) -S - # CFLAGS += -ffunction-sections -fdata-sections - # LDFLAGS += -Wl,--gc-sections -Wl,--print-gc-sections - else - STRIP ?= true - endif - VSIGN ?= true - - ifeq ($(SOURCE_SDK), 1) - Srv_GAMEOUTPUTFILE := $(GAMEOUTPUTFILE:.so=_srv.so) - COPY_DLL_TO_SRC := 1 - endif - - LINK_MAP_FLAGS = -Wl,-Map,$(@:.so=).map - - SHLIBLDFLAGS = -shared $(LDFLAGS) -Wl,--no-undefined - - _WRAP := -Xlinker --wrap= - PATHWRAP = $(_WRAP)fopen $(_WRAP)freopen $(_WRAP)open $(_WRAP)creat $(_WRAP)access $(_WRAP)__xstat \ - $(_WRAP)stat $(_WRAP)lstat $(_WRAP)fopen64 $(_WRAP)open64 $(_WRAP)opendir $(_WRAP)__lxstat \ - $(_WRAP)chmod $(_WRAP)chown $(_WRAP)lchown $(_WRAP)symlink $(_WRAP)link $(_WRAP)__lxstat64 \ - $(_WRAP)mknod $(_WRAP)utimes $(_WRAP)unlink $(_WRAP)rename $(_WRAP)utime $(_WRAP)__xstat64 \ - $(_WRAP)mount $(_WRAP)mkfifo $(_WRAP)mkdir $(_WRAP)rmdir $(_WRAP)scandir $(_WRAP)realpath - - LIB_START_EXE = $(PATHWRAP) -static-libgcc -Wl,--start-group - LIB_END_EXE = -Wl,--end-group -lm -ldl $(LIBSTDCXX) -lpthread - - LIB_START_SHLIB = $(PATHWRAP) -static-libgcc -Wl,--start-group - LIB_END_SHLIB = -Wl,--end-group -lm -ldl $(LIBSTDCXXPIC) -lpthread -l:$(LD_SO) -Wl,--version-script=$(SRCROOT)/devtools/version_script.linux.txt - -endif - -ifeq ($(OS),Darwin) - CCACHE := $(SRCROOT)/devtools/bin/osx32/ccache - MAC_SDK_VER ?= 10.6 - MAC_SDK := macosx$(MAC_SDK_VER) - SYSROOT := $(shell xcodebuild -sdk $(MAC_SDK) -version Path) - - ifneq ($(origin MAC_SDK_VER), file) - $(warning Attempting build with SDK version $(MAC_SDK_VER), only 10.6 is supported and recommended!) - endif - - ifeq ($(SYSROOT),) - FIRSTSDK := $(firstword $(sort $(shell xcodebuild -showsdks | grep macosx | sed 's/.*macosx//'))) - $(error Could not find SDK version $(MAC_SDK_VER). Install and configure Xcode 4.3, or build with: make MAC_SDK_VER=$(FIRSTSDK)) - endif - - ifeq ($(origin CC), default) - # Test to see if you have a compiler in the right place, if you - # don't abort with an error - CLANG := $(shell xcrun -sdk $(MAC_SDK) -find clang) - ifeq ($(wildcard $(CLANG)),) - $(error Unable to find C compiler, install and configure Xcode 4.3) - endif - - CC := $(CCACHE) $(CLANG) -Qunused-arguments - endif - - ifeq ($(origin CXX), default) - CXXLANG := $(shell xcrun -sdk $(MAC_SDK) -find clang++) - ifeq ($(wildcard $(CXXLANG)),) - $(error Unable to find C++ compiler, install and configure Xcode 4.3) - endif - - CXX := $(CCACHE) $(CXXLANG) -Qunused-arguments - endif - LINK ?= $(CXX) - - ifeq ($(origin AR), default) - AR := $(shell xcrun -sdk $(MAC_SDK) -find libtool) -static -o - endif - - ifeq ($(TARGET_PLATFORM),osx64) - ARCH_FLAGS += -arch x86_64 -m64 -march=core2 - else ifeq (,$(findstring -arch x86_64,$(GCC_ExtraCompilerFlags))) - ARCH_FLAGS += -arch i386 -m32 -march=prescott -momit-leaf-frame-pointer -mtune=core2 - else - # dirty hack to build a universal binary - don't specify the architecture - ARCH_FLAGS += -arch i386 -Xarch_i386 -march=prescott -Xarch_i386 -mtune=core2 -Xarch_i386 -momit-leaf-frame-pointer -Xarch_x86_64 -march=core2 - endif - - GEN_SYM ?= $(shell xcrun -sdk $(MAC_SDK) -find dsymutil) - ifeq ($(CFG),release) - STRIP ?= strip -S - else - STRIP ?= true - endif - ifeq ($(SOURCE_SDK), 1) - VSIGN ?= true - else - VSIGN ?= $(SRCROOT)/devtools/bin/vsign - endif - - CPPFLAGS += -I$(SYSROOT)/usr/include/malloc - CFLAGS += -isysroot $(SYSROOT) -mmacosx-version-min=10.5 -fasm-blocks - - LIB_START_EXE = -lm -ldl -lpthread - LIB_END_EXE = - - LIB_START_SHLIB = - LIB_END_SHLIB = - - SHLIBLDFLAGS = $(LDFLAGS) -bundle -flat_namespace -undefined suppress -Wl,-dead_strip -Wl,-no_dead_strip_inits_and_terms - - ifeq (lib,$(findstring lib,$(GAMEOUTPUTFILE))) - SHLIBLDFLAGS = $(LDFLAGS) -dynamiclib -current_version 1.0 -compatibility_version 1.0 -install_name @rpath/$(basename $(notdir $(GAMEOUTPUTFILE))).dylib $(SystemLibraries) -Wl,-dead_strip -Wl,-no_dead_strip_inits_and_terms - endif - -endif - -# -# Profile-directed optimizations. -# Note: Last time these were tested 3/5/08, it actually slowed down the server benchmark by 5%! -# -# First, uncomment these, build, and test. It will generate .gcda and .gcno files where the .o files are. -# PROFILE_LINKER_FLAG=-fprofile-arcs -# PROFILE_COMPILER_FLAG=-fprofile-arcs -# -# Then, comment the above flags out again and rebuild with this flag uncommented: -# PROFILE_COMPILER_FLAG=-fprofile-use -# - -############################################################################# -# The compiler command lne for each src code file to compile -############################################################################# - -OBJ_DIR = ./obj_$(NAME)_$(TARGET_PLATFORM)$(TARGET_PLATFORM_EXT)/$(CFG) -CPP_TO_OBJ = $(CPPFILES:.cpp=.o) -CXX_TO_OBJ = $(CPP_TO_OBJ:.cxx=.o) -CC_TO_OBJ = $(CXX_TO_OBJ:.cc=.o) -MM_TO_OBJ = $(CC_TO_OBJ:.mm=.o) -C_TO_OBJ = $(MM_TO_OBJ:.c=.o) -OBJS = $(addprefix $(OBJ_DIR)/, $(notdir $(C_TO_OBJ))) - -ifeq ($(MAKE_VERBOSE),1) - QUIET_PREFIX = - QUIET_ECHO_POSTFIX = -else - QUIET_PREFIX = @ - QUIET_ECHO_POSTFIX = > /dev/null -endif - -ifeq ($(MAKE_CC_VERBOSE),1) -CC += -v -endif - -ifeq ($(CONFTYPE),lib) - LIB_File = $(OUTPUTFILE) -endif - -ifeq ($(CONFTYPE),dll) - SO_File = $(OUTPUTFILE) -endif - -ifeq ($(CONFTYPE),exe) - EXE_File = $(OUTPUTFILE) -endif - -# we generate dependencies as a side-effect of compilation now -GEN_DEP_FILE= - -PRE_COMPILE_FILE = - -POST_COMPILE_FILE = - -ifeq ($(BUILDING_MULTI_ARCH),1) - SINGLE_ARCH_CXXFLAGS=$(subst -arch x86_64,,$(CXXFLAGS)) - COMPILE_FILE = \ - $(QUIET_PREFIX) \ - echo "---- $(lastword $(subst /, ,$<)) as MULTIARCH----";\ - mkdir -p $(OBJ_DIR) && \ - $(CXX) $(SINGLE_ARCH_CXXFLAGS) $(GENDEP_CXXFLAGS) -o $@ -c $< && \ - $(CXX) $(CXXFLAGS) -o $@ -c $< -else - COMPILE_FILE = \ - $(QUIET_PREFIX) \ - echo "---- $(lastword $(subst /, ,$<)) ----";\ - mkdir -p $(OBJ_DIR) && \ - $(CXX) $(CXXFLAGS) $(GENDEP_CXXFLAGS) -o $@ -c $< -endif - -ifneq "$(origin VALVE_NO_AUTO_P4)" "undefined" - P4_EDIT_START = chmod -R +w - P4_EDIT_END = || true - P4_REVERT_START = true - P4_REVERT_END = -else - ifndef P4_EDIT_CHANGELIST - # You can use an environment variable to specify what changelist to check the Linux Binaries out into. Normally the default - # setting is best, but here is an alternate example: - # export P4_EDIT_CHANGELIST_CMD="echo 1424335" - # ?= means that if P4_EDIT_CHANGELIST_CMD is already set it won't be changed. - P4_EDIT_CHANGELIST_CMD ?= p4 changes -c `p4 client -o | grep ^Client | cut -f 2` -s pending | fgrep 'POSIX Auto Checkout' | cut -d' ' -f 2 | tail -n 1 - P4_EDIT_CHANGELIST := $(shell $(P4_EDIT_CHANGELIST_CMD)) - endif - ifeq ($(P4_EDIT_CHANGELIST),) - # If we haven't found a changelist to check out to then create one. The name must match the one from a few - # lines above or else a new changelist will be created each time. - # Warning: the behavior of 'echo' is not consistent. In bash you need the "-e" option in order for \n to be - # interpreted as a line-feed, but in dash you do not, and if "-e" is passed along then it is printed, which - # confuses p4. So, if you run this command from the bash shell don't forget to add "-e" to the echo command. - P4_EDIT_CHANGELIST = $(shell echo "Change: new\nDescription: POSIX Auto Checkout" | p4 change -i | cut -f 2 -d ' ') - endif - - P4_EDIT_START := for f in - P4_EDIT_END := ; do if [ -n $$f ]; then if [ -d $$f ]; then find $$f -type f -print | p4 -x - edit -c $(P4_EDIT_CHANGELIST); else p4 edit -c $(P4_EDIT_CHANGELIST) $$f; fi; fi; done $(QUIET_ECHO_POSTFIX) - P4_REVERT_START := for f in - P4_REVERT_END := ; do if [ -n $$f ]; then if [ -d $$f ]; then find $$f -type f -print | p4 -x - revert; else p4 revert $$f; fi; fi; done $(QUIET_ECHO_POSTFIX) -endif - -ifeq ($(CONFTYPE),dll) -all: $(OTHER_DEPENDENCIES) $(OBJS) $(GAMEOUTPUTFILE) - @echo $(GAMEOUTPUTFILE) $(QUIET_ECHO_POSTFIX) -else -all: $(OTHER_DEPENDENCIES) $(OBJS) $(OUTPUTFILE) - @echo $(OUTPUTFILE) $(QUIET_ECHO_POSTFIX) -endif - -.PHONY: clean cleantargets cleanandremove rebuild relink RemoveOutputFile SingleFile - - -rebuild : - $(MAKE) -f $(firstword $(MAKEFILE_LIST)) cleanandremove - $(MAKE) -f $(firstword $(MAKEFILE_LIST)) - - -# Use the relink target to force to relink the project. -relink: RemoveOutputFile all - -RemoveOutputFile: - rm -f $(OUTPUTFILE) - - -# This rule is so you can say "make SingleFile SingleFilename=/home/myname/valve_main/src/engine/language.cpp" and have it only build that file. -# It basically just translates the full filename to create a dependency on the appropriate .o file so it'll build that. -SingleFile : RemoveSingleFile $(OBJ_DIR)/$(basename $(notdir $(SingleFilename))).o - @echo "" - -RemoveSingleFile: - $(QUIET_PREFIX) rm -f $(OBJ_DIR)/$(basename $(notdir $(SingleFilename))).o - -clean: -ifneq "$(OBJ_DIR)" "" - $(QUIET_PREFIX) echo "rm -rf $(OBJ_DIR)" - $(QUIET_PREFIX) rm -rf $(OBJ_DIR) -endif -ifneq "$(OUTPUTFILE)" "" - $(QUIET_PREFIX) if [ -e $(OUTPUTFILE) ]; then \ - echo "p4 revert $(OUTPUTFILE)"; \ - $(P4_REVERT_START) $(OUTPUTFILE) $(OUTPUTFILE)$(SYM_EXT) $(P4_REVERT_END); \ - fi; -endif -ifneq "$(OTHER_DEPENDENCIES)" "" - $(QUIET_PREFIX) echo "rm -f $(OTHER_DEPENDENCIES)" - $(QUIET_PREFIX) rm -f $(OTHER_DEPENDENCIES) -endif -ifneq "$(GAMEOUTPUTFILE)" "" - $(QUIET_PREFIX) echo "p4 revert $(GAMEOUTPUTFILE)" - $(QUIET_PREFIX) $(P4_REVERT_START) $(GAMEOUTPUTFILE) $(GAMEOUTPUTFILE)$(SYM_EXT) $(P4_REVERT_END) -endif - - -# Do the above cleaning, except with p4 edit and rm. Reason being ar crs adds and replaces obj files to the -# archive. However if you've renamed or deleted a source file, $(AR) won't remove it. This can leave -# us with archive files that have extra unused symbols, and also potentially cause compilation errors -# when you rename a file and have many duplicate symbols. -cleanandremove: -ifneq "$(OBJ_DIR)" "" - $(QUIET_PREFIX) echo "rm -rf $(OBJ_DIR)" - $(QUIET_PREFIX) -rm -rf $(OBJ_DIR) -endif -ifneq "$(OUTPUTFILE)" "" - $(QUIET_PREFIX) if [ -e $(OUTPUTFILE) ]; then \ - echo "p4 edit and rm -f $(OUTPUTFILE) $(OUTPUTFILE)$(SYM_EXT)"; \ - $(P4_EDIT_START) $(OUTPUTFILE) $(OUTPUTFILE)$(SYM_EXT) $(P4_EDIT_END); \ - fi; - $(QUIET_PREFIX) -rm -f $(OUTPUTFILE) $(OUTPUTFILE)$(SYM_EXT); -endif -ifneq "$(OTHER_DEPENDENCIES)" "" - $(QUIET_PREFIX) echo "rm -f $(OTHER_DEPENDENCIES)" - $(QUIET_PREFIX) -rm -f $(OTHER_DEPENDENCIES) -endif -ifneq "$(GAMEOUTPUTFILE)" "" - $(QUIET_PREFIX) echo "p4 edit and rm -f $(GAMEOUTPUTFILE) $(GAMEOUTPUTFILE)$(SYM_EXT)" - $(QUIET_PREFIX) $(P4_EDIT_START) $(GAMEOUTPUTFILE) $(GAMEOUTPUTFILE)$(SYM_EXT) $(P4_EDIT_END) - $(QUIET_PREFIX) -rm -f $(GAMEOUTPUTFILE) -endif - - -# This just deletes the final targets so it'll do a relink next time we build. -cleantargets: - $(QUIET_PREFIX) rm -f $(OUTPUTFILE) $(GAMEOUTPUTFILE) - - -$(LIB_File): $(OTHER_DEPENDENCIES) $(OBJS) - $(QUIET_PREFIX) -$(P4_EDIT_START) $(LIB_File) $(P4_EDIT_END); - $(QUIET_PREFIX) $(AR) $(LIB_File) $(OBJS) $(LIBFILES); - -SO_GameOutputFile = $(GAMEOUTPUTFILE) - -# Remove the target before installing a file over it; this prevents existing -# instances of the game from crashing due to the overwrite. -$(SO_GameOutputFile): $(SO_File) - $(QUIET_PREFIX) \ - $(P4_EDIT_START) $(GAMEOUTPUTFILE) $(P4_EDIT_END) && \ - echo "----" $(QUIET_ECHO_POSTFIX);\ - echo "---- COPYING TO $@ [$(CFG)] ----";\ - echo "----" $(QUIET_ECHO_POSTFIX); - $(QUIET_PREFIX) -$(P4_EDIT_START) $(GAMEOUTPUTFILE) $(P4_EDIT_END); - $(QUIET_PREFIX) -mkdir -p `dirname $(GAMEOUTPUTFILE)` > /dev/null; - $(QUIET_PREFIX) rm -f $(GAMEOUTPUTFILE) $(QUIET_ECHO_POSTFIX); - $(QUIET_PREFIX) cp -v $(OUTPUTFILE) $(GAMEOUTPUTFILE) $(QUIET_ECHO_POSTFIX); - $(QUIET_PREFIX) -$(P4_EDIT_START) $(GAMEOUTPUTFILE)$(SYM_EXT) $(P4_EDIT_END); - $(QUIET_PREFIX) $(GEN_SYM) $(GAMEOUTPUTFILE); - $(QUIET_PREFIX) -$(STRIP) $(GAMEOUTPUTFILE); - $(QUIET_PREFIX) $(VSIGN) -signvalve $(GAMEOUTPUTFILE); - $(QUIET_PREFIX) if [ "$(COPY_DLL_TO_SRV)" = "1" ]; then\ - echo "----" $(QUIET_ECHO_POSTFIX);\ - echo "---- COPYING TO $(Srv_GAMEOUTPUTFILE) ----";\ - echo "----" $(QUIET_ECHO_POSTFIX);\ - cp -v $(GAMEOUTPUTFILE) $(Srv_GAMEOUTPUTFILE) $(QUIET_ECHO_POSTFIX);\ - cp -v $(GAMEOUTPUTFILE)$(SYM_EXT) $(Srv_GAMEOUTPUTFILE)$(SYM_EXT) $(QUIET_ECHO_POSTFIX);\ - fi; - $(QUIET_PREFIX) if [ "$(IMPORTLIBRARY)" != "" ]; then\ - echo "----" $(QUIET_ECHO_POSTFIX);\ - echo "---- COPYING TO IMPORT LIBRARY $(IMPORTLIBRARY) ----";\ - echo "----" $(QUIET_ECHO_POSTFIX);\ - $(P4_EDIT_START) $(IMPORTLIBRARY) $(P4_EDIT_END) && \ - mkdir -p `dirname $(IMPORTLIBRARY)` > /dev/null && \ - cp -v $(OUTPUTFILE) $(IMPORTLIBRARY); \ - fi; - - -$(SO_File): $(OTHER_DEPENDENCIES) $(OBJS) $(LIBFILENAMES) - $(QUIET_PREFIX) \ - echo "----" $(QUIET_ECHO_POSTFIX);\ - echo "---- LINKING $@ [$(CFG)] ----";\ - echo "----" $(QUIET_ECHO_POSTFIX);\ - \ - $(LINK) $(LINK_MAP_FLAGS) $(SHLIBLDFLAGS) $(PROFILE_LINKER_FLAG) -o $(OUTPUTFILE) $(LIB_START_SHLIB) $(OBJS) $(LIBFILES) $(SystemLibraries) $(LIB_END_SHLIB); - $(VSIGN) -signvalve $(OUTPUTFILE); - - -$(EXE_File) : $(OTHER_DEPENDENCIES) $(OBJS) $(LIBFILENAMES) - $(QUIET_PREFIX) \ - echo "----" $(QUIET_ECHO_POSTFIX);\ - echo "---- LINKING EXE $@ [$(CFG)] ----";\ - echo "----" $(QUIET_ECHO_POSTFIX);\ - \ - $(P4_EDIT_START) $(OUTPUTFILE) $(P4_EDIT_END);\ - $(LINK) $(LINK_MAP_FLAGS) $(LDFLAGS) $(PROFILE_LINKER_FLAG) -o $(OUTPUTFILE) $(LIB_START_EXE) $(OBJS) $(LIBFILES) $(SystemLibraries) $(LIB_END_EXE); - $(QUIET_PREFIX) -$(P4_EDIT_START) $(OUTPUTFILE)$(SYM_EXT) $(P4_EDIT_END); - $(QUIET_PREFIX) $(GEN_SYM) $(OUTPUTFILE); - $(QUIET_PREFIX) -$(STRIP) $(OUTPUTFILE); - $(QUIET_PREFIX) $(VSIGN) -signvalve $(OUTPUTFILE); - - -tags: - etags -a -C -o $(SRCROOT)/TAGS *.cpp *.cxx *.h *.hxx +# +# Base makefile for Linux and OSX +# +# !!!!! Note to future editors !!!!! +# +# before you make changes, make sure you grok: +# 1. the difference between =, :=, +=, and ?= +# 2. how and when this base makefile gets included in the generated makefile(s) +# ( see http://www.gnu.org/software/make/manual/make.html#Flavors ) +# +# Command line prefixes: +# - errors are ignored +# @ command is not printed to stdout before being executed +# + command is executed even if Make is invoked in "do not exec" mode + +OS := $(shell uname) +HOSTNAME := $(shell hostname) + +-include $(SRCROOT)/devtools/steam_def.mak +-include $(SRCROOT)/devtools/sourcesdk_def.mak + +# To build with clang, set the following in your environment: +# CC = clang +# CXX = clang++ + +ifeq ($(CFG), release) + # With gcc 4.6.3, engine.so went from 7,383,765 to 8,429,109 when building with -O3. + # There also was no speed difference running at 1280x1024. May 2012, mikesart. + # tonyp: The size increase was likely caused by -finline-functions and -fipa-cp-clone getting switched on with -O3. + # -fno-omit-frame-pointer: need this for stack traces with perf. + OptimizerLevel_CompilerSpecific = -O2 -fno-strict-aliasing -ffast-math -fno-omit-frame-pointer -ftree-vectorize -fpredictive-commoning -funswitch-loops +else + OptimizerLevel_CompilerSpecific = -O0 + #-O1 -finline-functions +endif + +# CPPFLAGS == "c/c++ *preprocessor* flags" - not "cee-plus-plus flags" +ARCH_FLAGS = +BUILDING_MULTI_ARCH = 0 +CPPFLAGS = $(DEFINES) $(addprefix -I, $(abspath $(INCLUDEDIRS) )) +CFLAGS = $(ARCH_FLAGS) $(CPPFLAGS) $(WARN_FLAGS) -fvisibility=$(SymbolVisibility) $(OptimizerLevel) -pipe $(GCC_ExtraCompilerFlags) -Usprintf -Ustrncpy -UPROTECTED_THINGS_ENABLE +# In -std=gnu++0x mode we get lots of errors about "error: narrowing conversion". -fpermissive +# turns these into warnings in gcc, and -Wno-c++11-narrowing suppresses them entirely in clang 3.1+. +ifeq ($(CXX),clang++) + CXXFLAGS = $(CFLAGS) -Wno-c++11-narrowing -Wno-dangling-else +else + CXXFLAGS = $(CFLAGS) -fpermissive +endif +DEFINES += -DVPROF_LEVEL=1 -DGNUC -DNO_HOOK_MALLOC -DNO_MALLOC_OVERRIDE +LDFLAGS = $(CFLAGS) $(GCC_ExtraLinkerFlags) $(OptimizerLevel) +GENDEP_CXXFLAGS = -MD -MP -MF $(@:.o=.P) +MAP_FLAGS = +Srv_GAMEOUTPUTFILE = +COPY_DLL_TO_SRV = 0 + + +ifeq ($(STEAM_BRANCH),1) + WARN_FLAGS = -Wall -Wextra -Wshadow -Wno-invalid-offsetof +else + WARN_FLAGS = -Wno-write-strings -Wno-multichar +endif + +WARN_FLAGS += -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-value -Wno-missing-field-initializers -Wno-sign-compare -Wno-reorder -Wno-invalid-offsetof -Wno-float-equal -Werror=return-type -fdiagnostics-show-option -Wformat -Wformat-security + + +ifeq ($(OS),Linux) + # We should always specify -Wl,--build-id, as documented at: + # http://linux.die.net/man/1/ld and http://fedoraproject.org/wiki/Releases/FeatureBuildId.http://fedoraproject.org/wiki/Releases/FeatureBuildId + LDFLAGS += -Wl,--build-id + # Set USE_VALVE_BINDIR to build with /Steam/tools/linux in the /valve/bin path. + # Dedicated server uses this. + ifeq ($(USE_VALVE_BINDIR),1) + # dedicated server flags + ifeq ($(TARGET_PLATFORM),linux64) + VALVE_BINDIR = /valve/bin64/ + MARCH_TARGET = nocona + else + VALVE_BINDIR = /valve/bin/ + MARCH_TARGET = pentium4 + endif + STRIP_FLAGS = + else + # linux desktop client flags + VALVE_BINDIR = + # If the steam-runtime is available, use it. We should just default to using it when + # buildbot and everyone has a bit of time to get it installed. + ifneq "$(wildcard /valve/steam-runtime/bin/)" "" + # The steam-runtime is incompatible with clang at this point, so disable it + # if clang is enabled. + ifneq ($(CXX),clang++) + VALVE_BINDIR = /valve/steam-runtime/bin/ + endif + endif + GCC_VER = + MARCH_TARGET = pentium4 + # On dedicated servers, some plugins depend on global variable symbols in addition to functions. + # So symbols like _Z16ClearMultiDamagev should show up when you do "nm server_srv.so" in TF2. + STRIP_FLAGS = -x + endif + + ifeq ($(CXX),clang++) + # Clang does not support -mfpmath=sse because it uses whatever + # instruction set extensions are available by default. + SSE_GEN_FLAGS = -msse2 + else + SSE_GEN_FLAGS = -msse2 -mfpmath=sse + endif + + CCACHE := $(SRCROOT)/devtools/bin/linux/ccache + + ifeq ($(origin GCC_VER), undefined) + GCC_VER=-4.6 + endif + ifeq ($(origin AR), default) + AR = $(VALVE_BINDIR)ar crs + endif + ifeq ($(origin CC),default) + CC = $(CCACHE) $(VALVE_BINDIR)gcc$(GCC_VER) + endif + ifeq ($(origin CXX), default) + CXX = $(CCACHE) $(VALVE_BINDIR)g++$(GCC_VER) + endif + # Support ccache with clang. Add -Qunused-arguments to avoid excessive warnings due to + # a ccache quirk. Could also upgrade ccache. + # http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html + ifeq ($(CC),clang) + CC = $(CCACHE) $(VALVE_BINDIR)clang -Qunused-arguments + endif + ifeq ($(CXX),clang++) + CXX = $(CCACHE) $(VALVE_BINDIR)clang++ -Qunused-arguments + endif + LINK ?= $(CC) + + ifeq ($(TARGET_PLATFORM),linux64) + # nocona = pentium4 + 64bit + MMX, SSE, SSE2, SSE3 - no SSSE3 (that's three s's - added in core2) + ARCH_FLAGS += -march=$(MARCH_TARGET) -mtune=core2 + LD_SO = ld-linux-x86_64.so.2 + LIBSTDCXX := $(shell $(CXX) -print-file-name=libstdc++.a) + LIBSTDCXXPIC := $(shell $(CXX) -print-file-name=libstdc++-pic.a) + else + # pentium4 = MMX, SSE, SSE2 - no SSE3 (added in prescott) # -msse3 -mfpmath=sse + ARCH_FLAGS += -m32 -march=$(MARCH_TARGET) -mtune=core2 $(SSE_GEN_FLAGS) + LD_SO = ld-linux.so.2 + LIBSTDCXX := $(shell $(CXX) $(ARCH_FLAGS) -print-file-name=libstdc++.so) + LIBSTDCXXPIC := $(shell $(CXX) $(ARCH_FLAGS) -print-file-name=libstdc++.so) + LDFLAGS += -m32 + endif + + GEN_SYM ?= $(SRCROOT)/devtools/gendbg.sh + ifeq ($(CFG),release) + STRIP ?= strip $(STRIP_FLAGS) -S + # CFLAGS += -ffunction-sections -fdata-sections + # LDFLAGS += -Wl,--gc-sections -Wl,--print-gc-sections + else + STRIP ?= true + endif + VSIGN ?= true + + ifeq ($(SOURCE_SDK), 1) + Srv_GAMEOUTPUTFILE := $(GAMEOUTPUTFILE:.so=_srv.so) + COPY_DLL_TO_SRV := 1 + endif + + LINK_MAP_FLAGS = -Wl,-Map,$(@:.so=).map + + SHLIBLDFLAGS = -shared $(LDFLAGS) -Wl,--no-undefined + + _WRAP := -Xlinker --wrap= + PATHWRAP = $(_WRAP)fopen $(_WRAP)freopen $(_WRAP)open $(_WRAP)creat $(_WRAP)access $(_WRAP)__xstat \ + $(_WRAP)stat $(_WRAP)lstat $(_WRAP)fopen64 $(_WRAP)open64 $(_WRAP)opendir $(_WRAP)__lxstat \ + $(_WRAP)chmod $(_WRAP)chown $(_WRAP)lchown $(_WRAP)symlink $(_WRAP)link $(_WRAP)__lxstat64 \ + $(_WRAP)mknod $(_WRAP)utimes $(_WRAP)unlink $(_WRAP)rename $(_WRAP)utime $(_WRAP)__xstat64 \ + $(_WRAP)mount $(_WRAP)mkfifo $(_WRAP)mkdir $(_WRAP)rmdir $(_WRAP)scandir $(_WRAP)realpath + + LIB_START_EXE = $(PATHWRAP) -static-libgcc -Wl,--start-group + LIB_END_EXE = -Wl,--end-group -lm -ldl $(LIBSTDCXX) -lpthread + + LIB_START_SHLIB = $(PATHWRAP) -static-libgcc -Wl,--start-group + LIB_END_SHLIB = -Wl,--end-group -lm -ldl $(LIBSTDCXXPIC) -lpthread -l:$(LD_SO) -Wl,--version-script=$(SRCROOT)/devtools/version_script.linux.txt + +endif + +ifeq ($(OS),Darwin) + CCACHE := $(SRCROOT)/devtools/bin/osx32/ccache + MAC_SDK_VER ?= 10.6 + MAC_SDK := macosx$(MAC_SDK_VER) + SYSROOT := $(shell xcodebuild -sdk $(MAC_SDK) -version Path) + + ifneq ($(origin MAC_SDK_VER), file) + $(warning Attempting build with SDK version $(MAC_SDK_VER), only 10.6 is supported and recommended!) + endif + + ifeq ($(SYSROOT),) + FIRSTSDK := $(firstword $(sort $(shell xcodebuild -showsdks | grep macosx | sed 's/.*macosx//'))) + $(error Could not find SDK version $(MAC_SDK_VER). Install and configure Xcode 4.3, or build with: make MAC_SDK_VER=$(FIRSTSDK)) + endif + + ifeq ($(origin CC), default) + # Test to see if you have a compiler in the right place, if you + # don't abort with an error + CLANG := $(shell xcrun -sdk $(MAC_SDK) -find clang) + ifeq ($(wildcard $(CLANG)),) + $(error Unable to find C compiler, install and configure Xcode 4.3) + endif + + CC := $(CCACHE) $(CLANG) -Qunused-arguments + endif + + ifeq ($(origin CXX), default) + CXXLANG := $(shell xcrun -sdk $(MAC_SDK) -find clang++) + ifeq ($(wildcard $(CXXLANG)),) + $(error Unable to find C++ compiler, install and configure Xcode 4.3) + endif + + CXX := $(CCACHE) $(CXXLANG) -Qunused-arguments + endif + LINK ?= $(CXX) + + ifeq ($(origin AR), default) + AR := $(shell xcrun -sdk $(MAC_SDK) -find libtool) -static -o + endif + + ifeq ($(TARGET_PLATFORM),osx64) + ARCH_FLAGS += -arch x86_64 -m64 -march=core2 + else ifeq (,$(findstring -arch x86_64,$(GCC_ExtraCompilerFlags))) + ARCH_FLAGS += -arch i386 -m32 -march=prescott -momit-leaf-frame-pointer -mtune=core2 + else + # dirty hack to build a universal binary - don't specify the architecture + ARCH_FLAGS += -arch i386 -Xarch_i386 -march=prescott -Xarch_i386 -mtune=core2 -Xarch_i386 -momit-leaf-frame-pointer -Xarch_x86_64 -march=core2 + endif + + GEN_SYM ?= $(shell xcrun -sdk $(MAC_SDK) -find dsymutil) + ifeq ($(CFG),release) + STRIP ?= strip -S + else + STRIP ?= true + endif + ifeq ($(SOURCE_SDK), 1) + VSIGN ?= true + else + VSIGN ?= $(SRCROOT)/devtools/bin/vsign + endif + + CPPFLAGS += -I$(SYSROOT)/usr/include/malloc + CFLAGS += -isysroot $(SYSROOT) -mmacosx-version-min=10.5 -fasm-blocks + + LIB_START_EXE = -lm -ldl -lpthread + LIB_END_EXE = + + LIB_START_SHLIB = + LIB_END_SHLIB = + + SHLIBLDFLAGS = $(LDFLAGS) -bundle -flat_namespace -undefined suppress -Wl,-dead_strip -Wl,-no_dead_strip_inits_and_terms + + ifeq (lib,$(findstring lib,$(GAMEOUTPUTFILE))) + SHLIBLDFLAGS = $(LDFLAGS) -dynamiclib -current_version 1.0 -compatibility_version 1.0 -install_name @rpath/$(basename $(notdir $(GAMEOUTPUTFILE))).dylib $(SystemLibraries) -Wl,-dead_strip -Wl,-no_dead_strip_inits_and_terms + endif + +endif + +# +# Profile-directed optimizations. +# Note: Last time these were tested 3/5/08, it actually slowed down the server benchmark by 5%! +# +# First, uncomment these, build, and test. It will generate .gcda and .gcno files where the .o files are. +# PROFILE_LINKER_FLAG=-fprofile-arcs +# PROFILE_COMPILER_FLAG=-fprofile-arcs +# +# Then, comment the above flags out again and rebuild with this flag uncommented: +# PROFILE_COMPILER_FLAG=-fprofile-use +# + +############################################################################# +# The compiler command lne for each src code file to compile +############################################################################# + +OBJ_DIR = ./obj_$(NAME)_$(TARGET_PLATFORM)$(TARGET_PLATFORM_EXT)/$(CFG) +CPP_TO_OBJ = $(CPPFILES:.cpp=.o) +CXX_TO_OBJ = $(CPP_TO_OBJ:.cxx=.o) +CC_TO_OBJ = $(CXX_TO_OBJ:.cc=.o) +MM_TO_OBJ = $(CC_TO_OBJ:.mm=.o) +C_TO_OBJ = $(MM_TO_OBJ:.c=.o) +OBJS = $(addprefix $(OBJ_DIR)/, $(notdir $(C_TO_OBJ))) + +ifeq ($(MAKE_VERBOSE),1) + QUIET_PREFIX = + QUIET_ECHO_POSTFIX = +else + QUIET_PREFIX = @ + QUIET_ECHO_POSTFIX = > /dev/null +endif + +ifeq ($(MAKE_CC_VERBOSE),1) +CC += -v +endif + +ifeq ($(CONFTYPE),lib) + LIB_File = $(OUTPUTFILE) +endif + +ifeq ($(CONFTYPE),dll) + SO_File = $(OUTPUTFILE) +endif + +ifeq ($(CONFTYPE),exe) + EXE_File = $(OUTPUTFILE) +endif + +# we generate dependencies as a side-effect of compilation now +GEN_DEP_FILE= + +PRE_COMPILE_FILE = + +POST_COMPILE_FILE = + +ifeq ($(BUILDING_MULTI_ARCH),1) + SINGLE_ARCH_CXXFLAGS=$(subst -arch x86_64,,$(CXXFLAGS)) + COMPILE_FILE = \ + $(QUIET_PREFIX) \ + echo "---- $(lastword $(subst /, ,$<)) as MULTIARCH----";\ + mkdir -p $(OBJ_DIR) && \ + $(CXX) $(SINGLE_ARCH_CXXFLAGS) $(GENDEP_CXXFLAGS) -o $@ -c $< && \ + $(CXX) $(CXXFLAGS) -o $@ -c $< +else + COMPILE_FILE = \ + $(QUIET_PREFIX) \ + echo "---- $(lastword $(subst /, ,$<)) ----";\ + mkdir -p $(OBJ_DIR) && \ + $(CXX) $(CXXFLAGS) $(GENDEP_CXXFLAGS) -o $@ -c $< +endif + +ifneq "$(origin VALVE_NO_AUTO_P4)" "undefined" + P4_EDIT_START = chmod -R +w + P4_EDIT_END = || true + P4_REVERT_START = true + P4_REVERT_END = +else + ifndef P4_EDIT_CHANGELIST + # You can use an environment variable to specify what changelist to check the Linux Binaries out into. Normally the default + # setting is best, but here is an alternate example: + # export P4_EDIT_CHANGELIST_CMD="echo 1424335" + # ?= means that if P4_EDIT_CHANGELIST_CMD is already set it won't be changed. + P4_EDIT_CHANGELIST_CMD ?= p4 changes -c `p4 client -o | grep ^Client | cut -f 2` -s pending | fgrep 'POSIX Auto Checkout' | cut -d' ' -f 2 | tail -n 1 + P4_EDIT_CHANGELIST := $(shell $(P4_EDIT_CHANGELIST_CMD)) + endif + ifeq ($(P4_EDIT_CHANGELIST),) + # If we haven't found a changelist to check out to then create one. The name must match the one from a few + # lines above or else a new changelist will be created each time. + # Warning: the behavior of 'echo' is not consistent. In bash you need the "-e" option in order for \n to be + # interpreted as a line-feed, but in dash you do not, and if "-e" is passed along then it is printed, which + # confuses p4. So, if you run this command from the bash shell don't forget to add "-e" to the echo command. + P4_EDIT_CHANGELIST = $(shell echo "Change: new\nDescription: POSIX Auto Checkout" | p4 change -i | cut -f 2 -d ' ') + endif + + P4_EDIT_START := for f in + P4_EDIT_END := ; do if [ -n $$f ]; then if [ -d $$f ]; then find $$f -type f -print | p4 -x - edit -c $(P4_EDIT_CHANGELIST); else p4 edit -c $(P4_EDIT_CHANGELIST) $$f; fi; fi; done $(QUIET_ECHO_POSTFIX) + P4_REVERT_START := for f in + P4_REVERT_END := ; do if [ -n $$f ]; then if [ -d $$f ]; then find $$f -type f -print | p4 -x - revert; else p4 revert $$f; fi; fi; done $(QUIET_ECHO_POSTFIX) +endif + +ifeq ($(CONFTYPE),dll) +all: $(OTHER_DEPENDENCIES) $(OBJS) $(GAMEOUTPUTFILE) + @echo $(GAMEOUTPUTFILE) $(QUIET_ECHO_POSTFIX) +else +all: $(OTHER_DEPENDENCIES) $(OBJS) $(OUTPUTFILE) + @echo $(OUTPUTFILE) $(QUIET_ECHO_POSTFIX) +endif + +.PHONY: clean cleantargets cleanandremove rebuild relink RemoveOutputFile SingleFile + + +rebuild : + $(MAKE) -f $(firstword $(MAKEFILE_LIST)) cleanandremove + $(MAKE) -f $(firstword $(MAKEFILE_LIST)) + + +# Use the relink target to force to relink the project. +relink: RemoveOutputFile all + +RemoveOutputFile: + rm -f $(OUTPUTFILE) + + +# This rule is so you can say "make SingleFile SingleFilename=/home/myname/valve_main/src/engine/language.cpp" and have it only build that file. +# It basically just translates the full filename to create a dependency on the appropriate .o file so it'll build that. +SingleFile : RemoveSingleFile $(OBJ_DIR)/$(basename $(notdir $(SingleFilename))).o + @echo "" + +RemoveSingleFile: + $(QUIET_PREFIX) rm -f $(OBJ_DIR)/$(basename $(notdir $(SingleFilename))).o + +clean: +ifneq "$(OBJ_DIR)" "" + $(QUIET_PREFIX) echo "rm -rf $(OBJ_DIR)" + $(QUIET_PREFIX) rm -rf $(OBJ_DIR) +endif +ifneq "$(OUTPUTFILE)" "" + $(QUIET_PREFIX) if [ -e $(OUTPUTFILE) ]; then \ + echo "p4 revert $(OUTPUTFILE)"; \ + $(P4_REVERT_START) $(OUTPUTFILE) $(OUTPUTFILE)$(SYM_EXT) $(P4_REVERT_END); \ + fi; +endif +ifneq "$(OTHER_DEPENDENCIES)" "" + $(QUIET_PREFIX) echo "rm -f $(OTHER_DEPENDENCIES)" + $(QUIET_PREFIX) rm -f $(OTHER_DEPENDENCIES) +endif +ifneq "$(GAMEOUTPUTFILE)" "" + $(QUIET_PREFIX) echo "p4 revert $(GAMEOUTPUTFILE)" + $(QUIET_PREFIX) $(P4_REVERT_START) $(GAMEOUTPUTFILE) $(GAMEOUTPUTFILE)$(SYM_EXT) $(P4_REVERT_END) +endif + + +# Do the above cleaning, except with p4 edit and rm. Reason being ar crs adds and replaces obj files to the +# archive. However if you've renamed or deleted a source file, $(AR) won't remove it. This can leave +# us with archive files that have extra unused symbols, and also potentially cause compilation errors +# when you rename a file and have many duplicate symbols. +cleanandremove: +ifneq "$(OBJ_DIR)" "" + $(QUIET_PREFIX) echo "rm -rf $(OBJ_DIR)" + $(QUIET_PREFIX) -rm -rf $(OBJ_DIR) +endif +ifneq "$(OUTPUTFILE)" "" + $(QUIET_PREFIX) if [ -e $(OUTPUTFILE) ]; then \ + echo "p4 edit and rm -f $(OUTPUTFILE) $(OUTPUTFILE)$(SYM_EXT)"; \ + $(P4_EDIT_START) $(OUTPUTFILE) $(OUTPUTFILE)$(SYM_EXT) $(P4_EDIT_END); \ + fi; + $(QUIET_PREFIX) -rm -f $(OUTPUTFILE) $(OUTPUTFILE)$(SYM_EXT); +endif +ifneq "$(OTHER_DEPENDENCIES)" "" + $(QUIET_PREFIX) echo "rm -f $(OTHER_DEPENDENCIES)" + $(QUIET_PREFIX) -rm -f $(OTHER_DEPENDENCIES) +endif +ifneq "$(GAMEOUTPUTFILE)" "" + $(QUIET_PREFIX) echo "p4 edit and rm -f $(GAMEOUTPUTFILE) $(GAMEOUTPUTFILE)$(SYM_EXT)" + $(QUIET_PREFIX) $(P4_EDIT_START) $(GAMEOUTPUTFILE) $(GAMEOUTPUTFILE)$(SYM_EXT) $(P4_EDIT_END) + $(QUIET_PREFIX) -rm -f $(GAMEOUTPUTFILE) +endif + + +# This just deletes the final targets so it'll do a relink next time we build. +cleantargets: + $(QUIET_PREFIX) rm -f $(OUTPUTFILE) $(GAMEOUTPUTFILE) + + +$(LIB_File): $(OTHER_DEPENDENCIES) $(OBJS) + $(QUIET_PREFIX) -$(P4_EDIT_START) $(LIB_File) $(P4_EDIT_END); + $(QUIET_PREFIX) $(AR) $(LIB_File) $(OBJS) $(LIBFILES); + +SO_GameOutputFile = $(GAMEOUTPUTFILE) + +# Remove the target before installing a file over it; this prevents existing +# instances of the game from crashing due to the overwrite. +$(SO_GameOutputFile): $(SO_File) + $(QUIET_PREFIX) \ + $(P4_EDIT_START) $(GAMEOUTPUTFILE) $(P4_EDIT_END) && \ + echo "----" $(QUIET_ECHO_POSTFIX);\ + echo "---- COPYING TO $@ [$(CFG)] ----";\ + echo "----" $(QUIET_ECHO_POSTFIX); + $(QUIET_PREFIX) -$(P4_EDIT_START) $(GAMEOUTPUTFILE) $(P4_EDIT_END); + $(QUIET_PREFIX) -mkdir -p `dirname $(GAMEOUTPUTFILE)` > /dev/null; + $(QUIET_PREFIX) rm -f $(GAMEOUTPUTFILE) $(QUIET_ECHO_POSTFIX); + $(QUIET_PREFIX) cp -v $(OUTPUTFILE) $(GAMEOUTPUTFILE) $(QUIET_ECHO_POSTFIX); + $(QUIET_PREFIX) -$(P4_EDIT_START) $(GAMEOUTPUTFILE)$(SYM_EXT) $(P4_EDIT_END); + $(QUIET_PREFIX) $(GEN_SYM) $(GAMEOUTPUTFILE); + $(QUIET_PREFIX) -$(STRIP) $(GAMEOUTPUTFILE); + $(QUIET_PREFIX) $(VSIGN) -signvalve $(GAMEOUTPUTFILE); + $(QUIET_PREFIX) if [ "$(COPY_DLL_TO_SRV)" = "1" ]; then\ + echo "----" $(QUIET_ECHO_POSTFIX);\ + echo "---- COPYING TO $(Srv_GAMEOUTPUTFILE) ----";\ + echo "----" $(QUIET_ECHO_POSTFIX);\ + cp -v $(GAMEOUTPUTFILE) $(Srv_GAMEOUTPUTFILE) $(QUIET_ECHO_POSTFIX);\ + cp -v $(GAMEOUTPUTFILE)$(SYM_EXT) $(Srv_GAMEOUTPUTFILE)$(SYM_EXT) $(QUIET_ECHO_POSTFIX);\ + fi; + $(QUIET_PREFIX) if [ "$(IMPORTLIBRARY)" != "" ]; then\ + echo "----" $(QUIET_ECHO_POSTFIX);\ + echo "---- COPYING TO IMPORT LIBRARY $(IMPORTLIBRARY) ----";\ + echo "----" $(QUIET_ECHO_POSTFIX);\ + $(P4_EDIT_START) $(IMPORTLIBRARY) $(P4_EDIT_END) && \ + mkdir -p `dirname $(IMPORTLIBRARY)` > /dev/null && \ + cp -v $(OUTPUTFILE) $(IMPORTLIBRARY); \ + fi; + + +$(SO_File): $(OTHER_DEPENDENCIES) $(OBJS) $(LIBFILENAMES) + $(QUIET_PREFIX) \ + echo "----" $(QUIET_ECHO_POSTFIX);\ + echo "---- LINKING $@ [$(CFG)] ----";\ + echo "----" $(QUIET_ECHO_POSTFIX);\ + \ + $(LINK) $(LINK_MAP_FLAGS) $(SHLIBLDFLAGS) $(PROFILE_LINKER_FLAG) -o $(OUTPUTFILE) $(LIB_START_SHLIB) $(OBJS) $(LIBFILES) $(SystemLibraries) $(LIB_END_SHLIB); + $(VSIGN) -signvalve $(OUTPUTFILE); + + +$(EXE_File) : $(OTHER_DEPENDENCIES) $(OBJS) $(LIBFILENAMES) + $(QUIET_PREFIX) \ + echo "----" $(QUIET_ECHO_POSTFIX);\ + echo "---- LINKING EXE $@ [$(CFG)] ----";\ + echo "----" $(QUIET_ECHO_POSTFIX);\ + \ + $(P4_EDIT_START) $(OUTPUTFILE) $(P4_EDIT_END);\ + $(LINK) $(LINK_MAP_FLAGS) $(LDFLAGS) $(PROFILE_LINKER_FLAG) -o $(OUTPUTFILE) $(LIB_START_EXE) $(OBJS) $(LIBFILES) $(SystemLibraries) $(LIB_END_EXE); + $(QUIET_PREFIX) -$(P4_EDIT_START) $(OUTPUTFILE)$(SYM_EXT) $(P4_EDIT_END); + $(QUIET_PREFIX) $(GEN_SYM) $(OUTPUTFILE); + $(QUIET_PREFIX) -$(STRIP) $(OUTPUTFILE); + $(QUIET_PREFIX) $(VSIGN) -signvalve $(OUTPUTFILE); + + +tags: + etags -a -C -o $(SRCROOT)/TAGS *.cpp *.cxx *.h *.hxx -- cgit v1.2.3