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