1 #!/usr/bin/perl 2 use Cwd; 3 use IO::File; 4 use strict; 5 use Getopt::Long; 6 use CoolStackPkg; 7 8 my $_doPackage = 0; 9 my $_doSrcPackage = 0; 10 my $_exitOnFailure = 0; 11 my $_cleanupAtStart = 0; 12 my $_noExecute = 0; 13 my $_rebuild = 1; 14 my $_installDir = $ENV{INSTALLDIR}; 15 my $_buildDir = "build"; 16 my $_packagesDir = "./packages"; 17 my $_srcPackagelocation = ""; 18 19 sub findDiff($$) 20 { 21 my ($dirname, $prevList) = @_; 22 my @newList = `find $dirname -name "*"`; 23 my %prevListHash; 24 25 foreach my $entry (@$prevList) { 26 # Remove spaces 27 chomp $entry; 28 $entry =~ s/\s*$//g; 29 $prevListHash{$entry} = 1; 30 } 31 my @diffList = (); 32 foreach my $entry (@newList) { 33 # Remove spaces 34 chomp $entry; 35 $entry =~ s/\s*$//g; 36 unless (exists $prevListHash{$entry}) { 37 push(@diffList, $entry); 38 } 39 } 40 return \@diffList; 41 } 42 43 sub generateDiff($$$) 44 { 45 my ($dirname, $prevListFileName, $outputFile) = @_; 46 my $fh = new IO::File("<$prevListFileName"); 47 die "Unable to open file $prevListFileName" unless defined $fh; 48 my @fileList = <$fh>; 49 my $diffList = findDiff($dirname, \@fileList); 50 $fh->close(); 51 $fh = new IO::File(">$outputFile"); 52 foreach my $entry (@$diffList) { 53 $fh->print("$entry\n"); 54 } 55 $fh->close(); 56 } 57 58 sub compile 59 { 60 my $comp = shift; 61 my %compOptions = @_; 62 print "Compiling $comp\n"; 63 my $compBasename = $comp; 64 if ($comp =~ m/(.+?)-\d/) { 65 $compBasename = $1; 66 } 67 if (defined $compOptions{"COMP_NAME"}) { 68 $compBasename = $compOptions{"COMP_NAME"}; 69 } 70 71 my $compPrev = "./$_buildDir/$compBasename" . "_prev_files"; 72 my $compFilesName = "./$_buildDir/$compBasename" . "_files"; 73 74 if ((! -e $compPrev) && $_doPackage) { 75 system("find $_installDir -name \"*\" > $compPrev"); 76 } 77 my $workdir = getcwd(); 78 my $doneFile = "$workdir/$_buildDir/$compBasename.done"; 79 80 chdir $comp or die "Unable to change directory to $comp\n"; 81 82 83 my $cmd="./make_solaris.sh"; 84 if (defined $compOptions{"SCRIPT"}) { 85 $cmd = $compOptions{"SCRIPT"}; 86 } 87 88 my $outfile = "make.out"; 89 if (defined $compOptions{"OUT_FILE"}) { 90 $outfile = $compOptions{"OUT_FILE"}; 91 } 92 93 my @cmdArgs = (); 94 if (defined $compOptions{"COMMAND_ARGS"}) { 95 @cmdArgs = @{$compOptions{"COMMAND_ARGS"}}; 96 } 97 98 my $retval = 0; 99 print "$cmd @cmdArgs > $outfile 2>&1 \n"; 100 unless ($_noExecute) { 101 unless (-e "$doneFile" ) { 102 $retval = system("$cmd @cmdArgs > $outfile 2>&1"); 103 } else { 104 print "$comp was already compiled successfully\n"; 105 } 106 } 107 if ($retval == 0) { 108 print "Compilation for $comp completed with success\n"; 109 } 110 else { 111 print "Compilation for $comp completed with *failure*\n"; 112 if ($_exitOnFailure) { 113 exit (1); 114 } 115 } 116 117 chdir $workdir; 118 if ($retval == 0) { 119 if ((! -e "$compFilesName") && $_doPackage) { 120 print "Generating diff $compFilesName\n"; 121 generateDiff($_installDir, $compPrev, $compFilesName); 122 print "Generating diff done\n"; 123 } 124 125 unless ($_noExecute) { 126 system("touch $doneFile"); 127 } 128 } 129 print "\n"; 130 return $retval; 131 } 132 133 sub createDirectories 134 { 135 foreach my $var (@_) { 136 mkdir $var unless (-d $var); 137 } 138 } 139 140 sub compile_coolstack 141 { 142 $| = 1; 143 my $coolStackPkg = new CoolStackPkg($_buildDir, $_packagesDir, $_doSrcPackage); 144 if (! defined $_installDir) { 145 die "INSTALLDIR not defined\n"; 146 } 147 if (($_installDir eq "") || ($_installDir eq "/")) { 148 die "INSTALLDIR can't be blank or / \n"; 149 } 150 151 if ($_cleanupAtStart) { 152 if ($_installDir =~ m,^/\S+/,) { 153 system("rm -rf $_installDir/*"); 154 } 155 system("rm -f $_buildDir/*"); 156 } 157 createDirectories("./$_buildDir", "$_installDir", "$_installDir/include", 158 "$_installDir/lib", "$_installDir/share", 159 "$_installDir/bin", "$_installDir/info"); 160 if ($_doSrcPackage) { 161 $coolStackPkg->createSrcPackages($_srcPackagelocation); 162 } 163 164 if ($_rebuild) { 165 # Remove all done files. 166 system("rm -f ./$_buildDir/*.done"); 167 } 168 169 my @compList = ("imap-2006c1", 170 "libiconv-1.9.2", 171 "libxml2-2.6.27" 172 ); 173 foreach my $comp (@compList) { 174 compile($comp); 175 } 176 177 unless (-d "mysql_64-5.0.45") { 178 system("cp -rpf mysql-5.0.45 mysql_64-5.0.45"); 179 } 180 181 compile("mysql-5.0.45", SCRIPT => "./make_solaris_32bit.sh"); 182 183 @compList = ("curl-7.14.0", 184 "readline-5.2", 185 "gettext-0.16", 186 "ncurses-5.5", 187 "freetype-2.2.1", 188 "gd-2.0.33", 189 "gdbm-1.8.3", 190 "gmp-4.2.1", 191 "tidy", 192 "pcre-7.1" 193 ); 194 195 foreach my $comp (@compList) { 196 compile($comp); 197 } 198 199 @compList = ("unixODBC-2.2.12", 200 "freetds-0.64", 201 "cyrus-sasl-2.1.22", 202 "openldap-2.3.30" 203 ); 204 205 foreach my $comp (@compList) { 206 compile($comp); 207 } 208 209 @compList = ("httpd-2.2.6", "php-5.2.4"); 210 foreach my $comp (@compList) { 211 compile($comp); 212 } 213 214 compile("mod_fcgid.2.2"); 215 216 my @phpComp = ("APC-3.0.14", "suhosin-0.9.16", "dtrace-1.0.3"); 217 foreach my $comp (@phpComp) { 218 compile($comp); 219 } 220 221 ######################## 222 # Build for memcached 223 ######################## 224 compile("libevent-1.3d"); 225 compile("memcached-1.2.2"); 226 227 ######################## 228 # Build for ruby 229 ######################## 230 compile("ruby-1.8.6"); 231 compile("rubygems-0.9.0"); 232 compile("rails-1.2.3"); 233 234 ######################## 235 # Build for squid 236 ######################## 237 compile("squid-2.6.16"); 238 239 ######################## 240 # Build for mysql 64bit 241 ######################## 242 compile("mysql_64-5.0.45", SCRIPT=>"./make_solaris_64bit.sh"); 243 244 ######################## 245 # Build for perl. 246 ######################## 247 compile("perl-5.8.8"); 248 # compile perl modules 249 compile("mod_perl-2.0.2"); 250 compile("perl-5.8.8/ext-add", COMP_NAME => "perl-ext"); 251 252 # Compile lighttpd-1.4.18 253 compile("lighttpd-1.4.18"); 254 255 # Compile tomcat. It basically doesn't compile but install it. 256 compile("tomcat"); 257 258 # compile tomcat-connector (mod_jk) 259 compile("tomcat-connectors-1.2.25"); 260 261 $coolStackPkg->createPackages() if (!$_noExecute && $_doPackage); 262 } 263 264 sub help() 265 { 266 my $helpString = <<helpEnd 267 ./build_coolstack.sh [--exit-on-failure] [ --cleanup-at-start] 268 [--noexecute] [--rebuild|norebuild] [--help] 269 --exit-on-failure : Exit if any component fails to compile 270 --cleanup-at-start : Cleanup the INSTALLDIR (/opt/coolstack) before starting 271 --noexecute : Just do the dry run. Don't compile. 272 --[no]rebuild : Rebuild all components from scratch. Default is true. 273 274 helpEnd 275 ; 276 print "$helpString\n"; 277 exit(0); 278 } 279 280 GetOptions("package" => \$_doPackage, 281 "src-package" => \$_doSrcPackage, 282 "src-package-location=s" => \$_srcPackagelocation, 283 "exit-on-failure" => \$_exitOnFailure, 284 "cleanup-at-start" => \$_cleanupAtStart, 285 "noexecute" => \$_noExecute, 286 "rebuild!" => \$_rebuild, 287 "help|?" => \&help 288 ); 289 compile_coolstack(); 290