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