Darwin support

This commit is contained in:
Alexey Pelykh 2012-06-21 07:24:17 +03:00
parent b89f94ff70
commit 1a5f61cec4
10 changed files with 225 additions and 77 deletions

View file

@ -15,7 +15,7 @@ CXXFLAGS_debug := -g$(DEBUG_INFO_FORMAT) -O0
CFLAGS_debug := -g$(DEBUG_INFO_FORMAT) -O0
CXXFLAGS_release := -O2
CFLAGS_release := -O2
OUTPUT_DIR_PREFIX = ../lib/$(TARGET)-$(ARCH)
BUILD_DIR_PREFIX = ../build/$(TARGET)-$(ARCH)
@ -43,8 +43,8 @@ debug: $(BUILD_DIR_PREFIX)-debug/$(LIBNAME).$(LIBTYPE)
# Clean removes all objects
clean:
$(RM) -r build-release/obj-$(TARGET)-$(ARCH)/
$(RM) -r build-debug/obj-$(TARGET)-$(ARCH)/
$(RM) -r build-release/obj-$(TARGET)-$(ARCH)
$(RM) -r build-debug/obj-$(TARGET)-$(ARCH)
$(RM) -r build-release/$(TARGET)-$(ARCH)
$(RM) -r build-debug/$(TARGET)-$(ARCH)
$(RM) -r $(BUILD_DIR_PREFIX)-release
@ -86,7 +86,7 @@ build-%/$(TARGET)-$(ARCH)/$(LIBNAME).$(STATICLIB_EXT): $$(addprefix build-%/,$(O
.SECONDEXPANSION:
build-%/$(TARGET)-$(ARCH)/$(LIBNAME).$(DYNAMICLIB_EXT): $$(addprefix build-%/,$(OBJECTS))
@mkdir -p `dirname $@`
$(CXX) -shared -o $@ $(addprefix build-$*/,$(OBJECTS)) $(LDFLAGS) -L$(BUILD_DIR_PREFIX)-$* $(LDLIBS)
$(CXX) $(DYNAMICLIB_FLAGS) -o $@ $(addprefix build-$*/,$(OBJECTS)) $(LDFLAGS) -L$(BUILD_DIR_PREFIX)-$* $(LDLIBS)
# This is for copying binary files to build directory
$(BUILD_DIR_PREFIX)-%/$(LIBNAME).$(LIBTYPE): build-%/$(TARGET)-$(ARCH)/$(LIBNAME).$(LIBTYPE)

View file

@ -1,15 +1,19 @@
# Make default definitions
ifndef $(ARCH)
ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN)
# Cygwin returns 'unknown'
ARCH := i386
else
ARCH := $(shell uname -i)
# Autodetermine target if not set
ifeq ($(TARGET),)
ifeq ($(shell uname),Darwin)
TARGET := darwin
else ifeq ($(shell uname),Linux)
TARGET := linux
else ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN)
TARGET := windows
else ifeq ($(findstring MINGW,$(shell uname)),MINGW)
TARGET := windows
endif
endif
############################################
############# NACL ### TARGET
# Google NaCl target
ifeq ($(TARGET),nacl)
ifndef NACL_SDK_ROOT
$(error Set NACL_SDK_ROOT environment variable)
@ -18,8 +22,8 @@ ifeq ($(TARGET),nacl)
NACL_SDK_ROOT := $(shell cygpath -u "$(NACL_SDK_ROOT)")
endif
OSNAME:=$(shell python $(NACL_SDK_ROOT)/tools/getos.py)
NACL_TOOLCHAIN:=$(abspath $(NACL_SDK_ROOT)/toolchain/$(OSNAME)_x86_newlib)
OSNAME := $(shell python $(NACL_SDK_ROOT)/tools/getos.py)
NACL_TOOLCHAIN := $(abspath $(NACL_SDK_ROOT)/toolchain/$(OSNAME)_x86_newlib)
CXX := $(NACL_TOOLCHAIN)/bin/i686-nacl-g++
CC := $(NACL_TOOLCHAIN)/bin/i686-nacl-gcc
AR := $(NACL_TOOLCHAIN)/bin/i686-nacl-ar
@ -29,59 +33,111 @@ ifeq ($(TARGET),nacl)
LDLIBS += -lppapi_cpp -lppapi
GLOBAL_INCLUDES := -I../zlib/zlib_library -I$(NACL_TOOLCHAIN)/i686-nacl/usr/include
ZLIB_BUILD := defined
CFLAGS := -D__int64="long long"
CXXFLAGS := -D__int64="long long"
else
CFLAGS += -D__int64="long long" -std=gnu++0x
CXXFLAGS += -D__int64="long long" -std=gnu++0x
DYNAMICLIB_FLAGS := -shared
############################################
### EVERYTHING ELSE REQUIRES JAVA_HOME #####
ifndef JAVA_HOME
$(error Set JAVA_HOME environment variable)
endif
ifeq ($(TARGET),)
ifeq ($(shell uname),Darwin)
TARGET := darwin
# MacOSX/Darwin target
else ifeq ($(TARGET),darwin)
MACOSX_TOOLCHAIN_ROOT := /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer
MACOSX_SDK := $(IOS_TOOLCHAIN_ROOT)/SDKs/MacOSX10.6.sdk/
ifeq ($(JAVA_HOME),)
JAVA_HOME = /System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers
endif
ifeq ($(shell uname),Linux)
TARGET := linux
endif
ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN)
TARGET := windows
endif
ifeq ($(findstring MINGW,$(shell uname)),MINGW)
TARGET := windows
endif
endif
############################################
####### Windows via MinGW/Linux and MinGW/Cygwin target
ifeq ($(TARGET),windows)
CXX := i686-w64-mingw32-g++
CC := i686-w64-mingw32-gcc
AR := i686-w64-mingw32-ar
# Skia on Darwin supports only i386
ARCH := i386
CXXFLAGS += -arch $(ARCH)
CFLAGS += -arch $(ARCH)
CXX := /usr/bin/g++
CC := /usr/bin/gcc
AR := /usr/bin/ar
GLOBAL_INCLUDES := -I../zlib/zlib_library
ZLIB_BUILD := defined
STATICLIB_EXT := lib
DYNAMICLIB_EXT := dll
LIBRARY_PREFIX := # empty
LDFLAGS := -Wl,--kill-at -static-libstdc++ -static-libgcc
ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN)
# Latest MinGW compiler under Cygwin needs this
CFLAGS := -D__int64="long long"
CXXFLAGS := -D__int64="long long"
endif
############################################
####### DEFAULT LINUX ########## TARGET
else
CXX := g++
CC := gcc
STRIP := strip
STATICLIB_EXT := a
DYNAMICLIB_EXT := so
DYNAMICLIB_EXT := dylib
LIBRARY_PREFIX := lib
DYNAMICLIB_FLAGS := -dynamiclib
############################################
# iOS target
else ifeq ($(TARGET),ios)
IOS_TOOLCHAIN_ROOT := /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer
IOS_SDK := $(IOS_TOOLCHAIN_ROOT)/SDKs/iPhoneOS5.1.sdk/
ifeq ($(ARCH),)
ARCH := armv6
endif
CXX := $(IOS_TOOLCHAIN_ROOT)/usr/bin/arm-apple-darwin10-llvm-g++-4.2
CC := $(IOS_TOOLCHAIN_ROOT)/usr/bin/arm-apple-darwin10-llvm-gcc-4.2
AR := $(IOS_TOOLCHAIN_ROOT)/usr/bin/ar
GLOBAL_INCLUDES := -I../zlib/zlib_library
ZLIB_BUILD := defined
STATICLIB_EXT := a
DYNAMICLIB_EXT := dylib
LIBRARY_PREFIX := lib
CXXFLAGS += -isysroot $(IOS_SDK)
CFLAGS += -isysroot $(IOS_SDK)
DYNAMICLIB_FLAGS := -dynamiclib
LDFLAGS := # empty
# -arch armv6
############################################
### EVERYTHING ELSE REQUIRES JAVA_HOME #####
else
# Just don't ask
ifndef JAVA_HOME
$(error Set JAVA_HOME environment variable)
endif
############################################
# Windows via MinGW/Linux and MinGW/Cygwin target
ifeq ($(TARGET),windows)
CXX := i686-w64-mingw32-g++
CC := i686-w64-mingw32-gcc
AR := i686-w64-mingw32-ar
GLOBAL_INCLUDES := -I../zlib/zlib_library
ZLIB_BUILD := defined
STATICLIB_EXT := lib
DYNAMICLIB_EXT := dll
LIBRARY_PREFIX := # empty
LDFLAGS += -Wl,--kill-at -static-libstdc++ -static-libgcc
CFLAGS += -std=gnu++0x
CXXFLAGS += -std=gnu++0x
DYNAMICLIB_FLAGS := -shared
ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN)
# Latest MinGW compiler under Cygwin needs this
CFLAGS += -D__int64="long long"
CXXFLAGS += -D__int64="long long"
endif
###########################################
# Default target
else
STATICLIB_EXT := a
DYNAMICLIB_EXT := so
LIBRARY_PREFIX := lib
DYNAMICLIB_FLAGS := -shared
CFLAGS += -std=gnu++0x
CXXFLAGS += -std=gnu++0x
endif
endif
############################################
# CPU architectures support
# Make default definitions
ifeq ($(ARCH),)
ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN)
# Cygwin returns 'unknown'
ARCH := i386
else
ARCH := $(shell uname -i)
endif
endif
# Modify compiler flags
ifeq ($(ARCH),i386)
CFLAGS += -m32
CXXFLAGS += -m32
@ -90,8 +146,7 @@ else ifeq ($(ARCH),x86_64)
CFLAGS += -m64
CXXFLAGS += -m64
LDFLAGS += -m64
else ifeq ($(ARCH),armv6)
else
$(error Undefined ARCH $(ARCH))
endif
$(error Undefined ARCH $(ARCH))
endif

View file

@ -2,7 +2,3 @@ chmod +x zlib/configure.sh
cd zlib
./configure.sh
cd ..
chmod +x pthread/configure.sh
cd pthread
./configure.sh
cd ..

View file

@ -6,12 +6,10 @@ LOCAL_PATH = .
include Common.mk
OSMAND_FLAGS = \
-std=c++0x \
-DGOOGLE_PROTOBUF_NO_RTTI \
-DSK_ALLOW_STATIC_GLOBAL_INITIALIZERS=0 \
-DSK_RELEASE \
-DGR_RELEASE=1
OSMAND_FLAGS_WINDOWS = \
-DSK_BUILD_FOR_WIN32 \
-DMINGW_HAS_SECURE_API \
@ -21,14 +19,30 @@ OSMAND_FLAGS_WINDOWS = \
-DSK_SCALAR_IS_FLOAT \
-DSK_CAN_USE_FLOAT \
-DSK_CPU_LENDIAN
OSMAND_FLAGS_MAC = \
-DSK_BUILD_FOR_MAC \
-DSK_USE_CORETEXT \
-DSkUserConfig_DEFINED \
-DPICTURE_VERSION_ICS=1 \
-DPICTURE_VERSION_JB=2 \
-DSK_SCALAR_IS_FLOAT \
-DSK_CAN_USE_FLOAT \
-DSK_CPU_LENDIAN
LIBNAME = $(LIBRARY_PREFIX)osmand
LIBTYPE = $(DYNAMICLIB_EXT)
LDLIBS += -Wl,-Bsymbolic -Wl,--whole-archive -lskia -lpng -Wl,--no-whole-archive -lproto -lft2 -lexpat -lz
ifeq ($(TARGET),darwin)
LDLIBS += --whole-archive -lskia --no-whole-archive -lproto -lft2 -lexpat -lpng -lz
else
LDLIBS += -Wl,-Bsymbolic -Wl,--whole-archive -lskia -lpng -Wl,--no-whole-archive -lproto -lft2 -lexpat -lpng -lz
endif
ifeq ($(TARGET),windows)
LDLIBS += -lwinmm -lgdi32 -lusp10
OSMAND_FLAGS += $(OSMAND_FLAGS_WINDOWS)
else ifeq ($(TARGET),darwin)
OSMAND_FLAGS += $(OSMAND_FLAGS_MAC)
LDLIBS += -framework CoreText -lpthread
else ifeq ($(TARGET),nacl)
LDLIBS += -lpthread
else
@ -40,6 +54,11 @@ ifeq ($(TARGET),nacl)
-DRT_NOT_SUPPORTED
LOCAL_SRC_FILES += \
src/osmand_nacl.cpp
else ifeq ($(TARGET),darwin)
LOCAL_SRC_FILES += \
src/java_wrap.cpp
OSMAND_FLAGS += -I"$(JAVA_HOME)"
else
LOCAL_SRC_FILES += \
src/java_wrap.cpp

View file

@ -3,13 +3,16 @@
#include <SkPath.h>
#include <SkBitmap.h>
#include <SkImageDecoder.h>
#include <time.h>
#include "osmand_log.h"
#if defined(_WIN32)
# include <windows.h>
# include <mmsystem.h>
#elif defined(__APPLE__)
# include <mach/mach_time.h>|
#else
# include <time.h>
#endif
TextDrawInfo::TextDrawInfo(std::string itext)
@ -49,6 +52,9 @@ ElapsedTimer::ElapsedTimer()
, enableFlag(true)
, run(false)
{
#if defined(__APPLE__)
mach_timebase_info(&machTimeInfo);
#endif
}
void ElapsedTimer::enable()
@ -70,6 +76,8 @@ void ElapsedTimer::start()
{
#if defined(_WIN32)
startInit = timeGetTime();
#elif defined(__APPLE__)
startInit = mach_absolute_time();
#else
clock_gettime(CLOCK_MONOTONIC, &startInit);
#endif
@ -84,6 +92,12 @@ void ElapsedTimer::pause()
#if defined(_WIN32)
endInit = timeGetTime();
elapsedTime += (endInit - startInit) * 1e6;
#elif defined(__APPLE__)
endInit = mach_absolute_time();
uint64_t duration = endInit - startInit;
duration *= machTimeInfo.numer;
duration /= machTimeInfo.denom;
elapsedTime += duration;
#else
clock_gettime(CLOCK_MONOTONIC, &endInit);
int sec = endInit.tv_sec - startInit.tv_sec;

View file

@ -3,10 +3,21 @@
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#if defined(ANDROID)
# include <unordered_map>
# include <unordered_set>
#elif defined(__APPLE__)
# include <tr1/unordered_map>
# include <tr1/unordered_set>
#else
# include <unordered_map>
# include <unordered_set>
#endif
#include <stdint.h>
#include <cstdint>
#if defined(__APPLE__)
# include <mach/mach_time.h>|
#endif
#include <SkPath.h>
#include <SkBitmap.h>
@ -17,10 +28,10 @@
#define _USE_MATH_DEFINES
#include <math.h>
#if !defined(M_PI)
const double M_PI = 3.14159265358979323846;
const double M_PI = 3.14159265358979323846;
#endif
#if !defined(M_PI_2)
const double M_PI_2 = M_PI / 2.0;
const double M_PI_2 = M_PI / 2.0;
#endif
// Wrapper for unordered classes
@ -28,6 +39,10 @@ const double M_PI_2 = M_PI / 2.0;
# define UNORDERED_NAMESPACE std::tr1
# define UNORDERED_map unordered_map
# define UNORDERED_set unordered_set
#elif defined(__APPLE__)
# define UNORDERED_NAMESPACE std::tr1
# define UNORDERED_map unordered_map
# define UNORDERED_set unordered_set
#else
# define UNORDERED_NAMESPACE std
# define UNORDERED_map unordered_map
@ -60,6 +75,10 @@ private:
#if defined(_WIN32)
DWORD startInit;
DWORD endInit;
#elif defined(__APPLE__)
mach_timebase_info_data_t machTimeInfo;
uint64_t startInit;
uint64_t endInit;
#else
timespec startInit;
timespec endInit;

View file

@ -8,7 +8,7 @@ include Common.mk
# Set library name
LIBNAME = $(LIBRARY_PREFIX)proto
LIBTYPE = $(STATICLIB_EXT)
CXXFLAGS += -DGOOGLE_PROTOBUF_NO_RTTI -std=gnu++0x
CXXFLAGS += -DGOOGLE_PROTOBUF_NO_RTTI
LDFLAGS += -lpthread
LOCAL_C_INCLUDES += .

View file

@ -20,6 +20,27 @@
/* define if the compiler has hash_map */
#define HAVE_HASH_MAP 1
/* define if the compiler has hash_set */
#define HAVE_HASH_SET 1
#elif defined(__APPLE__)
/* the namespace of hash_map/hash_set */
#define HASH_NAMESPACE std::tr1
/* the name of <hash_set> */
#define HASH_MAP_CLASS unordered_map
/* the location of <hash_map> */
#define HASH_MAP_H <tr1/unordered_map>
/* the name of <hash_set> */
#define HASH_SET_CLASS unordered_set
/* the location of <hash_set> */
#define HASH_SET_H <tr1/unordered_set>
/* define if the compiler has hash_map */
#define HAVE_HASH_MAP 1
/* define if the compiler has hash_set */
#define HAVE_HASH_SET 1
#else

View file

@ -47,7 +47,8 @@ LOCAL_SRC_FILES += \
$(OSMAND_SKIA_LOC)/src/ports/SkTime_Unix.cpp \
FontHostConfiguration_android.cpp
LOCAL_C_INCLUDES += \
$(OSMAND_SKIA_ABS)/src/ports
$(OSMAND_SKIA_ABS)/src/ports \
$(OSMAND_SKIA_ABS)/include/utils/android
ifeq ($(TARGET_ARCH),arm)

View file

@ -44,11 +44,34 @@ SKIA_FLAGS_WINDOWS = \
-DSK_SCALAR_IS_FLOAT \
-DSK_CAN_USE_FLOAT \
-DSK_CPU_LENDIAN
LOCAL_SRC_FILES_MAC = \
$(OSMAND_SKIA_LOC)/src/ports/SkThread_pthread.cpp \
$(OSMAND_SKIA_LOC)/src/ports/SkFontHost_mac.cpp \
$(OSMAND_SKIA_LOC)/src/ports/SkFontHost_mac_coretext.cpp \
$(OSMAND_SKIA_LOC)/src/ports/SkFontHost_freetype_mac.cpp \
$(OSMAND_SKIA_LOC)/src/ports/SkTime_Unix.cpp
SKIA_FLAGS_MAC = \
-DSK_BUILD_FOR_MAC \
-DSK_USE_CORETEXT \
-DSkUserConfig_DEFINED \
-DPICTURE_VERSION_ICS=1 \
-DPICTURE_VERSION_JB=2 \
-DSK_SCALAR_IS_FLOAT \
-DSK_CAN_USE_FLOAT \
-DSK_CPU_LENDIAN
ifeq ($(TARGET),windows)
LOCAL_SRC_FILES += $(LOCAL_SRC_FILES_WINDOWS)
LOCAL_C_INCLUDES += $(OSMAND_SKIA_ABS)/include/utils/win
SKIAFLAGS += $(SKIA_FLAGS_WINDOWS)
else ifeq ($(TARGET),darwin)
LOCAL_SRC_FILES += $(LOCAL_SRC_FILES_MAC)
LOCAL_C_INCLUDES += $(OSMAND_SKIA_ABS)/include/utils/mac
SKIAFLAGS += $(SKIA_FLAGS_MAC)
else
LOCAL_C_INCLUDES += $(OSMAND_SKIA_ABS)/include/utils/unix
LOCAL_SRC_FILES += \
$(OSMAND_SKIA_LOC)/src/ports/SkFontHost_sandbox_none.cpp \
$(OSMAND_SKIA_LOC)/src/ports/SkThread_pthread.cpp \