ProjectBuilder.st
changeset 2921 bea9c6bb6a90
parent 2918 47d5c20da62d
child 2958 d842f4a91d44
equal deleted inserted replaced
2920:a7ddf89e20e3 2921:bea9c6bb6a90
    14 "{ NameSpace: Tools }"
    14 "{ NameSpace: Tools }"
    15 
    15 
    16 Object subclass:#ProjectBuilder
    16 Object subclass:#ProjectBuilder
    17 	instanceVariableNames:'package projectDefinitionClass sourceCodeManager buildDirectory
    17 	instanceVariableNames:'package projectDefinitionClass sourceCodeManager buildDirectory
    18 		myWorkingDirectory mySTXTopDirectory myTopDirectory outputStream
    18 		myWorkingDirectory mySTXTopDirectory myTopDirectory outputStream
    19 		makeExeOnly usedCompiler'
    19 		makeExeOnly usedCompiler stdOut stdErr'
    20 	classVariableNames:'PreviousBuildDirectory'
    20 	classVariableNames:'PreviousBuildDirectory'
    21 	poolDictionaries:''
    21 	poolDictionaries:''
    22 	category:'System-Support-Projects'
    22 	category:'System-Support-Projects'
    23 !
    23 !
    24 
    24 
    80 
    80 
    81     (compiler := UserPreferences current usedCompilerForBuild) notNil ifTrue:[
    81     (compiler := UserPreferences current usedCompilerForBuild) notNil ifTrue:[
    82         ^ compiler
    82         ^ compiler
    83     ].
    83     ].
    84 
    84 
    85     OperatingSystem isMSWINDOWSlike ifTrue:[
    85     ^ OperatingSystem isMSWINDOWSlike 
    86         ^ 'bcc'
    86         ifTrue:[ 'bcc' ]
    87     ].
    87         ifFalse:[ 'gcc' ]
    88     ^ 'gcc'
       
    89 
    88 
    90     "Created: / 21-01-2012 / 14:06:51 / cg"
    89     "Created: / 21-01-2012 / 14:06:51 / cg"
    91 !
    90 !
    92 
    91 
    93 listOfPossibleCompilers
    92 listOfPossibleCompilers
    94     OperatingSystem isMSWINDOWSlike ifTrue:[
    93     OperatingSystem isMSWINDOWSlike ifTrue:[
    95         OperatingSystem getLoginName = 'cg' ifTrue:[
    94         OperatingSystem getLoginName = 'cg' ifTrue:[
    96             ^ #('bcc' 'vc' 'lcc' 'tcc' 'mingw'  )
    95             ^ #(
    97         ].
    96                 'bcc'   "/ OK
    98         ^ #('bcc' 'vc' 'lcc'  )
    97                 'vc'    "/ almost OK
       
    98                 'lcc'   "/ experimental, but only free for non-commercial work
       
    99                 'tcc'   "/ experimental; limited but free
       
   100                 'mingw' "/ experimental; free
       
   101              )
       
   102         ].
       
   103         ^ #('bcc' 'vc' "'lcc' 'mingw'" )
    99     ].
   104     ].
   100     ^ #('gcc')
   105     ^ #('gcc')
   101 
   106 
   102     "Created: / 21-01-2012 / 14:04:15 / cg"
   107     "Created: / 21-01-2012 / 14:04:15 / cg"
       
   108 !
       
   109 
       
   110 suiteNameOfCompiler:usedCompiler
       
   111     usedCompiler = 'bcc' ifTrue:[
       
   112         ^ 'Borland C-Compiler'.
       
   113     ].
       
   114     usedCompiler = 'vc' ifTrue:[
       
   115         ^ 'Microsoft Visual C C-Compiler'.
       
   116     ].
       
   117     usedCompiler = 'lcc' ifTrue:[
       
   118         ^ 'LCC C-Compiler'.
       
   119     ].
       
   120     usedCompiler = 'tcc' ifTrue:[
       
   121         ^ 'Tiny C-Compiler'.
       
   122     ].
       
   123     usedCompiler = 'gcc' ifTrue:[
       
   124         ^ 'GNU C-Compiler'.
       
   125     ].
       
   126     usedCompiler = 'mingw' ifTrue:[
       
   127         ^ 'MINGW GNU C-Compiler'.
       
   128     ].
       
   129     self halt:'unknown compiler'.
       
   130 
       
   131     ^ 'C-Compiler'.
       
   132 
       
   133     "Created: / 06-09-2012 / 15:58:33 / cg"
   103 ! !
   134 ! !
   104 
   135 
   105 !ProjectBuilder methodsFor:'accessing'!
   136 !ProjectBuilder methodsFor:'accessing'!
   106 
   137 
   107 buildDirectory
   138 buildDirectory
   156 
   187 
   157 buildWithColorizedOutputTo:makeOutput
   188 buildWithColorizedOutputTo:makeOutput
   158     "/ intermediate - this will move into a commonly used utility class
   189     "/ intermediate - this will move into a commonly used utility class
   159     "/ (where all the project code support will be collected).
   190     "/ (where all the project code support will be collected).
   160 
   191 
   161     |stdOut stdErr lock|
   192     |lock|
   162 
   193 
   163     lock := Semaphore forMutualExclusion.
   194     lock := Semaphore forMutualExclusion.
   164 
   195 
   165     stdErr := ActorStream new
   196     stdErr := ActorStream new
   166                     nextPutBlock:[:char |
   197                     nextPutBlock:[:char |
   167                         lock critical:[
   198                         lock critical:[
   168                             makeOutput emphasis:{#backgroundColor->Color red. #color->Color white.}.
   199                             makeOutput 
   169                             makeOutput nextPut:char.
   200                                 withEmphasis:{#backgroundColor->Color red. #color->Color white.}
   170                             makeOutput emphasis:nil.
   201                                 do:[makeOutput nextPut:char].
   171                         ]
   202                         ]
   172                     ];
   203                     ];
   173                     nextPutAllBlock:[:string |
   204                     nextPutAllBlock:[:string |
   174                         lock critical:[          
   205                         lock critical:[          
   175                             "/ (string includesString:'das Ziel' )ifTrue:[self halt].
   206                             "/ (string includesString:'das Ziel' )ifTrue:[self halt].
   176                             makeOutput emphasis:{#backgroundColor->Color red. #color->Color white.}.
   207                             makeOutput
   177                             makeOutput nextPutAll:string.
   208                                 withEmphasis:{#backgroundColor->Color red. #color->Color white.}
   178                             makeOutput emphasis:nil.
   209                                 do:[makeOutput nextPutAll:string].
   179                         ]
   210                         ]
   180                     ].
   211                     ].
   181     stdOut := ActorStream new
   212     stdOut := ActorStream new
   182                     nextPutBlock:[:char |
   213                     nextPutBlock:[:char |
   183                         lock critical:[
   214                         lock critical:[
   191                         ]
   222                         ]
   192                     ].
   223                     ].
   193 
   224 
   194     self buildWithOutputTo:stdOut errorTo:stdErr.
   225     self buildWithOutputTo:stdOut errorTo:stdErr.
   195 
   226 
   196     "Modified: / 21-01-2012 / 13:49:13 / cg"
   227     "Modified: / 06-09-2012 / 16:15:50 / cg"
   197 !
   228 !
   198 
   229 
   199 buildWithOutputTo:stdOut errorTo:stdErr
   230 buildWithOutputTo:stdOut errorTo:stdErr
   200     "/ intermediate - this will move into a commonly used utility class
   231     "/ intermediate - this will move into a commonly used utility class
   201     "/ (where all the project code support will be collected).
   232     "/ (where all the project code support will be collected).
   307 "/                objDirSource := objDirDest
   338 "/                objDirSource := objDirDest
   308 "/            ].
   339 "/            ].
   309             (dllSourceDir / objDirSource / (libraryName, '.dll')) exists ifFalse:[
   340             (dllSourceDir / objDirSource / (libraryName, '.dll')) exists ifFalse:[
   310                 alternativeObjDirSource := self objDirForUsedCompiler:'vc'.
   341                 alternativeObjDirSource := self objDirForUsedCompiler:'vc'.
   311                 (dllSourceDir / alternativeObjDirSource / (libraryName, '.dll')) exists ifTrue:[
   342                 (dllSourceDir / alternativeObjDirSource / (libraryName, '.dll')) exists ifTrue:[
   312                     objDirSource := alternativeObjDirSource
   343                     objDirSource := alternativeObjDirSource.
   313                 ]
   344                     stdErr nextPutLine:(('Warning: using alternative %1 from %2 (%3 version)...' 
       
   345                                                 bindWith:libraryName 
       
   346                                                 with:alternativeObjDirSource 
       
   347                                                 with:(self class suiteNameOfCompiler:'vc'))
       
   348                                             emphasizeAllWith:(#color -> Color red darkened)).
       
   349                 ] ifFalse:[
       
   350                     alternativeObjDirSource := self objDirForUsedCompiler:'bcc'.
       
   351                     (dllSourceDir / alternativeObjDirSource / (libraryName, '.dll')) exists ifTrue:[
       
   352                         objDirSource := alternativeObjDirSource.
       
   353                         stdErr nextPutLine:('Warning: using alternative %1 from %2 (%3 version)...' 
       
   354                                     bindWith:libraryName 
       
   355                                     with:alternativeObjDirSource 
       
   356                                     with:(self class suiteNameOfCompiler:'bcc')).
       
   357                     ]
       
   358                 ].
   314             ].
   359             ].
   315 
   360 
   316 "/            dllRelativePath := objDir,'/',(libraryName,'.dll').
   361 "/            dllRelativePath := objDir,'/',(libraryName,'.dll').
   317 "/            (dllSourceDir / dllRelativePath) exists 
   362 "/            (dllSourceDir / dllRelativePath) exists 
   318             dllRelativeSourcePathes := Array with:(objDirSource,'\', libraryName, '.dll').
   363             dllRelativeSourcePathes := Array with:(objDirSource,'\', libraryName, '.dll').
   338                 source copyTo:dest.    
   383                 source copyTo:dest.    
   339             ].
   384             ].
   340         ].
   385         ].
   341     ].
   386     ].
   342 
   387 
   343     "Modified: / 05-09-2012 / 08:27:07 / cg"
   388     "Modified: / 06-09-2012 / 16:19:29 / cg"
   344 !
   389 !
   345 
   390 
   346 copyDirectory:relativepath
   391 copyDirectory:relativepath
   347     "/ need rules in stx
   392     "/ need rules in stx
   348     ((Smalltalk projectDirectoryForPackage:'stx') asFilename construct:relativepath)
   393     ((Smalltalk projectDirectoryForPackage:'stx') asFilename construct:relativepath)
   786     ].
   831     ].
   787     usedCompiler = 'tcc' ifTrue:[ 
   832     usedCompiler = 'tcc' ifTrue:[ 
   788         ^ 'tccmake'. "/ compilerFlag := '-DUSELCC' 
   833         ^ 'tccmake'. "/ compilerFlag := '-DUSELCC' 
   789     ].
   834     ].
   790     usedCompiler = 'gcc' ifTrue:[ 
   835     usedCompiler = 'gcc' ifTrue:[ 
   791         ^ 'make'. 
   836         ^ 'make'.       "/ compilerFlag := '-DUSEGCC' 
   792     ].
   837     ].
   793     usedCompiler = 'mingw' ifTrue:[ 
   838     usedCompiler = 'mingw' ifTrue:[ 
   794         ^ 'mingwmake'. 
   839         ^ 'mingwmake'.  "/ compilerFlag := '-DUSEMINGW' 
   795     ].
   840     ].
   796     self error:'unknown compiler specified'.
   841     self error:'unknown compiler specified'.
   797 
   842 
   798     "Created: / 03-09-2012 / 19:46:07 / cg"
   843     "Created: / 03-09-2012 / 19:46:07 / cg"
   799 !
   844 !
   811     makeCommand := self makeCommandOfCompiler:usedCompiler.
   856     makeCommand := self makeCommandOfCompiler:usedCompiler.
   812 
   857 
   813     "/ makeCommand := makeCommand, ' TOP=', mySTXTopDirectory pathName.
   858     "/ makeCommand := makeCommand, ' TOP=', mySTXTopDirectory pathName.
   814 
   859 
   815     OperatingSystem isUNIXlike ifTrue:[
   860     OperatingSystem isUNIXlike ifTrue:[
       
   861         "/ generate the makefile first
   816         OperatingSystem
   862         OperatingSystem
   817             executeCommand:('sh %1/rules/stmkmf' bindWith:mySTXTopDirectory pathName)
   863             executeCommand:('sh %1/rules/stmkmf' bindWith:mySTXTopDirectory pathName)
   818             inputFrom:nil
   864             inputFrom:nil
   819             outputTo:stdOut
   865             outputTo:stdOut
   820             errorTo:stdErr
   866             errorTo:stdErr
   821             inDirectory:(buildDirectory / module / directory)
   867             inDirectory:(buildDirectory / module / directory)
   822             onError:[:status| self error:'make failed'].
   868             onError:[:status | self error:'make failed'].
   823     ].
   869     ].
   824 
   870 
   825     projectDefinitionClass isLibraryDefinition ifTrue:[
   871     projectDefinitionClass isLibraryDefinition ifTrue:[
       
   872         "/ generate the library
   826         OperatingSystem
   873         OperatingSystem
   827             executeCommand:(makeCommand,' classLibRule')
   874             executeCommand:(makeCommand,' classLibRule')
   828             inputFrom:nil
   875             inputFrom:nil
   829             outputTo:stdOut
   876             outputTo:stdOut
   830             errorTo:stdErr
   877             errorTo:stdErr
   831             inDirectory:(buildDirectory / module / directory)
   878             inDirectory:(buildDirectory / module / directory)
   832             onError:[:status| self error:'make failed'].
   879             onError:[:status | self error:'make failed'].
   833     ] ifFalse:[
   880     ] ifFalse:[
   834         OperatingSystem
   881         OperatingSystem
       
   882             "/ generate the executable
   835             executeCommand:(makeCommand,' exe')
   883             executeCommand:(makeCommand,' exe')
   836             inputFrom:nil
   884             inputFrom:nil
   837             outputTo:stdOut
   885             outputTo:stdOut
   838             errorTo:stdErr
   886             errorTo:stdErr
   839             inDirectory:(buildDirectory / module / directory)
   887             inDirectory:(buildDirectory / module / directory)
   840             onError:[:status| self error:'make failed'].
   888             onError:[:status | self error:'make failed'].
   841 
   889 
   842         (makeExeOnly ? false) ifFalse:[
   890         (makeExeOnly ? false) ifFalse:[
       
   891             "/ generate the self-installable package
   843             OperatingSystem
   892             OperatingSystem
   844                 executeCommand:(makeCommand,' setup')
   893                 executeCommand:(makeCommand,' setup')
   845                 inputFrom:nil
   894                 inputFrom:nil
   846                 outputTo:stdOut
   895                 outputTo:stdOut
   847                 errorTo:stdErr
   896                 errorTo:stdErr
   848                 inDirectory:(buildDirectory / module / directory)
   897                 inDirectory:(buildDirectory / module / directory)
   849                 onError:[:status| self error:'make failed'].
   898                 onError:[:status | self error:'make failed'].
   850         ]
   899         ]
   851     ]
   900     ]
   852 
   901 
   853     "Modified: / 03-09-2012 / 19:47:15 / cg"
   902     "Modified: / 03-09-2012 / 19:47:15 / cg"
       
   903     "Modified (comment): / 06-09-2012 / 16:22:38 / cg"
   854 !
   904 !
   855 
   905 
   856 objDirForUsedCompiler
   906 objDirForUsedCompiler
   857     ^ self objDirForUsedCompiler:usedCompiler
   907     ^ self objDirForUsedCompiler:usedCompiler
   858 
   908