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