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