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