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