Ticket #1116: 0002-Fix-OS-X-build-issues.patch

File 0002-Fix-OS-X-build-issues.patch, 8.9 KB (added by MattArsenault, 13 years ago)
  • api/Makefile.am

    From 5591c64687ff9de47595027e9bc6c2296898780a Mon Sep 17 00:00:00 2001
    From: Matt Arsenault <arsenm2@rpi.edu>
    Date: Wed, 22 Jun 2011 18:17:13 -0400
    Subject: [PATCH 2/6] Fix OS X build issues
    
    ---
     api/Makefile.am  |    4 +-
     api/mac_icon.cpp |   81 ++++++++++++++++++++++++++++++++---------------------
     lib/coproc.h     |    2 +-
     3 files changed, 52 insertions(+), 35 deletions(-)
    
    diff --git a/api/Makefile.am b/api/Makefile.am
    index 04fcf78..8d5b4c7 100644
    a b libboinc_api_la_LDFLAGS = -L$(libdir) -rpath $(libdir) -version-number $(LIBBOIN 
    3939if BUILD_GRAPHICS_API
    4040lib_LTLIBRARIES += libboinc_graphics2.la
    4141libboinc_graphics2_la_SOURCES = $(graphics2_files)
    42 libboinc_graphics2_la_CPPFLAGS = -I$(top_srcdir)/lib 
     42libboinc_graphics2_la_CPPFLAGS = -I$(top_srcdir)/lib
    4343libboinc_graphics2_la_LDFLAGS = -L$(libdir) -rpath $(libdir) -version-number $(LIBBOINC_VERSION)
    4444endif #BUILD_GRAPHICS_API
    4545
    pkginclude_HEADERS = \ 
    5151        gutil.h
    5252endif ## INSTALL_HEADERS
    5353
    54 # Some OSs may not prefix libraries with lib. 
     54# Some OSs may not prefix libraries with lib.
    5555# For example OS2
    5656if OS_OS2
    5757LIBBOINC_API_STATIC=boinc_api.${LIBEXT}
  • api/mac_icon.cpp

    diff --git a/api/mac_icon.cpp b/api/mac_icon.cpp
    index e534bb8..64d438f 100644
    a b  
    1616// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
    1717
    1818/* Mac-specific code to display custom icon for science application (optional)
    19    adapted from code written by Bernd Machenschalk.  Used with permission of the 
     19   adapted from code written by Bernd Machenschalk.  Used with permission of the
    2020   Einstein@home project.
    21    
     21
    2222    To use this code:
    2323    1. Create a *.icns file using "/Developer/Applications/utilities/Icon Composer.app"
    24     2. Convert the *.icns file to an app_icon.h file as follows: in Terminal, run 
    25       "MakeAppIcon_h <source_file> <dest_file>".  (The MakeAppIcon_h command-line utility 
     24    2. Convert the *.icns file to an app_icon.h file as follows: in Terminal, run
     25      "MakeAppIcon_h <source_file> <dest_file>".  (The MakeAppIcon_h command-line utility
    2626      is built by the Mac boinc XCode project.)
    2727    3. In the science application's main(), #include "app_icon.h" and call:
    2828        setMacIcon(argv[0], MacAppIconData, sizeof(MacAppIconData));
    char MacPListData[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" 
    5252    return(e); } }
    5353
    5454// Adds the specified resource to the file given as an argument.
    55 int setMacRsrcForFile(char *filename, char *rsrcData, long rsrcSize, 
    56                             OSType rsrcType, int rsrcID, StringPtr rsrcName) {
     55int setMacRsrcForFile(char *filename, char *rsrcData, long rsrcSize,
     56                            OSType rsrcType, int rsrcID, ConstStringPtr rsrcName) {
    5757    OSErr oserr;                    /* stores an OS error code */
    5858//    FSSpec fsspec;                  /* FileSpec */
    5959    HFSUniStr255 forkName;          /* Unicode name of resource fork "RESOURCE_FORK" */
    int setMacRsrcForFile(char *filename, char *rsrcData, long rsrcSize, 
    6262    short rref;                     /* Resource Reference */
    6363    Handle hand;
    6464    int retry;
    65    
     65
    6666    /* get finder spec for this file */
    6767    CHECK_OSERR((int)FSPathMakeRef((StringPtr)filename, &fsref, NULL));
    6868//    CHECK_OSERR(FSGetCatalogInfo(&fsref, nil, NULL, NULL, &fsspec, NULL));
    6969
    7070    /* Open the resource fork for writing, create it if it does not exist.
    71         On a dual-processor system, the other cpu may have the resource fork 
     71        On a dual-processor system, the other cpu may have the resource fork
    7272        open for writing, so if we fail we wait and retry.
    7373    */
    7474    for (retry=0;retry<5;retry++) {
    int setMacRsrcForFile(char *filename, char *rsrcData, long rsrcSize, 
    9292        }
    9393        // We may not have permissions to set resources in debug runs
    9494        if ((oserr == noErr) || (oserr == wrPermErr) || (oserr == permErr))
    95             break; 
     95            break;
    9696        sleep (1);
    9797    };
    9898
    9999    if (oserr)
    100100        return oserr; // give up after 5 seconds
    101        
     101
    102102    /* add the resource if not already present */
    103103    if (!GetResource(rsrcType, rsrcID)) { /* if resource not found */
    104104        oserr = PtrToHand(rsrcData, &hand, rsrcSize);
    void getPathToThisApp(char* pathBuf, size_t bufSize) { 
    145145    pid_t myPID = getpid();
    146146    int i;
    147147    struct stat stat_buf;
    148    
     148
    149149    strcpy(pathBuf, GRAPHICS_APP_FILENAME);
    150150    if (!stat(pathBuf, &stat_buf)) {
    151151       // stat() returns zero on success
    152152       return;
    153153    }
    154    
     154
    155155    *pathBuf = 0;    // in case of failure
    156    
    157     // Before launching this project application, the BOINC client set the 
    158     // current directory to the slot directory which contains this application 
    159     // (or the soft-link to it.)  So all we need for the path to this 
    160     // application is the file name.  We use the -c option so ps strips off 
     156
     157    // Before launching this project application, the BOINC client set the
     158    // current directory to the slot directory which contains this application
     159    // (or the soft-link to it.)  So all we need for the path to this
     160    // application is the file name.  We use the -c option so ps strips off
    161161    // any command-line arguments for us.
    162162    sprintf(buf, "ps -wcp %d -o command=", myPID);
    163163    f = popen(buf,  "r");
    void getPathToThisApp(char* pathBuf, size_t bufSize) { 
    167167    PersistentFGets(pathBuf, bufSize, f);  // Get the UNIX command which ran us
    168168    pclose(f);
    169169
    170     c = strstr(pathBuf, " -"); 
     170    c = strstr(pathBuf, " -");
    171171    if (c)
    172172        *c = 0;     // Strip off any command-line arguments
    173        
     173
    174174    for (i=strlen(pathBuf)-1; i>=0; --i) {
    175175        if (pathBuf[i] <= ' ')
    176176            pathBuf[i] = 0;  // Strip off trailing spaces, newlines, etc.
    void getPathToThisApp(char* pathBuf, size_t bufSize) { 
    179179    }
    180180}
    181181
    182 
    183 // Adds plst resource 0 to the file given as an argument.  This
    184 // identifies the application to the OS as an NSUIElement, so
    185 // that the application does not show in the Dock and it has no
     182// Adds plst resource 0 to the file given as an argument.  This
     183// identifies the application to the OS as an NSUIElement, so
     184// that the application does not show in the Dock and it has no
    186185// menu bar.
    187186int setMacPList() {
     187    int rc;
    188188    char path[1024], resolvedPath[1024];
    189     StringPtr rsrcName = (StringPtr)"\pApplication PList";
     189    const char plistStr[] = "Application PList";
     190    CFStringRef plistCFStr = CFStringCreateWithCString(kCFAllocatorDefault, plistStr, kCFStringEncodingMacRoman);
     191    ConstStringPtr rsrcName = CFStringGetPascalStringPtr(plistCFStr, kCFStringEncodingMacRoman);
     192    if (!rsrcName) {
     193        return -2;
     194    }
    190195
    191     // If resource already exists, don't call getPathToThisApp() 
     196    // If resource already exists, don't call getPathToThisApp()
    192197    // which leaves a zombie process.
    193     if (GetResource('plst', 0)) { 
     198    if (GetResource('plst', 0)) {
    194199        return 0;
    195200    }
    196    
     201
    197202    getPathToThisApp(path, sizeof(path));
    198203    if (path[0] == 0)
    199204        return -1; // Should never happen
    200    
     205
    201206    setMacRsrcForFile(path, MacPListData, sizeof(MacPListData), 'plst', 0, rsrcName);
    202207    boinc_resolve_filename(path, resolvedPath, sizeof(resolvedPath));
    203     return(setMacRsrcForFile(resolvedPath, MacPListData, sizeof(MacPListData), 'plst', 0, rsrcName));
     208    rc = setMacRsrcForFile(resolvedPath, MacPListData, sizeof(MacPListData), 'plst', 0, rsrcName);
     209
     210    CFRelease(plistCFStr);
     211    return rc;
    204212}
    205213
    206214
    207215// Adds icns resource to the file given as an argument.
    208 // If the file is a soft link, also adds icns resource to the resolved flle. 
     216// If the file is a soft link, also adds icns resource to the resolved flle.
    209217// Typically called from a main() with argv[0] to attach resources to itself */
    210218int setMacIcon(char *filename, char *iconData, long iconSize) {
     219    int rc;
    211220    char path[1024];
    212     StringPtr rsrcName = (StringPtr)"\pApplication icons";
     221    const char iconStr[] = "Application icons";
     222    CFStringRef iconCFStr = CFStringCreateWithCString(kCFAllocatorDefault, iconStr, kCFStringEncodingMacRoman);
     223    ConstStringPtr rsrcName = CFStringGetPascalStringPtr(iconCFStr, kCFStringEncodingMacRoman);  // FIXME: How to release this?
     224    if (!rsrcName) {
     225        return -2;
     226    }
    213227
    214228    setMacRsrcForFile(filename, iconData, iconSize, 'icns', RESIDICON, rsrcName);
    215229    boinc_resolve_filename(filename, path, sizeof(path));
    216     return(setMacRsrcForFile(path, iconData, iconSize, 'icns', RESIDICON, rsrcName));
     230    rc = setMacRsrcForFile(path, iconData, iconSize, 'icns', RESIDICON, rsrcName);
     231
     232    CFRelease(iconCFStr);
     233    return rc;
    217234}
  • lib/coproc.h

    diff --git a/lib/coproc.h b/lib/coproc.h
    index 771c081..89371c6 100644
    a b struct COPROCS { 
    334334            }
    335335        }
    336336    }
    337     void COPROCS::clear() {
     337    void clear() {
    338338        n_rsc = 0;
    339339        for (int i=0; i<MAX_RSC; i++) {
    340340            coprocs[i].clear();