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