ProjectBuilder.st
author Claus Gittinger <cg@exept.de>
Fri, 20 Jul 2012 15:30:07 +0200
changeset 2895 2b939399b83b
parent 2873 bacaa7ec62b1
child 2896 6ed90332dbda
permissions -rw-r--r--
changed: #makeWithOutputTo:errorTo:
     1 "
     2  COPYRIGHT (c) 2009 by eXept Software AG
     3               All Rights Reserved
     4 
     5  This software is furnished under a license and may be used
     6  only in accordance with the terms of that license and with the
     7  inclusion of the above copyright notice.   This software may not
     8  be provided or otherwise made available to, or used by, any
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    11 "
    12 "{ Package: 'stx:libtool2' }"
    13 
    14 "{ NameSpace: Tools }"
    15 
    16 Object subclass:#ProjectBuilder
    17 	instanceVariableNames:'package projectDefinitionClass sourceCodeManager buildDirectory
    18 		myWorkingDirectory mySTXTopDirectory myTopDirectory outputStream
    19 		makeExeOnly usedCompiler'
    20 	classVariableNames:'PreviousBuildDirectory'
    21 	poolDictionaries:''
    22 	category:'System-Support-Projects'
    23 !
    24 
    25 !ProjectBuilder class methodsFor:'documentation'!
    26 
    27 copyright
    28 "
    29  COPYRIGHT (c) 2009 by eXept Software AG
    30               All Rights Reserved
    31 
    32  This software is furnished under a license and may be used
    33  only in accordance with the terms of that license and with the
    34  inclusion of the above copyright notice.   This software may not
    35  be provided or otherwise made available to, or used by, any
    36  other person.  No title to or ownership of the software is
    37  hereby transferred.
    38 "
    39 ! !
    40 
    41 !ProjectBuilder class methodsFor:'accessing'!
    42 
    43 previousBuildDirectory
    44     ^ PreviousBuildDirectory
    45 !
    46 
    47 previousBuildDirectory:something
    48     PreviousBuildDirectory := something.
    49 ! !
    50 
    51 !ProjectBuilder class methodsFor:'examples'!
    52 
    53 example1
    54     Smalltalk loadPackage:'stx:projects/helloWorldApp' asAutoloaded:true.
    55 
    56     self new
    57         package:'stx:projects/helloWorldApp';
    58         build
    59 !
    60 
    61 example2
    62     |builder|
    63 
    64     Smalltalk loadPackage:'stx:clients/Demos/foxCalcApplication' asAutoloaded:true.
    65 
    66     builder := self new.
    67     builder package:'stx:clients/Demos/foxCalcApplication'.
    68     builder build.
    69 
    70     UserPreferences fileBrowserClass openOnDirectory:builder packageBuildDirectory.
    71 ! !
    72 
    73 !ProjectBuilder class methodsFor:'queries'!
    74 
    75 defaultUsedCompiler
    76     |compiler|
    77 
    78     (compiler := UserPreferences current usedCompilerForBuild) notNil ifTrue:[
    79         ^ compiler
    80     ].
    81 
    82     OperatingSystem isMSWINDOWSlike ifTrue:[
    83         ^ 'bcc'
    84     ].
    85     ^ 'gcc'
    86 
    87     "Created: / 21-01-2012 / 14:06:51 / cg"
    88 !
    89 
    90 listOfPossibleCompilers
    91     OperatingSystem isMSWINDOWSlike ifTrue:[
    92         ^ #('bcc' 'vc' 'lcc' 'gcc' )
    93     ].
    94     ^ #('gcc')
    95 
    96     "Created: / 21-01-2012 / 14:04:15 / cg"
    97 ! !
    98 
    99 !ProjectBuilder methodsFor:'accessing'!
   100 
   101 buildDirectory
   102     ^ buildDirectory
   103 !
   104 
   105 buildDirectory:something
   106     buildDirectory := something.
   107 !
   108 
   109 makeExeOnly:aBoolean
   110     makeExeOnly := aBoolean.
   111 !
   112 
   113 package:aPackageIDOrSymbol
   114     package := aPackageIDOrSymbol asPackageId.
   115 !
   116 
   117 packageBuildDirectory
   118     "the directoray, where the deployable binary is created (xxxSetup.exe)"
   119 
   120     ^ buildDirectory / (package asPackageId module) / (package asPackageId directory)
   121 !
   122 
   123 projectDefinitionClass:something
   124     projectDefinitionClass := something.
   125 !
   126 
   127 suffixForHeaderFiles
   128     ^ OperatingSystem isUNIXlike ifTrue:['.H'] ifFalse:['.STH']
   129 !
   130 
   131 usedCompilerForBuild:something
   132     usedCompiler := something.
   133 
   134     "Created: / 22-01-2012 / 10:50:48 / cg"
   135 ! !
   136 
   137 !ProjectBuilder methodsFor:'building'!
   138 
   139 build
   140     "/ intermediate - this will move into a commonly used utility class
   141     "/ (where all the project code support will be collected).
   142 
   143     |makeOutput|
   144 
   145     makeOutput := TextStream on:(Text new:10000).
   146     self buildWithColorizedOutputTo:makeOutput.
   147 
   148     TextView openWith:makeOutput contents.
   149 !
   150 
   151 buildWithColorizedOutputTo:makeOutput
   152     "/ intermediate - this will move into a commonly used utility class
   153     "/ (where all the project code support will be collected).
   154 
   155     |stdOut stdErr lock|
   156 
   157     lock := Semaphore forMutualExclusion.
   158 
   159     stdErr := ActorStream new
   160                     nextPutBlock:[:char |
   161                         lock critical:[
   162                             makeOutput emphasis:{#backgroundColor->Color red. #color->Color white.}.
   163                             makeOutput nextPut:char.
   164                             makeOutput emphasis:nil.
   165                         ]
   166                     ];
   167                     nextPutAllBlock:[:string |
   168                         lock critical:[          
   169                             "/ (string includesString:'das Ziel' )ifTrue:[self halt].
   170                             makeOutput emphasis:{#backgroundColor->Color red. #color->Color white.}.
   171                             makeOutput nextPutAll:string.
   172                             makeOutput emphasis:nil.
   173                         ]
   174                     ].
   175     stdOut := ActorStream new
   176                     nextPutBlock:[:char |
   177                         lock critical:[
   178                             makeOutput nextPut:char.
   179                         ]
   180                     ];
   181                     nextPutAllBlock:[:string |
   182                         lock critical:[         
   183                             "/ (string includesString:'das Ziel' )ifTrue:[self halt].
   184                             makeOutput nextPutAll:string.
   185                         ]
   186                     ].
   187 
   188     self buildWithOutputTo:stdOut errorTo:stdErr.
   189 
   190     "Modified: / 21-01-2012 / 13:49:13 / cg"
   191 !
   192 
   193 buildWithOutputTo:stdOut errorTo:stdErr
   194     "/ intermediate - this will move into a commonly used utility class
   195     "/ (where all the project code support will be collected).
   196 
   197     |module directory|
   198 
   199     projectDefinitionClass := ProjectDefinition definitionClassForPackage:package.
   200     projectDefinitionClass isNil ifTrue:[
   201         self error:('Missing ProjectDefinition class for "',package asString,'"')
   202     ].
   203 
   204     "/ ensure that everything is loaded...
   205     projectDefinitionClass loadAsAutoloaded:false.
   206     projectDefinitionClass loadExtensions.
   207     projectDefinitionClass loadAllClassesAsAutoloaded:false.
   208 
   209     module := package module.
   210     directory := package directory.
   211 
   212     buildDirectory isNil ifTrue:[
   213         buildDirectory := PreviousBuildDirectory ifNil:[ UserPreferences current buildDirectory ].
   214         buildDirectory isNil ifTrue:[
   215             buildDirectory := Filename tempDirectory construct:'stx_build'.
   216         ].
   217     ].
   218     buildDirectory := buildDirectory asFilename.
   219 
   220     "/ self validateBuildDirectoryIsPresent.
   221 
   222     PreviousBuildDirectory := buildDirectory.
   223 
   224     "/ UserPreferences current localBuild:true
   225     UserPreferences current localBuild ifFalse:[
   226         SourceCodeManager notNil ifTrue:[
   227             sourceCodeManager := SourceCodeManagerUtilities default sourceCodeManagerFor:projectDefinitionClass.
   228         ]
   229     ].
   230     sourceCodeManager := nil.
   231 
   232     myTopDirectory := 
   233         Smalltalk packagePath 
   234             detect:[:aPath |
   235                 (aPath asFilename / 'stx' / 'include') exists
   236                 and: [ (aPath asFilename / 'stx' / 'rules') exists ]]
   237             ifNone:nil.       
   238     myTopDirectory isNil ifTrue:[
   239         self error:('Cannot figure out my top directory (where stx/include and stx/rules are)')
   240     ].
   241     myTopDirectory := myTopDirectory asFilename.
   242     mySTXTopDirectory := myTopDirectory / 'stx'.
   243 
   244     self setupBuildDirectory.
   245     self activityNotification:'Generating stc directory...'.
   246     self copySTCDirectoryForBuild.
   247     self activityNotification:'Generating source files...'.
   248     self generateSourceFiles.
   249     self activityNotification:'Copying dlls for linkage...'.
   250     self copyDLLsForLinkage.
   251     self activityNotification:'Copying support files for linkage...'.
   252     self copySupportFilesForLinkage.
   253     self copyStartupFilesFromSmalltalk.
   254 
   255     self activityNotification:'Executing make...'.
   256     self makeWithOutputTo:stdOut errorTo:stdErr.
   257 !
   258 
   259 copyDLLsForLinkage
   260     |targetBuildDir preRequisites dllRelativePaths|
   261 
   262 
   263     targetBuildDir := buildDirectory / package module / package directory.
   264 
   265     preRequisites := projectDefinitionClass allPreRequisites.
   266     OperatingSystem isUNIXlike ifTrue:[
   267         "For now: unix Makefiles require some libs implicitely..."
   268         preRequisites := preRequisites union:#(
   269                                'stx:goodies/refactoryBrowser/parser'
   270                                'stx:libtool'
   271                             ).
   272     ].
   273 
   274     preRequisites do:[:eachPackageToFileout |
   275         |packageId packageDef packageModule packageDirectory packageTargetDir
   276          dllSource dllSourceDir libraryName dllRelativePath|
   277 
   278         packageId := eachPackageToFileout asPackageId.
   279         packageModule := packageId module.
   280         packageDirectory := packageId directory.
   281         packageTargetDir := (buildDirectory / packageModule / packageDirectory) recursiveMakeDirectory.
   282 
   283         packageDef := packageId projectDefinitionClass.
   284         libraryName := packageDef libraryName.
   285 
   286         "/ mhmh - take them from my tree or from the projects/smalltalk execution directory ??
   287         dllSourceDir := myTopDirectory / packageModule / packageDirectory.
   288         OperatingSystem isMSWINDOWSlike ifTrue:[
   289 "/            dllRelativePath := 'objvc','/',(libraryName,'.dll').
   290 "/            (dllSourceDir / dllRelativePath) exists 
   291             dllRelativePaths := Array with:('objbc\', libraryName, '.dll').
   292         ] ifFalse:[
   293             dllRelativePaths := Array with:(libraryName,'.so').
   294             (packageModule = 'stx' and:[packageDirectory = 'libview']) ifTrue:[
   295                 dllRelativePaths := dllRelativePaths, #('XWorkstation.so' 'GLXWorkstation.so').
   296             ].
   297         ].
   298         dllRelativePaths do:[:dllRelativePath|
   299             ((packageTargetDir / dllRelativePath) exists not
   300              or:[(dllSourceDir / dllRelativePath) fileSize ~= (packageTargetDir / dllRelativePath) fileSize
   301              or:[(dllSourceDir / dllRelativePath) modificationTime >= (packageTargetDir / dllRelativePath) modificationTime
   302              "/ or:[ ((dllSourceDir / dllRelativePath) sameContentsAs:(packageTargetDir / dllRelativePath)) not ]
   303             ]]) ifTrue:[
   304                 (packageTargetDir / dllRelativePath) directory recursiveMakeDirectory.
   305                 (dllSourceDir / dllRelativePath) copyTo:(packageTargetDir / dllRelativePath).    
   306             ].
   307         ].
   308     ].
   309 !
   310 
   311 copyDirectory:relativepath
   312     "/ need rules in stx
   313     ((Smalltalk projectDirectoryForPackage:'stx') asFilename construct:relativepath)
   314         recursiveCopyTo:(buildDirectory construct:'stx').
   315 !
   316 
   317 copyDirectoryForBuild:subdir
   318     |targetDir targetFile|
   319 
   320     targetDir := buildDirectory / 'stx' / subdir.
   321     targetDir exists ifFalse:[
   322         targetDir makeDirectory.
   323     ].
   324     (mySTXTopDirectory / subdir) directoryContentsAsFilenamesDo:[:eachFile |
   325         eachFile isDirectory ifFalse:[
   326             targetFile := targetDir / eachFile baseName.
   327             (targetFile exists not
   328             or:[ targetFile modificationTime < eachFile modificationTime ]) ifTrue:[
   329                 self activityNotification:'copying ',eachFile pathName,'...'.
   330                 eachFile copyTo:(targetDir construct:eachFile baseName)
   331             ]
   332         ].
   333     ].
   334     self activityNotification:nil
   335 !
   336 
   337 copyResourcesForPackage:aPackage
   338     |module directory|
   339 
   340     module := aPackage asPackageId module.
   341     directory := aPackage asPackageId directory.
   342 
   343     (myTopDirectory / module / directory / 'resources' ) exists ifTrue:[
   344         (myTopDirectory / module / directory / 'resources' )
   345             recursiveCopyTo:(buildDirectory / module / directory)
   346     ].
   347     (myTopDirectory / module / directory / 'styles' ) exists ifTrue:[
   348         (myTopDirectory / module / directory / 'styles' )
   349             recursiveCopyTo:(buildDirectory / module / directory)
   350     ].
   351 !
   352 
   353 copySTCDirectoryForBuild
   354     |targetDir stc files|
   355 
   356     targetDir := buildDirectory / 'stx' / 'stc'.
   357     targetDir exists ifFalse:[ targetDir makeDirectory ].
   358 
   359     stc := OperatingSystem isMSWINDOWSlike 
   360                 ifTrue:[ 'stc.exe' ]
   361                 ifFalse:[ 'stc' ].
   362 
   363     files := #( ) copyWith:stc.
   364 
   365     files do:[:eachFile |
   366         |sourceFile targetFile|
   367 
   368         sourceFile := mySTXTopDirectory / 'stc' / eachFile.
   369         targetFile := targetDir / eachFile.
   370         (targetFile exists not
   371         or:[ targetFile modificationTime < sourceFile modificationTime ]) ifTrue:[
   372             self activityNotification:'copying ',sourceFile pathName,'...'.
   373             sourceFile copyTo:targetFile
   374         ].
   375     ].
   376 
   377     OperatingSystem isUNIXlike ifTrue:[
   378         (targetDir / 'stc') makeExecutableForAll    
   379     ].
   380 
   381     self activityNotification:nil
   382 !
   383 
   384 copyStartupFilesFromSmalltalk
   385     (buildDirectory / 'stx' / 'projects/smalltalk' ) exists ifFalse:[
   386         (buildDirectory / 'stx' / 'projects/smalltalk' ) recursiveMakeDirectory.
   387     ].
   388 
   389     #( 
   390         'keyboard.rc' 
   391         'keyboardMacros.rc' 
   392         'display.rc' 
   393         'd_win32.rc'
   394         'host.rc' 
   395         'h_win32.rc'  
   396         'smalltalk.rc'  
   397         'private.rc'  
   398     ) do:[:fn |
   399         (myTopDirectory / 'stx' / 'projects/smalltalk' / fn)
   400             copyTo: (buildDirectory / 'stx' / 'projects/smalltalk' / fn)
   401     ].
   402 
   403     (myTopDirectory / 'stx' / 'doc/online/english/LICENCE_STX.html')
   404             copyTo: (buildDirectory / 'stx' / 'projects/smalltalk' / 'LICENCE_STX.html').
   405 !
   406 
   407 copySupportFilesForLinkage
   408     |files|
   409 
   410     OperatingSystem isMSWINDOWSlike ifTrue:[
   411         files := #( 
   412                     'support/win32/borland/cs3245.dll' 
   413                     'support/win32/X11.dll'
   414                     'support/win32/Xext.dll'
   415                     'librun/objbc/librun.dll'
   416                     'libbc/librun.lib'
   417                     'libbc/cs32i.lib'
   418                     'librun/genDate.exe'
   419                     'librun/main.c'
   420                     'projects/smalltalk/stx_16x16.ico'
   421                     'projects/smalltalk/stx_32x32.ico'
   422                     'projects/smalltalk/stx_splash.bmp'
   423                  ).
   424     ] ifFalse:[
   425         files := #(
   426                     'librun/main.c'
   427                     'librun/librun.so'
   428                 )
   429     ].
   430     files := files asOrderedCollection.
   431 
   432     OperatingSystem isMSWINDOWSlike ifTrue:[
   433         projectDefinitionClass applicationIconFileName notNil ifTrue:[
   434             files add:('projects/smalltalk/',projectDefinitionClass applicationIconFileName,'.ico')
   435         ].
   436         projectDefinitionClass splashFileName notNil ifTrue:[
   437             files add:('projects/smalltalk/',projectDefinitionClass splashFileName,'.bmp')
   438         ].
   439     ].
   440 
   441     files do:[:dllRelativePath |
   442         (mySTXTopDirectory / dllRelativePath) exists ifTrue:[
   443             ((buildDirectory / 'stx' / dllRelativePath) exists
   444             and:[ (mySTXTopDirectory / dllRelativePath) fileSize = (buildDirectory / 'stx' / dllRelativePath) fileSize
   445             and:[ (mySTXTopDirectory / dllRelativePath) modificationTime < (buildDirectory / 'stx' / dllRelativePath) modificationTime
   446             "/ and:[ (mySTXTopDirectory / dllRelativePath) sameContentsAs:(targetBuildDir / dllRelativePath) ]
   447             ]]) ifFalse:[
   448                 (buildDirectory / 'stx' / dllRelativePath) directory recursiveMakeDirectory.
   449                 (mySTXTopDirectory / dllRelativePath) copyTo:(buildDirectory / 'stx' / dllRelativePath).    
   450             ]
   451         ] ifFalse:[
   452             self error:'Missing file: ',dllRelativePath printString mayProceed:true.
   453         ].
   454     ].
   455 
   456     "Modified: / 21-01-2012 / 13:40:56 / cg"
   457 !
   458 
   459 createHeaderFileFor:aClass in:packageTargetDir
   460     |instVarList classInstVarList classVarList bindings superclassFilename
   461      template file newContents oldContents|
   462 
   463     instVarList := StringCollection new.
   464     aClass instVarNames do:[:v |
   465         instVarList add:('OBJ %1;' bindWith:v)
   466     ].
   467     classInstVarList := StringCollection new.
   468     aClass class instVarNames do:[:v |
   469 (v includes:$_) ifTrue:[self halt].
   470         classInstVarList add:('OBJ %1;' bindWith:v)
   471     ].
   472     classVarList := StringCollection new.
   473     aClass classVarNames do:[:v |
   474         classVarList add:('extern OBJ %1_%2;' bindWith:aClass name with:v)
   475     ].
   476 
   477     bindings := Dictionary new.
   478     bindings at:'ClassName' put:aClass name. 
   479     aClass superclass isNil ifTrue:[
   480         bindings at:'SuperclassName' put:'-'. 
   481         bindings at:'SuperclassFileInclude' put:''.
   482     ] ifFalse:[
   483         bindings at:'SuperclassName' put:aClass superclass name. 
   484         bindings at:'SuperclassFileName' put:(superclassFilename := Smalltalk fileNameForClass:aClass superclass).
   485         bindings at:'SuperclassFileInclude' put:('#include "%1.STH"' bindWith:superclassFilename).
   486     ].
   487     bindings at:'InstVarList' put:instVarList asString. 
   488     bindings at:'ClassVarList' put:classVarList asString. 
   489     bindings at:'ClassInstVarList' put:classInstVarList asString. 
   490 
   491     template := 
   492 '/* This file was generated by ProjectBuilder. */
   493 /* !!!!!!!! Do not change by hand !!!!!!!! */
   494 
   495 /* Class: %(ClassName) */
   496 /* Superclass: %(SuperclassName) */
   497 
   498 %(SuperclassFileInclude)
   499 
   500 /* INDIRECTGLOBALS */
   501 #ifdef _HEADER_INST_
   502 %(InstVarList)
   503 #endif /* _HEADER_INST_ */
   504 
   505 #ifdef _HEADER_CLASS_
   506 %(ClassVarList)
   507 #endif /* _HEADER_CLASS_ */
   508 
   509 #ifdef _HEADER_CLASSINST_
   510 %(ClassInstVarList)
   511 #endif /* _HEADER_CLASSINST_ */
   512 '.
   513     newContents := template bindWithArguments:bindings.
   514     file := packageTargetDir asFilename / ((Smalltalk fileNameForClass:aClass),(self suffixForHeaderFiles)).
   515     (file exists not
   516     or:[ (oldContents := file contents) ~= newContents ]) ifTrue:[
   517         file contents: newContents.
   518     ].
   519 
   520     "Modified: / 15-08-2011 / 14:58:46 / cg"
   521 !
   522 
   523 generateSourceFiles
   524     sourceCodeManager notNil ifTrue:[
   525         "/ check out / generate files there
   526         self generateSourceFilesByCheckingOutUsing:sourceCodeManager
   527     ] ifFalse:[
   528         "/ local build
   529         "/ fileout the project
   530         self generateSourceFilesByFilingOut
   531     ]
   532 !
   533 
   534 generateSourceFilesByCheckingOutUsing:aSourceCodeManager
   535     "/ will no longer be needed/supported
   536 
   537     |repository stxRepository module directory|
   538 
   539     self breakPoint:#cg.
   540 
   541     "/ check out / generate files there
   542     repository := (aSourceCodeManager repositoryNameForModule:module) ifNil:[aSourceCodeManager repositoryName].
   543     stxRepository := aSourceCodeManager repositoryName.
   544 
   545     (buildDirectory construct:'stx') exists ifFalse:[
   546         (module ~= 'stx') ifTrue:[
   547             OperatingSystem
   548                 executeCommand:('cvs -d ',stxRepository,' co stx')
   549                 inputFrom:nil
   550                 outputTo:Transcript
   551                 errorTo:Transcript
   552                 inDirectory:buildDirectory
   553                 onError:[:status| self error:'cvs update stx failed'].
   554         ].
   555     ].
   556 
   557     ((buildDirectory construct:module) construct:'CVS') exists ifFalse:[
   558         OperatingSystem
   559             executeCommand:('cvs -d ',repository,' co -l ',directory)
   560             inputFrom:nil
   561             outputTo:Transcript
   562             errorTo:Transcript
   563             inDirectory:buildDirectory
   564             onError:[:status| self error:'cvs update failed'].
   565     ].
   566     OperatingSystem
   567         executeCommand:'cvs upd -d'
   568         inputFrom:nil
   569         outputTo:Transcript
   570         errorTo:Transcript
   571         inDirectory:(buildDirectory construct:module)
   572         onError:[:status| self error:'cvs update failed'].
   573 self halt.
   574 
   575     "Modified: / 29-12-2011 / 14:02:56 / cg"
   576 !
   577 
   578 generateSourceFilesByFilingOut
   579     "/ local build
   580     "/ fileout the project
   581 
   582     |fullPathName|
   583 
   584     (package module ~= 'stx') ifTrue:[
   585         (buildDirectory / package module) makeDirectory.
   586     ].
   587 
   588     "/ file out the package(s) which are to be built
   589     ((Array with:package))
   590     do:[:eachPackageToFileout |
   591         |packageId packageModule packageDirectory packageTargetDir packageDef|
   592 
   593         packageId := eachPackageToFileout asPackageId.
   594         packageModule := packageId module.
   595         packageDirectory := packageId directory.
   596         packageTargetDir := (buildDirectory / packageModule / packageDirectory) recursiveMakeDirectory.
   597 
   598         packageDef := packageId projectDefinitionClass.
   599         (packageDef compiled_classNames_common ,
   600         packageDef compiled_classNamesForPlatform) do:[:eachClassName |
   601             |cls fileName newSource|
   602 
   603             cls := Smalltalk classNamed:eachClassName.
   604             self assert:cls isLoaded.
   605             fileName := (Smalltalk fileNameForClass:cls),'.st'.
   606             fileName := packageTargetDir asFilename construct:fileName.
   607             fileName exists ifTrue:[
   608                 newSource := String streamContents:[:s | cls fileOutOn:s withTimeStamp:false].
   609                 newSource = fileName contentsAsString ifFalse:[
   610                     fileName contents:newSource
   611                 ].
   612             ] ifFalse:[
   613                 cls fileOutIn:packageTargetDir withTimeStamp:false
   614             ].
   615         ].
   616 
   617 "/        (Smalltalk allClassesInPackage:eachPackageToFileout) do:[:cls |
   618 "/            cls isPrivate ifFalse:[
   619 "/                cls isLoaded ifFalse:[
   620 "/                    self halt.
   621 "/                    cls autoload.
   622 "/                ].
   623 "/                cls fileOutIn:packageTargetDir
   624 "/            ]
   625 "/        ].
   626 
   627         projectDefinitionClass forEachFileNameAndGeneratedContentsDo:[:fileName :fileContents |
   628             fullPathName := packageTargetDir construct:fileName.
   629             fullPathName directory exists ifFalse:[
   630                 "take care for files like 'autopackage/default.apspec'"
   631                 fullPathName directory makeDirectory.
   632             ].
   633             (fullPathName exists
   634              and:[ fullPathName contents = fileContents ]) ifFalse:[
   635                 fullPathName contents:fileContents.
   636             ].
   637         ].    
   638     ].
   639 
   640     "/ generate header files in prerequisite packages...
   641     (projectDefinitionClass allPreRequisites)
   642     do:[:eachPackageToFileout |
   643         |packageId packageDef packageModule packageDirectory packageTargetDir|
   644 
   645         packageId := eachPackageToFileout asPackageId.
   646         packageModule := packageId module.
   647         packageDirectory := packageId directory.
   648         packageTargetDir := (buildDirectory / packageModule / packageDirectory) recursiveMakeDirectory.
   649 
   650         packageDef := packageId projectDefinitionClass.
   651         (packageDef compiled_classNames_common ,
   652         packageDef compiled_classNamesForPlatform) do:[:eachClassName |
   653             |cls|
   654 
   655             cls := Smalltalk classNamed:eachClassName.
   656             "/ self assert:cls isLoaded.
   657             cls isLoaded ifTrue:[    
   658                 self createHeaderFileFor:cls in:packageTargetDir
   659             ].
   660         ].
   661         self copyResourcesForPackage:eachPackageToFileout.
   662     ].
   663 
   664 "/    stx_libbasic2 preRequisitesForBuilding#(#'stx:libbasic')
   665 !
   666 
   667 makeWithOutputTo:stdOut errorTo:stdErr
   668     |module directory compilerFlag makeCommand|
   669 
   670     module := package module.
   671     directory := package directory.
   672 
   673     makeCommand := ParserFlags makeCommand.
   674     usedCompiler isNil ifTrue:[
   675         usedCompiler := ParserFlags usedCompiler.
   676     ].
   677     usedCompiler = 'vc' ifTrue:[ 
   678         makeCommand := 'vcmake'. "/ compilerFlag := '-DUSEVC' 
   679     ] ifFalse:[
   680         usedCompiler = 'lcc' ifTrue:[ 
   681             makeCommand := 'lcmake'. "/ compilerFlag := '-DUSELCC' 
   682         ] ifFalse:[
   683             usedCompiler = 'gcc' ifTrue:[ 
   684                 makeCommand := 'make'. 
   685             ] ifFalse:[
   686                 usedCompiler = 'bcc' ifTrue:[ 
   687                     makeCommand := 'bmake'.
   688                 ] ifFalse:[
   689                     self error:'no compiler specified'.
   690                 ]
   691             ]
   692         ]
   693     ].
   694 
   695     "/ makeCommand := makeCommand, ' TOP=', mySTXTopDirectory pathName.
   696 
   697     OperatingSystem isUNIXlike ifTrue:[
   698         OperatingSystem
   699             executeCommand:('sh %1/rules/stmkmf' bindWith:mySTXTopDirectory pathName)
   700             inputFrom:nil
   701             outputTo:stdOut
   702             errorTo:stdErr
   703             inDirectory:(buildDirectory / module / directory)
   704             onError:[:status| self error:'make failed'].
   705     ].
   706 
   707     projectDefinitionClass isLibraryDefinition ifTrue:[
   708         OperatingSystem
   709             executeCommand:(makeCommand,' classLibRule')
   710             inputFrom:nil
   711             outputTo:stdOut
   712             errorTo:stdErr
   713             inDirectory:(buildDirectory / module / directory)
   714             onError:[:status| self error:'make failed'].
   715     ] ifFalse:[
   716         OperatingSystem
   717             executeCommand:(makeCommand,' exe')
   718             inputFrom:nil
   719             outputTo:stdOut
   720             errorTo:stdErr
   721             inDirectory:(buildDirectory / module / directory)
   722             onError:[:status| self error:'make failed'].
   723 
   724         (makeExeOnly ? false) ifFalse:[
   725             OperatingSystem
   726                 executeCommand:(makeCommand,' setup')
   727                 inputFrom:nil
   728                 outputTo:stdOut
   729                 errorTo:stdErr
   730                 inDirectory:(buildDirectory / module / directory)
   731                 onError:[:status| self error:'make failed'].
   732         ]
   733     ]
   734 
   735     "Modified: / 20-07-2012 / 12:13:29 / cg"
   736 !
   737 
   738 recursiveCopyDirectoryForBuild:subdir
   739     |targetDir|
   740 
   741     targetDir := buildDirectory / 'stx' / subdir.
   742     targetDir exists ifFalse:[
   743         targetDir makeDirectory.
   744     ].
   745     (mySTXTopDirectory / subdir) directoryContentsAsFilenamesDo:[:eachFile |
   746         eachFile recursiveCopyTo:(targetDir construct:eachFile baseName)
   747     ].
   748     self activityNotification:nil
   749 !
   750 
   751 setupBuildDirectory
   752     buildDirectory exists ifFalse:[
   753         buildDirectory recursiveMakeDirectory.
   754     ].
   755     (buildDirectory / 'stx') exists ifFalse:[
   756         (buildDirectory / 'stx') makeDirectory.
   757     ].
   758 
   759     self copyDirectoryForBuild:'include'.
   760     self copyDirectoryForBuild:'rules'.
   761     OperatingSystem isUNIXlike ifTrue:[
   762         self recursiveCopyDirectoryForBuild:'configurations'.
   763     ]
   764 !
   765 
   766 validateBuildDirectoryIsPresent
   767 
   768     ^ self.
   769 
   770 "/    [
   771 "/        |default directoryIsOKForMe stc |
   772 "/
   773 "/        default := (buildDirectory ?
   774 "/                          PreviousBuildDirectory)
   775 "/                          ifNil:[ UserPreferences current buildDirectory].
   776 "/
   777 "/        buildDirectory := Dialog requestDirectoryName:'Temporary Work-ROOT for build:'
   778 "/                                 default:default.
   779 "/
   780 "/        buildDirectory isEmptyOrNil ifTrue:[^ self].
   781 "/        buildDirectory := buildDirectory asFilename.
   782 "/        directoryIsOKForMe := true.
   783 "/
   784 "/        buildDirectory exists ifFalse:[
   785 "/            Dialog warn:(self classResources string:'Work directory %1 does not exist.' with:buildDirectory).
   786 "/            directoryIsOKForMe := false.
   787 "/        ] ifTrue:[
   788 "/            (buildDirectory construct:'stx') exists ifFalse:[
   789 "/                Dialog warn:(self classResources stringWithCRs:'Work directory must contain an stx subDirectory,\which contains (at least) the stc and include subdirectories.').
   790 "/                directoryIsOKForMe := false.
   791 "/            ] ifTrue:[
   792 "/                stc := (OperatingSystem isMSDOSlike) ifTrue:['stc.exe'] ifFalse:['stc'].
   793 "/                (((buildDirectory construct:'stx')construct:'stc')construct:stc) exists ifFalse:[
   794 "/                    Dialog warn:(self classResources stringWithCRs:'Work directory must contain an stc compiler in the stx/stc subDirectory.').
   795 "/                    directoryIsOKForMe := false.
   796 "/                ].
   797 "/                ((buildDirectory construct:'stx')construct:'include') exists ifFalse:[
   798 "/                    Dialog warn:(self classResources stringWithCRs:'Work directory must have had a make run before (for include files to exists).').
   799 "/                    directoryIsOKForMe := false.
   800 "/                ].
   801 "/            ]
   802 "/        ].
   803 "/        directoryIsOKForMe
   804 "/    ] whileFalse
   805 ! !
   806 
   807 !ProjectBuilder class methodsFor:'documentation'!
   808 
   809 version_CVS
   810     ^ '$Header$'
   811 ! !