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