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