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