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