Detect Mac OS X user path using Mac OS X Foundation API. Modified the build system to build and link Objective-C code.
git-svn-id: http://voip.null.ro/svn/yate@4991 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
parent
3d323905a0
commit
df8496ae28
25
configure.in
25
configure.in
|
@ -509,6 +509,31 @@ AC_CHECK_FUNCS([regcomp], , [INTERNAL_REGEX=yes])
|
|||
fi
|
||||
AC_SUBST(INTERNAL_REGEX)
|
||||
|
||||
# check for Mac OS X Support
|
||||
MACOSX_INC=""
|
||||
HAVE_MACOSX_SUPPORT=no
|
||||
OBJCFLAGS=""
|
||||
if [[ "x$uname_os" = "xDarwin" ]]; then
|
||||
save_CPPFLAGS=$CPPFLAGS
|
||||
CPPFLAGS="$CPPFLAGS -x objective-c++"
|
||||
AC_MSG_CHECKING([for Mac OS X Objective-C support])
|
||||
AC_TRY_COMPILE([#import <Foundation/Foundation.h>],
|
||||
[
|
||||
[NSFileManager defaultManager]
|
||||
],
|
||||
[
|
||||
HAVE_MACOSX_SUPPORT="yes"
|
||||
OBJCFLAGS="-x objective-c++"
|
||||
MACOSX_INC="-DHAVE_MACOSX_SUPPORT"],[]
|
||||
)
|
||||
AC_MSG_RESULT([$HAVE_MACOSX_SUPPORT])
|
||||
CPPFLAGS=$save_CPPFLAGS
|
||||
fi
|
||||
AC_SUBST(MACOSX_INC)
|
||||
AC_SUBST(HAVE_MACOSX_SUPPORT)
|
||||
AC_SUBST(OBJCFLAGS)
|
||||
|
||||
|
||||
HAVE_PGSQL=no
|
||||
PGSQL_INC=""
|
||||
AC_ARG_WITH(libpq,AC_HELP_STRING([--with-libpq=DIR],[use Postgress SQL from DIR (default /usr)]),[ac_cv_use_libpq=$withval],[ac_cv_use_libpq=/usr])
|
||||
|
|
|
@ -54,13 +54,21 @@ __declspec(dllimport) BOOL WINAPI SHGetSpecialFolderPathA(HWND,LPSTR,INT,BOOL);
|
|||
typedef void* HMODULE;
|
||||
#define PATH_SEP "/"
|
||||
#ifndef CFG_DIR
|
||||
#ifdef HAVE_MACOSX_SUPPORT
|
||||
#define CFG_DIR "Yate"
|
||||
#else
|
||||
#define CFG_DIR ".yate"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static int s_childsig = 0;
|
||||
|
||||
#endif // _WINDOWS
|
||||
|
||||
#ifdef HAVE_MACOSX_SUPPORT
|
||||
#include "MacOSXUtils.h"
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
|
@ -349,6 +357,12 @@ static void initUsrPath(String& path, const char* newPath = 0)
|
|||
char szPath[MAX_PATH];
|
||||
if (SHGetSpecialFolderPathA(NULL,szPath,CSIDL_APPDATA,TRUE))
|
||||
path = szPath;
|
||||
#elif defined(HAVE_MACOSX_SUPPORT)
|
||||
MacOSXUtils::applicationSupportPath(path);
|
||||
if (path.null()) {
|
||||
Debug(DebugMild,"Could not get system user path on MacOS X, setting it to $(HOME)");
|
||||
path = ::getenv("HOME");
|
||||
}
|
||||
#else
|
||||
path = ::getenv("HOME");
|
||||
#endif
|
||||
|
|
|
@ -6,6 +6,7 @@ DEBUG :=
|
|||
|
||||
CC := @CC@ -Wall
|
||||
CXX := @CXX@ -Wall
|
||||
OBJCXX := @CXX@ -Wall
|
||||
SED := sed
|
||||
DEFS :=
|
||||
LIBAUX:= @DLOPEN_LIB@ @LIBS@
|
||||
|
@ -16,6 +17,7 @@ CPPFLAGS := @CFLAGS@ @MODULE_CPPFLAGS@ @INLINE_FLAGS@
|
|||
LDFLAGS:= @LDFLAGS@
|
||||
SONAME_OPT := @SONAME_OPT@
|
||||
LDCONFIG:=true
|
||||
OBJCFLAGS := @OBJCFLAGS@
|
||||
|
||||
MKDEPS := ../config.status
|
||||
YLIB:= libyate.so.@PACKAGE_VERSION@
|
||||
|
@ -36,6 +38,7 @@ LIBOBJS := $(CLSOBJS) $(ENGOBJS) $(TELOBJS) $(CLIOBJS)
|
|||
CLEANS = $(LIBOBJS) core
|
||||
CCOMPILE = $(CC) $(DEFS) $(DEBUG) $(INCLUDES) $(CFLAGS)
|
||||
COMPILE = $(CXX) $(DEFS) $(DEBUG) $(INCLUDES) $(CPPFLAGS)
|
||||
OBJCCOMPILE = $(OBJCXX) $(OBJCFLAGS) $(DEFS) $(DEBUG) $(INCLUDES) $(CPPFLAGS)
|
||||
LINK = $(CXX) $(LDFLAGS)
|
||||
|
||||
ifeq (@INTERNAL_REGEX@,yes)
|
||||
|
@ -45,6 +48,15 @@ else
|
|||
REGEX_INC:=
|
||||
endif
|
||||
|
||||
ifeq (@HAVE_MACOSX_SUPPORT@,yes)
|
||||
MACOSX_INC:= @MACOSX_INC@ -I@top_srcdir@/engine/macosx
|
||||
MACOSX_LIB:= -lobjc -framework Foundation
|
||||
LIBOBJS := $(LIBOBJS) MacOSXUtils.o
|
||||
else
|
||||
MACOSX_INC:=
|
||||
MACOSX_LIB:=
|
||||
endif
|
||||
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
|
||||
|
@ -77,7 +89,7 @@ strip: all
|
|||
-strip --strip-debug --discard-locals ../$(YLIB)
|
||||
|
||||
Engine.o: @srcdir@/Engine.cpp $(MKDEPS) $(EINC) ../yateversn.h ../yatepaths.h
|
||||
$(COMPILE) @FDSIZE_HACK@ @HAVE_PRCTL@ @HAVE_GETCWD@ -c $<
|
||||
$(COMPILE) @FDSIZE_HACK@ @HAVE_PRCTL@ @HAVE_GETCWD@ $(MACOSX_INC) -c $<
|
||||
|
||||
Channel.o: @srcdir@/Channel.cpp $(MKDEPS) $(PINC)
|
||||
$(COMPILE) -c $<
|
||||
|
@ -115,6 +127,9 @@ String.o: @srcdir@/String.cpp $(MKDEPS) $(CINC)
|
|||
regex.o: @top_srcdir@/engine/regex/regex.c $(MKDEPS)
|
||||
$(CCOMPILE) -DSTDC_HEADERS $(REGEX_INC) -c $<
|
||||
|
||||
MacOSXUtils.o: @top_srcdir@/engine/macosx/MacOSXUtils.mm $(MKDEPS)
|
||||
$(OBJCCOMPILE) $(MACOSX_INC) -c $<
|
||||
|
||||
%.o: @srcdir@/%.cpp $(MKDEPS) $(EINC)
|
||||
$(COMPILE) -c $<
|
||||
|
||||
|
@ -122,4 +137,4 @@ Makefile: @srcdir@/Makefile.in $(MKDEPS)
|
|||
cd .. && ./config.status
|
||||
|
||||
../$(YLIB): $(LIBOBJS) $(LIBS)
|
||||
$(LINK) -o $@ $(SONAME_OPT)$(YLIB) $^ $(LIBTHR) $(LIBAUX) @RESOLV_LIB@
|
||||
$(LINK) -o $@ $(SONAME_OPT)$(YLIB) $^ $(LIBTHR) $(LIBAUX) $(MACOSX_LIB) @RESOLV_LIB@
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* MacOSXUtils.h
|
||||
* This file is part of the YATE Project http://YATE.null.ro
|
||||
*
|
||||
* Classes for interfacing with Mac OS X API
|
||||
*
|
||||
* Yet Another Telephony Engine - a fully featured software PBX and IVR
|
||||
* Copyright (C) 2004-2012 Null Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __MACOSXUTILS_H
|
||||
#define __MACOSXUTILS_H
|
||||
|
||||
#include <yatecbase.h>
|
||||
|
||||
namespace TelEngine {
|
||||
|
||||
class YATE_API MacOSXUtils
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Directory search paths
|
||||
*/
|
||||
enum DirectoryPath {
|
||||
ApplicationDirectory = 1,
|
||||
DemoApplicationDirectory,
|
||||
DeveloperApplicationDirectory,
|
||||
AdminApplicationDirectory,
|
||||
LibraryDirectory,
|
||||
DeveloperDirectory,
|
||||
UserDirectory,
|
||||
DocumentationDirectory,
|
||||
DocumentDirectory,
|
||||
CoreServiceDirectory,
|
||||
AutosavedInformationDirectory,
|
||||
DesktopDirectory,
|
||||
CachesDirectory,
|
||||
ApplicationSupportDirectory,
|
||||
DownloadsDirectory,
|
||||
InputMethodsDirectory,
|
||||
MoviesDirectory,
|
||||
MusicDirectory,
|
||||
PicturesDirectory,
|
||||
PrinterDescriptionDirectory,
|
||||
SharedPublicDirectory,
|
||||
PreferencePanesDirectory,
|
||||
ItemReplacementDirectory,
|
||||
AllApplicationsDirectory,
|
||||
AllLibrariesDirectory,
|
||||
};
|
||||
|
||||
/**
|
||||
* Domains for searching directory paths
|
||||
*/
|
||||
enum Domain {
|
||||
UserDomainMask = 1,
|
||||
LocalDomainMask = 2,
|
||||
NetworkDomainMask = 4,
|
||||
SystemDomainMask = 8,
|
||||
AllDomainsMask = 0x0ffff,
|
||||
};
|
||||
|
||||
/**
|
||||
* Get path of the Application Support directory for the user
|
||||
* @param path String into which the determined path will go
|
||||
* @param appName Name of directory to create in the Application Support
|
||||
*/
|
||||
static void applicationSupportPath(String& path, const char* appName = 0);
|
||||
|
||||
/**
|
||||
* Get path of a given type of directory in a certain domain
|
||||
* @param path String into which the determined path will go
|
||||
* @param dirPath The type of directory path to be sought
|
||||
* @param domain Mask containing the domains where the type of directory is to be sought
|
||||
* @param append Name of directory to create in the searched directory
|
||||
* @param append True if the directory is to be created if it not exists
|
||||
*/
|
||||
static void getPath(String& path, DirectoryPath dirPath, Domain domain, const char* append = 0, bool createDir = true);
|
||||
};
|
||||
|
||||
}; // namespece TelEngine
|
||||
|
||||
#endif /* __MACOSXUTILS_H */
|
||||
|
||||
/* vi: set ts=8 sw=4 sts=4 noet: */
|
|
@ -0,0 +1,210 @@
|
|||
/**
|
||||
* MacOSXUtils.mm
|
||||
* This file is part of the YATE Project http://YATE.null.ro
|
||||
*
|
||||
* Yet Another Telephony Engine - a fully featured software PBX and IVR
|
||||
* Copyright (C) 2004-2012 Null Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#include <MacOSXUtils.h>
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
using namespace TelEngine;
|
||||
|
||||
// utility function to get const char* from NSString*
|
||||
static const char* fromNSString(NSString* str)
|
||||
{
|
||||
if (!str)
|
||||
return 0;
|
||||
return [str cStringUsingEncoding:NSUTF8StringEncoding];
|
||||
}
|
||||
|
||||
// utility function to get a NSString from a const char*
|
||||
static NSString* toNSString(const char* chars)
|
||||
{
|
||||
if (!chars)
|
||||
return 0;
|
||||
return [NSString stringWithCString:chars encoding:NSUTF8StringEncoding];
|
||||
}
|
||||
|
||||
// extend the NSFileManager class
|
||||
@interface NSFileManager (MacOSXUtils)
|
||||
|
||||
/**
|
||||
* Get path of the given directory type
|
||||
* @param directory Type of directory to search for
|
||||
* @param domainMask Mask specifying domains in which to search for directory
|
||||
* @param create True to create directory if it doesn't exist
|
||||
* @param pathComponent What to append to the directory path
|
||||
* @return The path to the searched directory
|
||||
*/
|
||||
-(NSString*)pathForDirectory:(NSSearchPathDirectory)directory
|
||||
inDomain:(NSSearchPathDomainMask)domainMask
|
||||
createDir:(bool)create
|
||||
byAppending:(NSString*)pathComponent;
|
||||
|
||||
/**
|
||||
* Get the path to the ~/Library/Application Support directory by appending to it the given appName. Create if it doesn't exist
|
||||
*/
|
||||
-(NSString*)applicationSupportDirectoryForApp:(NSString*)appName;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSFileManager (MacOSXUtils)
|
||||
|
||||
-(NSString*)pathForDirectory:(NSSearchPathDirectory)directory
|
||||
inDomain:(NSSearchPathDomainMask)domainMask
|
||||
createDir:(bool)create
|
||||
byAppending:(NSString*)pathComponent
|
||||
{
|
||||
NSArray* paths = NSSearchPathForDirectoriesInDomains(directory,domainMask,YES);
|
||||
if ([paths count] == 0) {
|
||||
Debug(DebugInfo,"Failed to get path for directory='%u' in domains='%u'",(unsigned int)directory,(unsigned int)domainMask);
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSString* path = [paths objectAtIndex:0];
|
||||
|
||||
if (pathComponent && [pathComponent length])
|
||||
path = [path stringByAppendingPathComponent:pathComponent];
|
||||
|
||||
NSError *error = nil;
|
||||
if (!([self createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error])) {
|
||||
Debug(DebugInfo,"Failed to create path '%s' error code = %d",fromNSString(path),(int)[error code]);
|
||||
return nil;
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
-(NSString*)applicationSupportDirectoryForApp:(NSString*)appName
|
||||
{
|
||||
NSString *result = [self pathForDirectory:NSApplicationSupportDirectory
|
||||
inDomain:NSUserDomainMask
|
||||
createDir:YES
|
||||
byAppending:appName];
|
||||
return result;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
static NSSearchPathDirectory translateDirectory(MacOSXUtils::DirectoryPath dirPath)
|
||||
{
|
||||
switch (dirPath) {
|
||||
case MacOSXUtils::ApplicationDirectory:
|
||||
return NSApplicationDirectory;
|
||||
case MacOSXUtils::DemoApplicationDirectory:
|
||||
return NSDemoApplicationDirectory;
|
||||
case MacOSXUtils::DeveloperApplicationDirectory:
|
||||
return NSDeveloperApplicationDirectory;
|
||||
case MacOSXUtils::AdminApplicationDirectory:
|
||||
return NSAdminApplicationDirectory;
|
||||
case MacOSXUtils::LibraryDirectory:
|
||||
return NSLibraryDirectory;
|
||||
case MacOSXUtils::DeveloperDirectory:
|
||||
return NSDeveloperDirectory;
|
||||
case MacOSXUtils::UserDirectory:
|
||||
return NSUserDirectory;
|
||||
case MacOSXUtils::DocumentationDirectory:
|
||||
return NSDocumentationDirectory;
|
||||
#ifdef MAC_OS_X_VERSION_10_6
|
||||
case MacOSXUtils::DocumentDirectory:
|
||||
return NSDocumentDirectory;
|
||||
#endif
|
||||
case MacOSXUtils::CoreServiceDirectory:
|
||||
return NSCoreServiceDirectory;
|
||||
#ifdef MAC_OS_X_VERSION_10_6
|
||||
case MacOSXUtils::AutosavedInformationDirectory:
|
||||
return NSAutosavedInformationDirectory;
|
||||
#endif
|
||||
case MacOSXUtils::DesktopDirectory:
|
||||
return NSDesktopDirectory;
|
||||
case MacOSXUtils::CachesDirectory:
|
||||
return NSCachesDirectory;
|
||||
case MacOSXUtils::ApplicationSupportDirectory:
|
||||
return NSApplicationSupportDirectory;
|
||||
case MacOSXUtils::DownloadsDirectory:
|
||||
return NSDownloadsDirectory;
|
||||
#ifdef MAC_OS_X_VERSION_10_6
|
||||
case MacOSXUtils::InputMethodsDirectory:
|
||||
return NSInputMethodsDirectory;
|
||||
case MacOSXUtils::MoviesDirectory:
|
||||
return NSMoviesDirectory;
|
||||
case MacOSXUtils::MusicDirectory:
|
||||
return NSMusicDirectory;
|
||||
case MacOSXUtils::PicturesDirectory:
|
||||
return NSPicturesDirectory;
|
||||
case MacOSXUtils::PrinterDescriptionDirectory:
|
||||
return NSPrinterDescriptionDirectory;
|
||||
case MacOSXUtils::SharedPublicDirectory:
|
||||
return NSSharedPublicDirectory;
|
||||
case MacOSXUtils::PreferencePanesDirectory:
|
||||
return NSPreferencePanesDirectory;
|
||||
case MacOSXUtils::ItemReplacementDirectory:
|
||||
return NSItemReplacementDirectory;
|
||||
#endif
|
||||
case MacOSXUtils::AllApplicationsDirectory:
|
||||
return NSAllApplicationsDirectory;
|
||||
case MacOSXUtils::AllLibrariesDirectory:
|
||||
return NSAllLibrariesDirectory;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static NSSearchPathDomainMask translateDomain(unsigned int domainMask)
|
||||
{
|
||||
NSSearchPathDomainMask mask = 0;
|
||||
if (domainMask & MacOSXUtils::UserDomainMask)
|
||||
mask |= NSUserDomainMask;
|
||||
if (domainMask & MacOSXUtils::LocalDomainMask)
|
||||
mask |= NSLocalDomainMask;
|
||||
if (domainMask & MacOSXUtils::NetworkDomainMask)
|
||||
mask |= NSNetworkDomainMask;
|
||||
if (domainMask & MacOSXUtils::SystemDomainMask)
|
||||
mask |= NSSystemDomainMask;
|
||||
if (domainMask & MacOSXUtils::AllDomainsMask)
|
||||
mask |= NSAllDomainsMask;
|
||||
|
||||
return mask;
|
||||
}
|
||||
|
||||
void MacOSXUtils::applicationSupportPath(String& path, const char* appName)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
NSString* app = toNSString(appName);
|
||||
|
||||
NSString* pth = [[NSFileManager defaultManager] applicationSupportDirectoryForApp:app];
|
||||
path = fromNSString(pth);
|
||||
[pool release];
|
||||
}
|
||||
|
||||
void MacOSXUtils::getPath(String& path, DirectoryPath dirPath, Domain domain, const char* append, bool createDir)
|
||||
{
|
||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||
NSSearchPathDirectory dir = translateDirectory(dirPath);
|
||||
NSSearchPathDomainMask domainMask = translateDomain(domain);
|
||||
|
||||
NSString* pth = [[NSFileManager defaultManager] pathForDirectory:dir inDomain:domainMask createDir:createDir byAppending:toNSString(append)];
|
||||
path = fromNSString(pth);
|
||||
[pool release];
|
||||
}
|
Loading…
Reference in New Issue