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