ProjectBuilder.st
author Claus Gittinger <cg@exept.de>
Sat, 21 Jul 2012 18:58:03 +0200
changeset 2898 c7f6c498df6a
parent 2896 6ed90332dbda
child 2905 d02db91a0938
permissions -rw-r--r--
category of:15 methods
     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 !ProjectBuilder methodsFor:'building/private'!
   260 
   261 copyDLLsForLinkage
   262     |targetBuildDir preRequisites dllRelativePaths|
   263 
   264 
   265     targetBuildDir := buildDirectory / package module / package directory.
   266 
   267     preRequisites := projectDefinitionClass allPreRequisites.
   268     OperatingSystem isUNIXlike ifTrue:[
   269         "For now: unix Makefiles require some libs implicitely..."
   270         preRequisites := preRequisites union:#(
   271                                'stx:goodies/refactoryBrowser/parser'
   272                                'stx:libtool'
   273                             ).
   274     ].
   275 
   276     preRequisites do:[:eachPackageToFileout |
   277         |packageId packageDef packageModule packageDirectory packageTargetDir
   278          dllSource dllSourceDir libraryName dllRelativePath|
   279 
   280         packageId := eachPackageToFileout asPackageId.
   281         packageModule := packageId module.
   282         packageDirectory := packageId directory.
   283         packageTargetDir := (buildDirectory / packageModule / packageDirectory) recursiveMakeDirectory.
   284 
   285         packageDef := packageId projectDefinitionClass.
   286         libraryName := packageDef libraryName.
   287 
   288         "/ mhmh - take them from my tree or from the projects/smalltalk execution directory ??
   289         dllSourceDir := myTopDirectory / packageModule / packageDirectory.
   290         OperatingSystem isMSWINDOWSlike ifTrue:[
   291 "/            dllRelativePath := 'objvc','/',(libraryName,'.dll').
   292 "/            (dllSourceDir / dllRelativePath) exists 
   293             dllRelativePaths := Array with:('objbc\', libraryName, '.dll').
   294         ] ifFalse:[
   295             dllRelativePaths := Array with:(libraryName,'.so').
   296             (packageModule = 'stx' and:[packageDirectory = 'libview']) ifTrue:[
   297                 dllRelativePaths := dllRelativePaths, #('XWorkstation.so' 'GLXWorkstation.so').
   298             ].
   299         ].
   300         dllRelativePaths do:[:dllRelativePath|
   301             |source dest|
   302 
   303             source := dllSourceDir / dllRelativePath.
   304             dest := packageTargetDir / dllRelativePath.
   305             (dest exists not
   306              or:[source fileSize ~= dest fileSize
   307              or:[source modificationTime >= dest modificationTime
   308              "/ or:[ ((dllSourceDir / dllRelativePath) sameContentsAs:(packageTargetDir / dllRelativePath)) not ]
   309             ]]) ifTrue:[
   310                 Transcript showCR:'updating ',dllRelativePath.
   311                 dest directory recursiveMakeDirectory.
   312                 source copyTo:dest.    
   313             ].
   314         ].
   315     ].
   316 
   317     "Modified: / 20-07-2012 / 18:30:06 / cg"
   318 !
   319 
   320 copyDirectory:relativepath
   321     "/ need rules in stx
   322     ((Smalltalk projectDirectoryForPackage:'stx') asFilename construct:relativepath)
   323         recursiveCopyTo:(buildDirectory construct:'stx').
   324 !
   325 
   326 copyDirectoryForBuild:subdir
   327     |targetDir targetFile|
   328 
   329     targetDir := buildDirectory / 'stx' / subdir.
   330     targetDir exists ifFalse:[
   331         targetDir makeDirectory.
   332     ].
   333     (mySTXTopDirectory / subdir) directoryContentsAsFilenamesDo:[:eachFile |
   334         eachFile isDirectory ifFalse:[
   335             targetFile := targetDir / eachFile baseName.
   336             (targetFile exists not
   337             or:[ targetFile modificationTime < eachFile modificationTime ]) ifTrue:[
   338                 self activityNotification:'copying ',eachFile pathName,'...'.
   339                 eachFile copyTo:(targetDir construct:eachFile baseName)
   340             ]
   341         ].
   342     ].
   343     self activityNotification:nil
   344 !
   345 
   346 copyResourcesForPackage:aPackage
   347     |module directory|
   348 
   349     module := aPackage asPackageId module.
   350     directory := aPackage asPackageId directory.
   351 
   352     (myTopDirectory / module / directory / 'resources' ) exists ifTrue:[
   353         (myTopDirectory / module / directory / 'resources' )
   354             recursiveCopyTo:(buildDirectory / module / directory)
   355     ].
   356     (myTopDirectory / module / directory / 'styles' ) exists ifTrue:[
   357         (myTopDirectory / module / directory / 'styles' )
   358             recursiveCopyTo:(buildDirectory / module / directory)
   359     ].
   360 !
   361 
   362 copySTCDirectoryForBuild
   363     |targetDir stc files|
   364 
   365     targetDir := buildDirectory / 'stx' / 'stc'.
   366     targetDir exists ifFalse:[ targetDir makeDirectory ].
   367 
   368     stc := OperatingSystem isMSWINDOWSlike 
   369                 ifTrue:[ 'stc.exe' ]
   370                 ifFalse:[ 'stc' ].
   371 
   372     files := #( ) copyWith:stc.
   373 
   374     files do:[:eachFile |
   375         |sourceFile targetFile|
   376 
   377         sourceFile := mySTXTopDirectory / 'stc' / eachFile.
   378         targetFile := targetDir / eachFile.
   379         (targetFile exists not
   380         or:[ targetFile modificationTime < sourceFile modificationTime ]) ifTrue:[
   381             self activityNotification:'copying ',sourceFile pathName,'...'.
   382             sourceFile copyTo:targetFile
   383         ].
   384     ].
   385 
   386     OperatingSystem isUNIXlike ifTrue:[
   387         (targetDir / 'stc') makeExecutableForAll    
   388     ].
   389 
   390     self activityNotification:nil
   391 !
   392 
   393 copyStartupFilesFromSmalltalk
   394     (buildDirectory / 'stx' / 'projects/smalltalk' ) exists ifFalse:[
   395         (buildDirectory / 'stx' / 'projects/smalltalk' ) recursiveMakeDirectory.
   396     ].
   397 
   398     #( 
   399         'keyboard.rc' 
   400         'keyboardMacros.rc' 
   401         'display.rc' 
   402         'd_win32.rc'
   403         'host.rc' 
   404         'h_win32.rc'  
   405         'smalltalk.rc'  
   406         'private.rc'  
   407     ) do:[:fn |
   408         (myTopDirectory / 'stx' / 'projects/smalltalk' / fn)
   409             copyTo: (buildDirectory / 'stx' / 'projects/smalltalk' / fn)
   410     ].
   411 
   412     (myTopDirectory / 'stx' / 'doc/online/english/LICENCE_STX.html')
   413             copyTo: (buildDirectory / 'stx' / 'projects/smalltalk' / 'LICENCE_STX.html').
   414 !
   415 
   416 copySupportFilesForLinkage
   417     |files|
   418 
   419     OperatingSystem isMSWINDOWSlike ifTrue:[
   420         files := #( 
   421                     'support/win32/borland/cs3245.dll' 
   422                     'support/win32/X11.dll'
   423                     'support/win32/Xext.dll'
   424                     'librun/objbc/librun.dll'
   425                     'libbc/librun.lib'
   426                     'libbc/cs32i.lib'
   427                     'librun/genDate.exe'
   428                     'librun/main.c'
   429                     'projects/smalltalk/stx_16x16.ico'
   430                     'projects/smalltalk/stx_32x32.ico'
   431                     'projects/smalltalk/stx_splash.bmp'
   432                  ).
   433     ] ifFalse:[
   434         files := #(
   435                     'librun/main.c'
   436                     'librun/librun.so'
   437                 )
   438     ].
   439     files := files asOrderedCollection.
   440 
   441     OperatingSystem isMSWINDOWSlike ifTrue:[
   442         projectDefinitionClass applicationIconFileName notNil ifTrue:[
   443             files add:('projects/smalltalk/',projectDefinitionClass applicationIconFileName,'.ico')
   444         ].
   445         projectDefinitionClass splashFileName notNil ifTrue:[
   446             files add:('projects/smalltalk/',projectDefinitionClass splashFileName,'.bmp')
   447         ].
   448     ].
   449 
   450     files do:[:dllRelativePath |
   451         (mySTXTopDirectory / dllRelativePath) exists ifTrue:[
   452             ((buildDirectory / 'stx' / dllRelativePath) exists
   453             and:[ (mySTXTopDirectory / dllRelativePath) fileSize = (buildDirectory / 'stx' / dllRelativePath) fileSize
   454             and:[ (mySTXTopDirectory / dllRelativePath) modificationTime < (buildDirectory / 'stx' / dllRelativePath) modificationTime
   455             "/ and:[ (mySTXTopDirectory / dllRelativePath) sameContentsAs:(targetBuildDir / dllRelativePath) ]
   456             ]]) ifFalse:[
   457                 (buildDirectory / 'stx' / dllRelativePath) directory recursiveMakeDirectory.
   458                 (mySTXTopDirectory / dllRelativePath) copyTo:(buildDirectory / 'stx' / dllRelativePath).    
   459             ]
   460         ] ifFalse:[
   461             self error:'Missing file: ',dllRelativePath printString mayProceed:true.
   462         ].
   463     ].
   464 
   465     "Modified: / 21-01-2012 / 13:40:56 / cg"
   466 !
   467 
   468 createHeaderFileFor:aClass in:packageTargetDir
   469     |instVarList classInstVarList classVarList bindings superclassFilename
   470      template file newContents oldContents|
   471 
   472     instVarList := StringCollection new.
   473     aClass instVarNames do:[:v |
   474         instVarList add:('OBJ %1;' bindWith:v)
   475     ].
   476     classInstVarList := StringCollection new.
   477     aClass class instVarNames do:[:v |
   478 (v includes:$_) ifTrue:[self halt].
   479         classInstVarList add:('OBJ %1;' bindWith:v)
   480     ].
   481     classVarList := StringCollection new.
   482     aClass classVarNames do:[:v |
   483         classVarList add:('extern OBJ %1_%2;' bindWith:aClass name with:v)
   484     ].
   485 
   486     bindings := Dictionary new.
   487     bindings at:'ClassName' put:aClass name. 
   488     aClass superclass isNil ifTrue:[
   489         bindings at:'SuperclassName' put:'-'. 
   490         bindings at:'SuperclassFileInclude' put:''.
   491     ] ifFalse:[
   492         bindings at:'SuperclassName' put:aClass superclass name. 
   493         bindings at:'SuperclassFileName' put:(superclassFilename := Smalltalk fileNameForClass:aClass superclass).
   494         bindings at:'SuperclassFileInclude' put:('#include "%1.STH"' bindWith:superclassFilename).
   495     ].
   496     bindings at:'InstVarList' put:instVarList asString. 
   497     bindings at:'ClassVarList' put:classVarList asString. 
   498     bindings at:'ClassInstVarList' put:classInstVarList asString. 
   499 
   500     template := 
   501 '/* This file was generated by ProjectBuilder. */
   502 /* !!!!!!!! Do not change by hand !!!!!!!! */
   503 
   504 /* Class: %(ClassName) */
   505 /* Superclass: %(SuperclassName) */
   506 
   507 %(SuperclassFileInclude)
   508 
   509 /* INDIRECTGLOBALS */
   510 #ifdef _HEADER_INST_
   511 %(InstVarList)
   512 #endif /* _HEADER_INST_ */
   513 
   514 #ifdef _HEADER_CLASS_
   515 %(ClassVarList)
   516 #endif /* _HEADER_CLASS_ */
   517 
   518 #ifdef _HEADER_CLASSINST_
   519 %(ClassInstVarList)
   520 #endif /* _HEADER_CLASSINST_ */
   521 '.
   522     newContents := template bindWithArguments:bindings.
   523     file := packageTargetDir asFilename / ((Smalltalk fileNameForClass:aClass),(self suffixForHeaderFiles)).
   524     (file exists not
   525     or:[ (oldContents := file contents) ~= newContents ]) ifTrue:[
   526         file contents: newContents.
   527     ].
   528 
   529     "Modified: / 15-08-2011 / 14:58:46 / cg"
   530 !
   531 
   532 generateSourceFiles
   533     sourceCodeManager notNil ifTrue:[
   534         "/ check out / generate files there
   535         self generateSourceFilesByCheckingOutUsing:sourceCodeManager
   536     ] ifFalse:[
   537         "/ local build
   538         "/ fileout the project
   539         self generateSourceFilesByFilingOut
   540     ]
   541 !
   542 
   543 generateSourceFilesByCheckingOutUsing:aSourceCodeManager
   544     "/ will no longer be needed/supported
   545 
   546     |repository stxRepository module directory|
   547 
   548     self breakPoint:#cg.
   549 
   550     "/ check out / generate files there
   551     repository := (aSourceCodeManager repositoryNameForModule:module) ifNil:[aSourceCodeManager repositoryName].
   552     stxRepository := aSourceCodeManager repositoryName.
   553 
   554     (buildDirectory construct:'stx') exists ifFalse:[
   555         (module ~= 'stx') ifTrue:[
   556             OperatingSystem
   557                 executeCommand:('cvs -d ',stxRepository,' co stx')
   558                 inputFrom:nil
   559                 outputTo:Transcript
   560                 errorTo:Transcript
   561                 inDirectory:buildDirectory
   562                 onError:[:status| self error:'cvs update stx failed'].
   563         ].
   564     ].
   565 
   566     ((buildDirectory construct:module) construct:'CVS') exists ifFalse:[
   567         OperatingSystem
   568             executeCommand:('cvs -d ',repository,' co -l ',directory)
   569             inputFrom:nil
   570             outputTo:Transcript
   571             errorTo:Transcript
   572             inDirectory:buildDirectory
   573             onError:[:status| self error:'cvs update failed'].
   574     ].
   575     OperatingSystem
   576         executeCommand:'cvs upd -d'
   577         inputFrom:nil
   578         outputTo:Transcript
   579         errorTo:Transcript
   580         inDirectory:(buildDirectory construct:module)
   581         onError:[:status| self error:'cvs update failed'].
   582 self halt.
   583 
   584     "Modified: / 29-12-2011 / 14:02:56 / cg"
   585 !
   586 
   587 generateSourceFilesByFilingOut
   588     "/ local build
   589     "/ fileout the project
   590 
   591     |fullPathName|
   592 
   593     (package module ~= 'stx') ifTrue:[
   594         (buildDirectory / package module) makeDirectory.
   595     ].
   596 
   597     "/ file out the package(s) which are to be built
   598     ((Array with:package))
   599     do:[:eachPackageToFileout |
   600         |packageId packageModule packageDirectory packageTargetDir packageDef|
   601 
   602         packageId := eachPackageToFileout asPackageId.
   603         packageModule := packageId module.
   604         packageDirectory := packageId directory.
   605         packageTargetDir := (buildDirectory / packageModule / packageDirectory) recursiveMakeDirectory.
   606 
   607         packageDef := packageId projectDefinitionClass.
   608         (packageDef compiled_classNames_common ,
   609         packageDef compiled_classNamesForPlatform) do:[:eachClassName |
   610             |cls fileName newSource|
   611 
   612             cls := Smalltalk classNamed:eachClassName.
   613             self assert:cls isLoaded.
   614             fileName := (Smalltalk fileNameForClass:cls),'.st'.
   615             fileName := packageTargetDir asFilename construct:fileName.
   616             fileName exists ifTrue:[
   617                 newSource := String streamContents:[:s | cls fileOutOn:s withTimeStamp:false].
   618                 newSource = fileName contentsAsString ifFalse:[
   619                     fileName contents:newSource
   620                 ].
   621             ] ifFalse:[
   622                 cls fileOutIn:packageTargetDir withTimeStamp:false
   623             ].
   624         ].
   625 
   626 "/        (Smalltalk allClassesInPackage:eachPackageToFileout) do:[:cls |
   627 "/            cls isPrivate ifFalse:[
   628 "/                cls isLoaded ifFalse:[
   629 "/                    self halt.
   630 "/                    cls autoload.
   631 "/                ].
   632 "/                cls fileOutIn:packageTargetDir
   633 "/            ]
   634 "/        ].
   635 
   636         projectDefinitionClass forEachFileNameAndGeneratedContentsDo:[:fileName :fileContents |
   637             fullPathName := packageTargetDir construct:fileName.
   638             fullPathName directory exists ifFalse:[
   639                 "take care for files like 'autopackage/default.apspec'"
   640                 fullPathName directory makeDirectory.
   641             ].
   642             (fullPathName exists
   643              and:[ fullPathName contents = fileContents ]) ifFalse:[
   644                 fullPathName contents:fileContents.
   645             ].
   646         ].    
   647     ].
   648 
   649     "/ generate header files in prerequisite packages...
   650     (projectDefinitionClass allPreRequisites)
   651     do:[:eachPackageToFileout |
   652         |packageId packageDef packageModule packageDirectory packageTargetDir|
   653 
   654         packageId := eachPackageToFileout asPackageId.
   655         packageModule := packageId module.
   656         packageDirectory := packageId directory.
   657         packageTargetDir := (buildDirectory / packageModule / packageDirectory) recursiveMakeDirectory.
   658 
   659         packageDef := packageId projectDefinitionClass.
   660         (packageDef compiled_classNames_common ,
   661         packageDef compiled_classNamesForPlatform) do:[:eachClassName |
   662             |cls|
   663 
   664             cls := Smalltalk classNamed:eachClassName.
   665             "/ self assert:cls isLoaded.
   666             cls isLoaded ifTrue:[    
   667                 self createHeaderFileFor:cls in:packageTargetDir
   668             ].
   669         ].
   670         self copyResourcesForPackage:eachPackageToFileout.
   671     ].
   672 
   673 "/    stx_libbasic2 preRequisitesForBuilding#(#'stx:libbasic')
   674 !
   675 
   676 makeWithOutputTo:stdOut errorTo:stdErr
   677     |module directory compilerFlag makeCommand|
   678 
   679     module := package module.
   680     directory := package directory.
   681 
   682     makeCommand := ParserFlags makeCommand.
   683     usedCompiler isNil ifTrue:[
   684         usedCompiler := ParserFlags usedCompiler.
   685     ].
   686     usedCompiler = 'vc' ifTrue:[ 
   687         makeCommand := 'vcmake'. "/ compilerFlag := '-DUSEVC' 
   688     ] ifFalse:[
   689         usedCompiler = 'lcc' ifTrue:[ 
   690             makeCommand := 'lcmake'. "/ compilerFlag := '-DUSELCC' 
   691         ] ifFalse:[
   692             usedCompiler = 'gcc' ifTrue:[ 
   693                 makeCommand := 'make'. 
   694             ] ifFalse:[
   695                 usedCompiler = 'bcc' ifTrue:[ 
   696                     makeCommand := 'bmake'.
   697                 ] ifFalse:[
   698                     self error:'no compiler specified'.
   699                 ]
   700             ]
   701         ]
   702     ].
   703 
   704     "/ makeCommand := makeCommand, ' TOP=', mySTXTopDirectory pathName.
   705 
   706     OperatingSystem isUNIXlike ifTrue:[
   707         OperatingSystem
   708             executeCommand:('sh %1/rules/stmkmf' bindWith:mySTXTopDirectory pathName)
   709             inputFrom:nil
   710             outputTo:stdOut
   711             errorTo:stdErr
   712             inDirectory:(buildDirectory / module / directory)
   713             onError:[:status| self error:'make failed'].
   714     ].
   715 
   716     projectDefinitionClass isLibraryDefinition ifTrue:[
   717         OperatingSystem
   718             executeCommand:(makeCommand,' classLibRule')
   719             inputFrom:nil
   720             outputTo:stdOut
   721             errorTo:stdErr
   722             inDirectory:(buildDirectory / module / directory)
   723             onError:[:status| self error:'make failed'].
   724     ] ifFalse:[
   725         OperatingSystem
   726             executeCommand:(makeCommand,' exe')
   727             inputFrom:nil
   728             outputTo:stdOut
   729             errorTo:stdErr
   730             inDirectory:(buildDirectory / module / directory)
   731             onError:[:status| self error:'make failed'].
   732 
   733         (makeExeOnly ? false) ifFalse:[
   734             OperatingSystem
   735                 executeCommand:(makeCommand,' setup')
   736                 inputFrom:nil
   737                 outputTo:stdOut
   738                 errorTo:stdErr
   739                 inDirectory:(buildDirectory / module / directory)
   740                 onError:[:status| self error:'make failed'].
   741         ]
   742     ]
   743 
   744     "Modified: / 20-07-2012 / 12:13:29 / cg"
   745 !
   746 
   747 recursiveCopyDirectoryForBuild:subdir
   748     |targetDir|
   749 
   750     targetDir := buildDirectory / 'stx' / subdir.
   751     targetDir exists ifFalse:[
   752         targetDir makeDirectory.
   753     ].
   754     (mySTXTopDirectory / subdir) directoryContentsAsFilenamesDo:[:eachFile |
   755         eachFile recursiveCopyTo:(targetDir construct:eachFile baseName)
   756     ].
   757     self activityNotification:nil
   758 !
   759 
   760 setupBuildDirectory
   761     buildDirectory exists ifFalse:[
   762         buildDirectory recursiveMakeDirectory.
   763     ].
   764     (buildDirectory / 'stx') exists ifFalse:[
   765         (buildDirectory / 'stx') makeDirectory.
   766     ].
   767 
   768     self copyDirectoryForBuild:'include'.
   769     self copyDirectoryForBuild:'rules'.
   770     OperatingSystem isUNIXlike ifTrue:[
   771         self recursiveCopyDirectoryForBuild:'configurations'.
   772     ]
   773 !
   774 
   775 validateBuildDirectoryIsPresent
   776 
   777     ^ self.
   778 
   779 "/    [
   780 "/        |default directoryIsOKForMe stc |
   781 "/
   782 "/        default := (buildDirectory ?
   783 "/                          PreviousBuildDirectory)
   784 "/                          ifNil:[ UserPreferences current buildDirectory].
   785 "/
   786 "/        buildDirectory := Dialog requestDirectoryName:'Temporary Work-ROOT for build:'
   787 "/                                 default:default.
   788 "/
   789 "/        buildDirectory isEmptyOrNil ifTrue:[^ self].
   790 "/        buildDirectory := buildDirectory asFilename.
   791 "/        directoryIsOKForMe := true.
   792 "/
   793 "/        buildDirectory exists ifFalse:[
   794 "/            Dialog warn:(self classResources string:'Work directory %1 does not exist.' with:buildDirectory).
   795 "/            directoryIsOKForMe := false.
   796 "/        ] ifTrue:[
   797 "/            (buildDirectory construct:'stx') exists ifFalse:[
   798 "/                Dialog warn:(self classResources stringWithCRs:'Work directory must contain an stx subDirectory,\which contains (at least) the stc and include subdirectories.').
   799 "/                directoryIsOKForMe := false.
   800 "/            ] ifTrue:[
   801 "/                stc := (OperatingSystem isMSDOSlike) ifTrue:['stc.exe'] ifFalse:['stc'].
   802 "/                (((buildDirectory construct:'stx')construct:'stc')construct:stc) exists ifFalse:[
   803 "/                    Dialog warn:(self classResources stringWithCRs:'Work directory must contain an stc compiler in the stx/stc subDirectory.').
   804 "/                    directoryIsOKForMe := false.
   805 "/                ].
   806 "/                ((buildDirectory construct:'stx')construct:'include') exists ifFalse:[
   807 "/                    Dialog warn:(self classResources stringWithCRs:'Work directory must have had a make run before (for include files to exists).').
   808 "/                    directoryIsOKForMe := false.
   809 "/                ].
   810 "/            ]
   811 "/        ].
   812 "/        directoryIsOKForMe
   813 "/    ] whileFalse
   814 ! !
   815 
   816 !ProjectBuilder class methodsFor:'documentation'!
   817 
   818 version
   819     ^ '$Header$'
   820 !
   821 
   822 version_CVS
   823     ^ '$Header$'
   824 ! !