ProjectBuilder.st
changeset 2614 ff815b56c808
parent 2613 b8d38caaa884
child 2622 e55f43981463
equal deleted inserted replaced
2613:b8d38caaa884 2614:ff815b56c808
   128     self copyStartupFilesFromSmalltalk.
   128     self copyStartupFilesFromSmalltalk.
   129 
   129 
   130     self makeWithOutputTo:stdOut errorTo:stdErr.
   130     self makeWithOutputTo:stdOut errorTo:stdErr.
   131 !
   131 !
   132 
   132 
   133 stdErr.
   133 copyDLLsForLinkage
   134 !
   134     |targetBuildDir|
   135 
   135 
   136 ].
   136     targetBuildDir := buildDirectory / package module / package directory.
   137 !
   137 
   138 
   138     (projectDefinitionClass allPreRequisites)
   139 'stx').
   139     do:[:eachPackageToFileout |
   140 !
   140         |packageId packageDef packageModule packageDirectory packageTargetDir
   141 
   141          dllSource dllSourceDir libraryName dllRelativePath|
   142 ion:nil
   142 
   143 !
   143         packageId := eachPackageToFileout asPackageId.
   144 
   144         packageModule := packageId module.
   145 ].
   145         packageDirectory := packageId directory.
   146 !
   146         packageTargetDir := (buildDirectory / packageModule / packageDirectory) recursiveMakeDirectory.
   147 
   147 
   148 ion:nil
   148         packageDef := packageId projectDefinitionClass.
   149 !
   149         libraryName := packageDef libraryName.
   150 
   150 
   151 ]
   151         "/ mhmh - take them from my tree or from the projects/smalltalk execution directory ??
   152 !
   152         dllSourceDir := myTopDirectory / packageModule / packageDirectory.
   153 
   153         OperatingSystem isMSWINDOWSlike ifTrue:[
   154 ].
   154 "/            dllRelativePath := 'objvc','/',(libraryName,'.dll').
   155 !
   155 "/            (dllSourceDir / dllRelativePath) exists 
   156 
   156             false ifFalse:[
   157 ].
   157                 dllRelativePath := 'objbc','/',(libraryName,'.dll').
   158 !
   158             ]
   159 
   159         ] ifFalse:[
   160 ]
   160             dllRelativePath := libraryName,'.so'.
   161 !
   161         ].
   162 
   162         ((packageTargetDir / dllRelativePath) exists
   163 f halt.
   163         and:[ (dllSourceDir / dllRelativePath) fileSize = (packageTargetDir / dllRelativePath) fileSize
       
   164         and:[ (dllSourceDir / dllRelativePath) modificationTime < (packageTargetDir / dllRelativePath) modificationTime
       
   165         "/ and:[ (dllSourceDir / dllRelativePath) sameContentsAs:(packageTargetDir / dllRelativePath) ]
       
   166         ]]) ifFalse:[
       
   167             (packageTargetDir / dllRelativePath) directory recursiveMakeDirectory.
       
   168             (dllSourceDir / dllRelativePath) copyTo:(packageTargetDir / dllRelativePath).    
       
   169         ]
       
   170     ].
       
   171 !
       
   172 
       
   173 copyDirectory:relativepath
       
   174     "/ need rules in stx
       
   175     ((Smalltalk projectDirectoryForPackage:'stx') asFilename construct:relativepath)
       
   176         recursiveCopyTo:(buildDirectory construct:'stx').
       
   177 !
       
   178 
       
   179 copyDirectoryForBuild:subdir
       
   180     |targetDir targetFile|
       
   181 
       
   182     targetDir := buildDirectory / 'stx' / subdir.
       
   183     targetDir exists ifFalse:[
       
   184         targetDir makeDirectory.
       
   185     ].
       
   186     (mySTXTopDirectory / subdir) directoryContentsAsFilenamesDo:[:eachFile |
       
   187         eachFile isDirectory ifFalse:[
       
   188             targetFile := targetDir / eachFile baseName.
       
   189             (targetFile exists not
       
   190             or:[ targetFile modificationTime < eachFile modificationTime ]) ifTrue:[
       
   191                 self activityNotification:'copying ',eachFile pathName,'...'.
       
   192                 eachFile copyTo:(targetDir construct:eachFile baseName)
       
   193             ]
       
   194         ].
       
   195     ].
       
   196     self activityNotification:nil
       
   197 !
       
   198 
       
   199 copyResourcesForPackage:aPackage
       
   200     |module directory|
       
   201 
       
   202     module := aPackage asPackageId module.
       
   203     directory := aPackage asPackageId directory.
       
   204 
       
   205     (myTopDirectory / module / directory / 'resources' ) exists ifTrue:[
       
   206         (myTopDirectory / module / directory / 'resources' )
       
   207             recursiveCopyTo:(buildDirectory / module / directory)
       
   208     ].
       
   209     (myTopDirectory / module / directory / 'styles' ) exists ifTrue:[
       
   210         (myTopDirectory / module / directory / 'styles' )
       
   211             recursiveCopyTo:(buildDirectory / module / directory)
       
   212     ].
       
   213 !
       
   214 
       
   215 copySTCDirectoryForBuild
       
   216     |targetDir stc files|
       
   217 
       
   218     targetDir := buildDirectory / 'stx' / 'stc'.
       
   219     targetDir exists ifFalse:[ targetDir makeDirectory ].
       
   220 
       
   221     stc := OperatingSystem isMSWINDOWSlike 
       
   222                 ifTrue:[ 'stc.exe' ]
       
   223                 ifFalse:[ 'stc' ].
       
   224 
       
   225     files := #( ) copyWith:stc.
       
   226 
       
   227     files do:[:eachFile |
       
   228         |sourceFile targetFile|
       
   229 
       
   230         sourceFile := mySTXTopDirectory / 'stc' / eachFile.
       
   231         targetFile := targetDir / eachFile.
       
   232         (targetFile exists not
       
   233         or:[ targetFile modificationTime < sourceFile modificationTime ]) ifTrue:[
       
   234             self activityNotification:'copying ',sourceFile pathName,'...'.
       
   235             sourceFile copyTo:targetFile
       
   236         ].
       
   237     ].
       
   238     self activityNotification:nil
       
   239 !
       
   240 
       
   241 copyStartupFilesFromSmalltalk
       
   242     (buildDirectory / 'stx' / 'projects/smalltalk' ) exists ifFalse:[
       
   243         (buildDirectory / 'stx' / 'projects/smalltalk' ) recursiveMakeDirectory.
       
   244     ].
       
   245 
       
   246     #( 'keyboard.rc' 'keyboardMacros.rc' 'display.rc' 'd_win32.rc'
       
   247        'host.rc' 'h_win32.rc'  
       
   248     ) do:[:fn |
       
   249         (myTopDirectory / 'stx' / 'projects/smalltalk' / fn)
       
   250             copyTo: (buildDirectory / 'stx' / 'projects/smalltalk' / fn)
       
   251     ]
       
   252 !
       
   253 
       
   254 copySupportFilesForLinkage
       
   255     |files|
       
   256 
       
   257     OperatingSystem isMSWINDOWSlike ifTrue:[
       
   258         files := #( 
       
   259                     'support/win32/borland/cs3245.dll' 
       
   260                     'support/win32/X11.dll'
       
   261                     'support/win32/Xext.dll'
       
   262                     'librun/librun.dll'
       
   263                     'libbc/librun.lib'
       
   264                     'libbc/cs32i.lib'
       
   265                     'librun/genDate.exe'
       
   266                     'librun/main.c'
       
   267                  ).
       
   268     ] ifFalse:[
       
   269         files := #(
       
   270                     'librun/genDate'
       
   271                     'librun/main.c'
       
   272                     'librun/librun.so'
       
   273                 )
       
   274     ].
       
   275 
       
   276     files do:[:dllRelativePath |
       
   277         ((buildDirectory / 'stx' / dllRelativePath) exists
       
   278         and:[ (mySTXTopDirectory / dllRelativePath) fileSize = (buildDirectory / 'stx' / dllRelativePath) fileSize
       
   279         and:[ (mySTXTopDirectory / dllRelativePath) modificationTime < (buildDirectory / 'stx' / dllRelativePath) modificationTime
       
   280         "/ and:[ (mySTXTopDirectory / dllRelativePath) sameContentsAs:(targetBuildDir / dllRelativePath) ]
       
   281         ]]) ifFalse:[
       
   282             (buildDirectory / 'stx' / dllRelativePath) directory recursiveMakeDirectory.
       
   283             (mySTXTopDirectory / dllRelativePath) copyTo:(buildDirectory / 'stx' / dllRelativePath).    
       
   284         ]
       
   285     ].
       
   286 !
       
   287 
       
   288 createHeaderFileFor:aClass in:packageTargetDir
       
   289     |instVarList classInstVarList classVarList bindings superclassFilename
       
   290      template file newContents oldContents|
       
   291 
       
   292     instVarList := StringCollection new.
       
   293     aClass instVarNames do:[:v |
       
   294         instVarList add:('OBJ %1;' bindWith:v)
       
   295     ].
       
   296     classInstVarList := StringCollection new.
       
   297     aClass class instVarNames do:[:v |
       
   298 (v includes:$_) ifTrue:[self halt].
       
   299         classInstVarList add:('OBJ %1;' bindWith:v)
       
   300     ].
       
   301     classVarList := StringCollection new.
       
   302     aClass classVarNames do:[:v |
       
   303         classVarList add:('extern OBJ %1_%2;' bindWith:aClass name with:v)
       
   304     ].
       
   305 
       
   306     bindings := Dictionary new.
       
   307     bindings at:'ClassName' put:aClass name. 
       
   308     aClass superclass isNil ifTrue:[
       
   309         bindings at:'SuperclassName' put:'-'. 
       
   310         bindings at:'SuperclassFileInclude' put:nil.
       
   311     ] ifFalse:[
       
   312         bindings at:'SuperclassName' put:aClass superclass name. 
       
   313         bindings at:'SuperclassFileName' put:(superclassFilename := Smalltalk fileNameForClass:aClass superclass).
       
   314         bindings at:'SuperclassFileInclude' put:('#include "%1.STH"' bindWith:superclassFilename).
       
   315     ].
       
   316     bindings at:'InstVarList' put:instVarList asString. 
       
   317     bindings at:'ClassVarList' put:classVarList asString. 
       
   318     bindings at:'ClassInstVarList' put:classInstVarList asString. 
       
   319 
       
   320     template := 
       
   321 '/* This file was generated by ProjectBuilder. */
       
   322 /* !!!!!!!! Do not change by hand !!!!!!!! */
       
   323 
       
   324 /* Class: %(ClassName) */
       
   325 /* Superclass: %(SuperclassName) */
       
   326 
       
   327 %(SuperclassFileInclude)
       
   328 
       
   329 /* INDIRECTGLOBALS */
       
   330 #ifdef _HEADER_INST_
       
   331 %(InstVarList)
       
   332 #endif /* _HEADER_INST_ */
       
   333 
       
   334 #ifdef _HEADER_CLASS_
       
   335 %(ClassVarList)
       
   336 #endif /* _HEADER_CLASS_ */
       
   337 
       
   338 #ifdef _HEADER_CLASSINST_
       
   339 %(ClassInstVarList)
       
   340 #endif /* _HEADER_CLASSINST_ */
       
   341 '.
       
   342     newContents := template bindWithArguments:bindings.
       
   343     file := packageTargetDir asFilename / ((Smalltalk fileNameForClass:aClass),'.STH').
       
   344     (file exists not
       
   345     or:[ (oldContents := file contents) ~= newContents ]) ifTrue:[
       
   346         file contents: newContents.
       
   347     ].
       
   348 !
       
   349 
       
   350 generateSourceFiles
       
   351     sourceCodeManager notNil ifTrue:[
       
   352         "/ check out / generate files there
       
   353         self generateSourceFilesByCheckingOutUsing:sourceCodeManager
       
   354     ] ifFalse:[
       
   355         "/ local build
       
   356         "/ fileout the project
       
   357         self generateSourceFilesByFilingOut
       
   358     ]
       
   359 !
       
   360 
       
   361 generateSourceFilesByCheckingOutUsing:aSourceCodeManager
       
   362     "/ will no longer be needed/supported
       
   363 
       
   364     |repository stxRepository module directory|
       
   365 
       
   366 self halt.
       
   367     "/ check out / generate files there
       
   368     repository := (aSourceCodeManager repositoryNameForModule:module) ifNil:[aSourceCodeManager repositoryName].
       
   369     stxRepository := aSourceCodeManager repositoryName.
       
   370 
       
   371     (buildDirectory construct:'stx') exists ifFalse:[
       
   372         (module ~= 'stx') ifTrue:[
       
   373             OperatingSystem
       
   374                 executeCommand:('cvs -d ',stxRepository,' co stx')
       
   375                 inputFrom:nil
       
   376                 outputTo:Transcript
       
   377                 errorTo:Transcript
       
   378                 inDirectory:buildDirectory
       
   379                 onError:[:status| self error:'cvs update stx failed'].
       
   380         ].
       
   381     ].
       
   382 
       
   383     ((buildDirectory construct:module) construct:'CVS') exists ifFalse:[
       
   384         OperatingSystem
       
   385             executeCommand:('cvs -d ',repository,' co -l ',directory)
       
   386             inputFrom:nil
       
   387             outputTo:Transcript
       
   388             errorTo:Transcript
       
   389             inDirectory:buildDirectory
       
   390             onError:[:status| self error:'cvs update failed'].
       
   391     ].
       
   392     OperatingSystem
       
   393         executeCommand:'cvs upd -d'
       
   394         inputFrom:nil
       
   395         outputTo:Transcript
       
   396         errorTo:Transcript
       
   397         inDirectory:(buildDirectory construct:module)
       
   398         onError:[:status| self error:'cvs update failed'].
       
   399 self halt.
       
   400 !
       
   401 
       
   402 generateSourceFilesByFilingOut
       
   403     "/ local build
       
   404     "/ fileout the project
       
   405 
       
   406     (package module ~= 'stx') ifTrue:[
       
   407         (buildDirectory / package module) makeDirectory.
       
   408     ].
       
   409 
       
   410     "/ file out the package(s) which are to be built
       
   411     ((Array with:package))
       
   412     do:[:eachPackageToFileout |
       
   413         |packageId packageModule packageDirectory packageTargetDir packageDef|
       
   414 
       
   415         packageId := eachPackageToFileout asPackageId.
       
   416         packageModule := packageId module.
       
   417         packageDirectory := packageId directory.
       
   418         packageTargetDir := (buildDirectory / packageModule / packageDirectory) recursiveMakeDirectory.
       
   419 
       
   420         packageDef := packageId projectDefinitionClass.
       
   421         (packageDef compiled_classNames_common ,
       
   422         packageDef compiled_classNamesForPlatform) do:[:eachClassName |
       
   423             |cls|
       
   424 
       
   425             cls := Smalltalk classNamed:eachClassName.
       
   426             self assert:cls isLoaded.
       
   427             cls fileOutIn:packageTargetDir
       
   428         ].
       
   429 
       
   430 "/        (Smalltalk allClassesInPackage:eachPackageToFileout) do:[:cls |
       
   431 "/            cls isPrivate ifFalse:[
       
   432 "/                cls isLoaded ifFalse:[
       
   433 "/                    self halt.
       
   434 "/                    cls autoload.
       
   435 "/                ].
       
   436 "/                cls fileOutIn:packageTargetDir
       
   437 "/            ]
       
   438 "/        ].
       
   439 
       
   440         projectDefinitionClass forEachFileNameAndGeneratedContentsDo:[:fileName :fileContents |
       
   441             ((packageTargetDir / fileName) exists
       
   442             and:[ (packageTargetDir / fileName) contents = fileContents ]) ifFalse:[
       
   443                 (packageTargetDir / fileName) contents:fileContents.
       
   444             ].
       
   445         ].    
       
   446     ].
       
   447 
       
   448     "/ generate header files in prerequisite packages...
       
   449     (projectDefinitionClass allPreRequisites)
       
   450     do:[:eachPackageToFileout |
       
   451         |packageId packageDef packageModule packageDirectory packageTargetDir|
       
   452 
       
   453         packageId := eachPackageToFileout asPackageId.
       
   454         packageModule := packageId module.
       
   455         packageDirectory := packageId directory.
       
   456         packageTargetDir := (buildDirectory / packageModule / packageDirectory) recursiveMakeDirectory.
       
   457 
       
   458         packageDef := packageId projectDefinitionClass.
       
   459         (packageDef compiled_classNames_common ,
       
   460         packageDef compiled_classNamesForPlatform) do:[:eachClassName |
       
   461             |cls|
       
   462 
       
   463             cls := Smalltalk classNamed:eachClassName.
       
   464             "/ self assert:cls isLoaded.
       
   465             cls isLoaded ifTrue:[    
       
   466                 self createHeaderFileFor:cls in:packageTargetDir
       
   467             ].
       
   468         ].
       
   469         self copyResourcesForPackage:eachPackageToFileout.
       
   470     ].
       
   471 
       
   472 "/    stx_libbasic2 preRequisitesForBuilding#(#'stx:libbasic')
   164 !
   473 !
   165 
   474 
   166 makeWithOutputTo:stdOut errorTo:stdErr
   475 makeWithOutputTo:stdOut errorTo:stdErr
   167     |module directory|
   476     |module directory|
   168 
   477 
   194             inDirectory:(buildDirectory / module / directory)
   503             inDirectory:(buildDirectory / module / directory)
   195             onError:[:status| self error:'make failed'].
   504             onError:[:status| self error:'make failed'].
   196     ]
   505     ]
   197 !
   506 !
   198 
   507 
   199 errorTo:stdErr
   508 setupBuildDirectory
   200             inDirectory:(buildDirectory / module / directory)
   509     buildDirectory exists ifFalse:[
   201             onError:[:status| self error:'make failed'].
   510         buildDirectory recursiveMakeDirectory.
   202 
   511     ].
   203         OperatingSystem
   512     (buildDirectory / 'stx') exists ifFalse:[
   204             executeCommand:(ParserFlags makeCommand,' setup')
   513         (buildDirectory / 'stx') makeDirectory.
   205             inputFrom:nil
   514     ].
   206             outputTo:stdOut
   515 
   207             errorTo:stdErr
   516     self copyDirectoryForBuild:'include'.
   208             inDirectory:(buildDirectory / module / directory)
   517     self copyDirectoryForBuild:'rules'.
   209             onError:[:status| self error:'make failed'].
   518 !
   210     ]
   519 
   211 !
   520 validateBuildDirectoryIsPresent
   212 
   521 
   213 :stdErr
   522     ^ self.
   214             inDirectory:(buildDirectory / module / directory)
   523 
   215             onError:[:status| self error:'make failed'].
   524 "/    [
   216     ]
   525 "/        |default directoryIsOKForMe stc |
       
   526 "/
       
   527 "/        default := (buildDirectory ?
       
   528 "/                          PreviousBuildDirectory)
       
   529 "/                          ifNil:[ UserPreferences current buildDirectory].
       
   530 "/
       
   531 "/        buildDirectory := Dialog requestDirectoryName:'Temporary Work-ROOT for build:'
       
   532 "/                                 default:default.
       
   533 "/
       
   534 "/        buildDirectory isEmptyOrNil ifTrue:[^ self].
       
   535 "/        buildDirectory := buildDirectory asFilename.
       
   536 "/        directoryIsOKForMe := true.
       
   537 "/
       
   538 "/        buildDirectory exists ifFalse:[
       
   539 "/            Dialog warn:(self classResources string:'Work directory %1 does not exist.' with:buildDirectory).
       
   540 "/            directoryIsOKForMe := false.
       
   541 "/        ] ifTrue:[
       
   542 "/            (buildDirectory construct:'stx') exists ifFalse:[
       
   543 "/                Dialog warn:(self classResources stringWithCRs:'Work directory must contain an stx subDirectory,\which contains (at least) the stc and include subdirectories.').
       
   544 "/                directoryIsOKForMe := false.
       
   545 "/            ] ifTrue:[
       
   546 "/                stc := (OperatingSystem isMSDOSlike) ifTrue:['stc.exe'] ifFalse:['stc'].
       
   547 "/                (((buildDirectory construct:'stx')construct:'stc')construct:stc) exists ifFalse:[
       
   548 "/                    Dialog warn:(self classResources stringWithCRs:'Work directory must contain an stc compiler in the stx/stc subDirectory.').
       
   549 "/                    directoryIsOKForMe := false.
       
   550 "/                ].
       
   551 "/                ((buildDirectory construct:'stx')construct:'include') exists ifFalse:[
       
   552 "/                    Dialog warn:(self classResources stringWithCRs:'Work directory must have had a make run before (for include files to exists).').
       
   553 "/                    directoryIsOKForMe := false.
       
   554 "/                ].
       
   555 "/            ]
       
   556 "/        ].
       
   557 "/        directoryIsOKForMe
       
   558 "/    ] whileFalse
   217 ! !
   559 ! !
   218 
   560 
   219 !ProjectBuilder class methodsFor:'documentation'!
   561 !ProjectBuilder class methodsFor:'documentation'!
   220 
   562 
   221 version_CVS
   563 version_CVS