NCBI C Toolkit Cross Reference

C/make/makeStat.met


  1 (*
     Make our stationery project from scratch that will 
    be used to make all other libraries. This allows us to get all of these common 
        settings out of the makeall script.
*)

-- create library or application stationery?
property pCreateLibrary : false

property pProjectFileExtension : ".mcp"

property pTargetList : {"Carbon Debug", "Carbon Final", "Mach-O Debug", "Mach-O Final"}
global gAccessRoot
global gMWCWfolder

(* ======  Stand alone. When run by itself, make the appropriate stationery. ====== *)

set my pCreateLibrary to true
SetGlobals()
CreateFolders()
CreateStationeryProject(gStationeryName, gRsrcsDir, gMWCWfolder)
set my pCreateLibrary to false
SetGlobals()
CreateFolders()
CreateStationeryProject(gStationeryName, gRsrcsDir, gMWCWfolder)



on CreateStationeryProject(projName, projDir, cwDir)
 
       -- make sure the Metrowerks folder spec is global.
     if gMWCWfolder is not cwDir then
               set gMWCWfolder to cwDir
       end if
 
       set projFilename to projName & pProjectFileExtension
   set projPathname to projDir & projFilename
     
       tell application "CodeWarrior IDE"
             
               try
                    close (the first project document whose name is projFilename)
          end try
                
               -- try
         
               -- display dialog "creating project: " & projPathname buttons {"OK"} default button 1
          
               Create Project {projPathname}
          
               -- end try
             
               repeat with t in pTargetList
                   my SetupTarget(t, projName)
            end repeat
             
               -- finish up.
          if my IsOSX() and not pCreateLibrary then
                      display dialog "To finish add the following files into " & projFilename & "'s Mach-O targets:" & return & Â
                            "  /System/Library/Frameworks/Carbon.framework" & return & Â
                           "  /System/Library/Frameworks/System.framework" & return & Â
                           "  /usr/lib/crt1.o" & return & return & Â
                              "Sorry, but Codewarrior's Applescript won't do these." buttons {"OK"} default button 1
         else
                   Close Project
          end if
         
       end tell
       
       CleanupFolder(projDir, projName)
       
end CreateStationeryProject

-- Delete files and folders created during this process we do not  need.
-- particularly the project's Data directory and output files and directories.
on CleanupFolder(thePath, projName)
      repeat with f in list folder (thePath) without invisibles
              if ((f as string) begins with "xxxx_" or (f as string) is projName & " Data") then
                     try
                            tell application "Finder" to delete folder (thePath & f)
                       end try
                        try
                            tell application "Finder" to delete file (thePath & f)
                 end try
                end if
 end repeat
end CleanupFolder

on SetupTarget(targetName, projName)
     tell application "CodeWarrior IDE"
             
               -- display dialog "Setup target: " & targetName & return & "project: " & projName
              
               -- Figure out what our output file will be (tentatively) named.
                
               set targetFilename to "xxxx" -- The real target's output name will get set later.
              set targetAPI to ""
            set debugFlag to ""
            
               -- Linker & Output type.
               
               if targetName contains "Carbon" then
                   set targetFilename to targetFilename & "_C"
                    set targetAPI to "Carbon"
              else if targetName contains "Mach-O" and my IsOSX() then
                       set targetFilename to targetFilename & "_M"
                    set targetAPI to "Mach-O"
              else
                   -- I do not know what kind of target you are talking about.
                    -- or we are on a OS 9 machine and I don't know what Mach-O is.
                        -- ignore this argument.
                       return
         end if
         
               -- Debug or not.
               if targetName contains "Final" or targetName contains "Release" then
                   set debugFlag to "Final"
                       set targetFilename to targetFilename & "_O" -- for Optimized.
          else
                   -- Assume Debug if nothing else.
                       set debugFlag to "Debug"
                       set targetFilename to targetFilename & "_D"
            end if
         
               if pCreateLibrary then
                 set targetFilename to targetFilename & ".lib"
                  set targetName to "Library " & targetName
              else
                   set targetFilename to targetFilename & ".app"
                  set targetName to "Application " & targetName
          end if
         
               -- Make the new target, and set the current target to be it.
           
               if (count targets of project document 1) is 1 and Â
                    (name of target 1 of project document 1) is projName then
                      -- brand new project comes with one default target, same name as the project.
                  -- rename that one.
                    set (name of target 1 of project document 1) to targetName
                     set the current target of project document 1 to the target 1 of project document 1
             else
                   -- make all the subsequent targets.
                    make new target at project document 1 with properties {name:targetName}
                        set the current target of project document 1 to the result
             end if
         
               -- set all the preference panels
               -- display dialog " API: " & targetAPI & return & " filename: " & targetFilename & return & debugFlag
          my SetPreferences(targetAPI, targetFilename, debugFlag is "Debug")
             
       end tell
end SetupTarget

------ All Preference Panel settings in here.  ----- 

on SetPreferences(targetAPI, targetFilename, shouldDebug)
     set weAreMach to (targetAPI is "Mach-O")
       
       tell application "CodeWarrior IDE"
             
               if weAreMach then
                      set linkerName to "MacOS X PPC Linker"
                 set targetPanelName to "PPC Mac OS X Project"
                  set codeGenPanelName to "PPC CodeGen Mach-O"
                   set linkerPanelName to "PPC Mac OS X Linker"
           else
                   set linkerName to "MacOS PPC Linker"
                   set targetPanelName to "PPC Project"
                   set codeGenPanelName to "PPC CodeGen"
                  set linkerPanelName to "PPC Linker"
            end if
         
               (* ===== Section "Target" ===== *)
             
               Set Preferences of panel "Target Settings" to {Linker:linkerName}
              
               -- Panel "PPC or Mac OS X Target"
              if pCreateLibrary then
                 Set Preferences of panel targetPanelName to {Project Type:library, File Name:targetFilename}
           else
                   if weAreMach then
                              Set Preferences of panel targetPanelName to Â
                                  {Project Type:application package, File Name:targetFilename, File Creator:"NCBI", File Type:"APPL"}
                    else
                           Set Preferences of panel targetPanelName to Â
                                  {Project Type:standard application, File Name:targetFilename, File Creator:"NCBI", File Type:"APPL", SIZE Flags:22720, Preferred Heap Size:8000, Min Heap Size:5000, Stack Size:64} Â
                                          
                               -- the following only needed on pre-OS X systems when we turn on the Output Flags post-linker, 
                                -- but it is harmless in other cases.
                          Set Preferences of panel "Output Flags" to {Has Bundle:true}
                   end if
         end if
         
               (* ===== Section "Language Settings" ===== *)
          
               -- Panel "C/C++ Language"
              Set Preferences of panel "C/C++ Compiler" to Â
                 {Activate CPlusPlus:false Â
                            , ARM Conformance:false Â
                              , Exception Handling:true Â
                            , RTTI:true Â
                          , Pool Strings:true Â
                          , Dont Reuse Strings:false Â
                           , Require Function Prototypes:true Â
                           , Enable bool Support:true Â
                           , Enable wchar_t:true Â
                                , C99:false Â
                          , ANSI Strict:false Â
                          , ANSI Keywords Only:false Â
                           , Expand Trigraph Sequences:false Â
                            , MPW Newlines:false Â
                         , MPW Pointer Type Rules:false Â
                               , Enums Always Ints:false Â
                            , Prefix File:""}
              
               -- Panel "C/C++ Warnings"
              Set Preferences of panel "C/C++ Warnings" to Â
                 {Treat Warnings As Errors:false Â
                              , Illegal Pragmas:true Â
                               , Empty Declarations:true Â
                            , Possible Errors:true Â
                               , Unused Variables:true Â
                              , Unused Arguments:false Â
                             , Extra Commas:true Â
                          , Extended Error Checking:true Â
                               , Hidden Virtual Functions:true Â
                              , Implicit Arithmetic Conversions:false Â
                              , NonInlined Functions:false Â
                         , Inconsistent Class Struct:true}
              
               (* ===== Section "Code Generation" ===== *)
            
               -- Panel "PPC CodeGen Mach-O"
          Set Preferences of panel codeGenPanelName to Â
                 {Struct Alignment:Align_PPC Â
                          , Make Strings ReadOnly:true Â
                         , Use FMADD Instructions:false Â
                               , Schedule:false Â
                             , Peephole Optimizer:true}
             
               if not weAreMach then
                  -- preferences that are only on non-Mach targets.
                      Set Preferences of panel codeGenPanelName to Â
                         {Store Data in TOC:true Â
                                      , Traceback Tables:TB_Inline}
          end if
         
               (* ===== Section "Debugger" ===== *)
           
               if shouldDebug then
                    (* ==== Debug settings ==== *)
                 (* ===== Panel PPC Global Optimizer =====  *)
                  Set Preferences of panel "PPC Global Optimizer" to Â
                           {Optimize For:code_Speed, Level:0}
                     
                       (* ===== Panel PPC Linker ===== *)
                     Set Preferences of panel linkerPanelName to Â
                          {Generate SYM File:true Â
                                      , Full Path In SYM:true Â
                                      , Generate Link Map:false Â
                                    , Link Mode:fast}
                      
                       (* ===== Panel C/C++ Language =====  *)
                        Set Preferences of panel "C/C++ Compiler" to Â
                         {Inlining:inline_none, AutoInlining:false}
             else
                   (* ==== optimized/release settings ==== *)
                     (* ===== Panel PPC Global Optimizer =====  *)
                  Set Preferences of panel "PPC Global Optimizer" to Â
                           {Optimize For:code_Speed, Level:4}
                     (* ===== Panel PPC Linker ===== *)
                     
                       Set Preferences of panel linkerPanelName to Â
                          {Generate SYM File:false Â
                                     , Generate Link Map:false Â
                                    , Link Mode:fast}
                      
                       (* ===== Panel C/C++ Language =====  *)
                        Set Preferences of panel "C/C++ Compiler" to Â
                         {Inlining:inline_smart, AutoInlining:true}
             end if
         
               -- Panel "Debugger Settings"
           Set Preferences of panel "Debugger Target" to Â
                        {Log System Messages:false}
            
               (* ===== Panel Access Paths ===== *)
           -- when building projects add the other paths at the end of User Paths.
                -- since 'Always Full Search' is true they will get searched before the default System Paths.
          -- But MachO needs to move the /usr/.. directories to User Paths.
              
               Set Preferences of panel "Access Paths" to {Always Full Search:true, Convert Paths:true, Require Framework Includes:false}
             my SetPaths(weAreMach)
         
               -- add libraries to this target
                
               if not pCreateLibrary then
                     if not weAreMach then
                          if shouldDebug then
                                    set libsToAdd to {gMWCWfolder & "MacOS Support:Libraries:Runtime:Libs:MSL_All_Carbon_D.lib"}
                           else
                                   set libsToAdd to {gMWCWfolder & "MacOS Support:Libraries:Runtime:Libs:MSL_All_Carbon.lib"}
                             end if
                         copy (gMWCWfolder & "MacOS Support:Universal:Libraries:StubLibraries:CarbonLib") to end of libsToAdd
                   else
                           if shouldDebug then
                                    set libsToAdd to {gMWCWfolder & "MacOS X Support:Libraries:Runtime:Libs:MSL_All_Mach-O_D.lib"}
                         else
                                   set libsToAdd to {gMWCWfolder & "MacOS X Support:Libraries:Runtime:Libs:MSL_All_Mach-O.lib"}
                           end if
                         copy (gMWCWfolder & "MSL:MSL_C:MSL_MacOS:Src:console_OS_X.c") to end of libsToAdd
                              copy ("/usr/lib/crt1.o") to end of libsToAdd
                           copy "abc:System:Library:Frameworks:Carbon.framework" to end of libsToAdd
                              copy "abc:System:Library:Frameworks:System.framework" to end of libsToAdd
                      end if
                 
                       Add Files libsToAdd
            end if
         
       end tell
end SetPreferences

on SetPaths(weAreMach)
    tell application "CodeWarrior IDE"
             
               (* ===== Panel Access Paths ===== *)
           
               -- This removes the compiler default folders because otherwise setting the paths only adds on to the end. Never deletes anything.
              Set Preferences of panel "Access Paths" to {User Paths:{}, System Paths:{}}
            
               -- set up User Paths
           set userPaths to {{name:":", format:MacOS Path, origin:project relative, recursive:true}}
              if weAreMach then
                      copy {name:":usr:include:", format:MacOS Path, origin:root relative, root:"OS X Volume", recursive:false} Â
                            to end of userPaths
                    if not pCreateLibrary then
                             copy {name:":usr:lib:", format:MacOS Path, origin:root relative, root:"OS X Volume", recursive:false} Â
                                        to end of userPaths
                    end if
         end if
         
               -- set up System Paths
         if weAreMach then
                      set sysPaths to {Â
                             {name:":MSL:MSL_C:", format:MacOS Path, origin:shell relative, recursive:true}, Â
                              {name:":MacOS Support:", format:MacOS Path, origin:shell relative, recursive:true}, Â
                          {name:":MacOS X Support:", format:MacOS Path, origin:shell relative, recursive:true}}
          else
                   set sysPaths to {Â
                             {name:":MSL:", format:MacOS Path, origin:shell relative, recursive:true}, Â
                            {name:":MacOS Support:", format:MacOS Path, origin:shell relative, recursive:true}}
            end if
         
               -- put everything back.
                Set Preferences of panel "Access Paths" to {User Paths:userPaths, System Paths:sysPaths}
               
       end tell
end SetPaths


on stripVolName(macPath)
       set saveTID to get text item delimiters of AppleScript
 set text item delimiters of AppleScript to ":"
 set strippedPath to (rest of text items of macPath) as string
  set text item delimiters of AppleScript to saveTID
     return strippedPath
end stripVolName


on IsOSX()
      tell application "Finder"
              set vers to the version as text
                if second character of vers is equal to "." then
                       set vers to "0" & vers
         end if
         return vers > 10 or vers = 10
  end tell
end IsOSX


-- the following will build the stationery project in the lib directory.
-- CreateStationeryProject(gStationeryName, gDistribRoot & gBuildDir & ":" & gStationeryName & ":", gMWCWfolder)


-- the following are needed to run this script by itself,
-- they are not needed when it is called by another script.

--
-- Global variables
--

global gStartupDisk
global gHomeDir
global gMWroot
global gDistribRoot
global gBuildDir
global gRsrcsDir
global gStationeryName
global gDirsToCreate

on ResolveAlias(pathname)
     tell application "Finder"
              if exists folder pathname then return pathname & ":"
           if exists alias file pathname then return the original item of alias file pathname as string
           error "The folder (or alias) '" & pathname & "' doesn't exist."
        end tell
end ResolveAlias

on HomeDir()
        tell application "Finder"
              
               if my IsOSX() then
                     return the home as string
              else
                   return gStartupDisk
            end if
         
       end tell
end HomeDir

on ModuleRoot()
  set modRoot to ""
      try
            set modRoot to ResolveAlias(gMWroot & "ncbi")
  on error
               try
                    set modRoot to ResolveAlias(gHomeDir & "ncbi")
         end try
        end try
        
       return modRoot
end ModuleRoot

on MWRootDir()
  
       set mwRoot to ""
       set mwLocations to {gStartupDisk, gStartupDisk & "Applications:", gStartupDisk & "Applications (Mac OS 9):", Â
         gHomeDir, gHomeDir & "Applications:", gHomeDir & "Applications (Mac OS 9):"}
   repeat with mwVersion from 8 to 9
              set dirName to "Metrowerks CodeWarrior " & mwVersion & ".0"
            repeat with mwLoc in mwLocations
                       try
                            set mwRoot to ResolveAlias(mwLoc & dirName)
                            return mwRoot
                  end try
                end repeat
     end repeat
     
       error "Can't find the Metrowerks CodeWarrior folder."
  
end MWRootDir

on SetGlobals()
        tell application "Finder"
              
               set gStartupDisk to startup disk as string
             set gHomeDir to my HomeDir()
           set gMWroot to my MWRootDir()
          set gMWCWfolder to gMWroot & "Metrowerks CodeWarrior:"
         set gDistribRoot to my ModuleRoot()
            set gRsrcsDir to gDistribRoot & "link:macmet:"
         
               if pCreateLibrary then
                 set gStationeryName to "LibraryStationery"
                     set gBuildDir to "lib"
         else
                   set gStationeryName to "ApplicationStationery"
                 set gBuildDir to "build"
               end if
         
               set gDirsToCreate to {Â
                        {relPath:"", name:gBuildDir}, Â
                        {relPath:gBuildDir, name:gStationeryName}}
             
       end tell
end SetGlobals

on CreateFolders()
    tell application "Finder"
              
               repeat with i in gDirsToCreate
                 set pth to relPath of i
                        if pth is not "" then set pth to pth & ":"
                     
                       if not (exists folder (gDistribRoot & pth & i's name)) then
                            make new folder at folder (gDistribRoot & pth) with properties {name:i's name}
                 end if
         end repeat
             
       end tell
end CreateFolders

source navigation ]   [ diff markup ]   [ identifier search ]   [ freetext search ]   [ file search ]  

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.