From b95a3f621ce90ce34f974799907ec7d930aa5551 Mon Sep 17 00:00:00 2001 From: Daniel Wolf Date: Wed, 31 Aug 2016 22:21:53 +0200 Subject: [PATCH] Fixed Linux build --- CMakeLists.txt | 20 +- LICENSE.md | 22 + lib/whereami/.gitattributes | 30 + lib/whereami/.gitignore | 5 + lib/whereami/LICENSE | 25 + lib/whereami/README.md | 118 ++++ lib/whereami/_gnu-make/Makefile | 103 +++ lib/whereami/_ios-xcode/.gitignore | 2 + lib/whereami/_ios-xcode/WhereAmI-Info.plist | 47 ++ .../WhereAmI.xcodeproj/project.pbxproj | 327 +++++++++ .../contents.xcworkspacedata | 7 + lib/whereami/_mac-xcode/.gitignore | 2 + .../WhereAmI.xcodeproj/project.pbxproj | 333 +++++++++ .../contents.xcworkspacedata | 7 + lib/whereami/_win-vs14/.gitignore | 9 + lib/whereami/_win-vs14/Common.props | 40 ++ lib/whereami/_win-vs14/Debug.props | 21 + lib/whereami/_win-vs14/Executable.vcxproj | 114 +++ lib/whereami/_win-vs14/Library.vcxproj | 113 +++ lib/whereami/_win-vs14/Release.props | 39 ++ lib/whereami/_win-vs14/WhereAmI.sln | 38 + lib/whereami/_win-vs14/x64.props | 16 + lib/whereami/_win-vs14/x86.props | 19 + lib/whereami/example/executable.c | 126 ++++ lib/whereami/example/library.c | 84 +++ lib/whereami/src/whereami.c | 660 ++++++++++++++++++ lib/whereami/src/whereami.h | 65 ++ src/centiseconds.cpp | 2 +- src/phoneExtraction.h | 2 +- src/platformTools.cpp | 134 +--- 30 files changed, 2409 insertions(+), 121 deletions(-) create mode 100644 lib/whereami/.gitattributes create mode 100644 lib/whereami/.gitignore create mode 100644 lib/whereami/LICENSE create mode 100644 lib/whereami/README.md create mode 100644 lib/whereami/_gnu-make/Makefile create mode 100644 lib/whereami/_ios-xcode/.gitignore create mode 100644 lib/whereami/_ios-xcode/WhereAmI-Info.plist create mode 100644 lib/whereami/_ios-xcode/WhereAmI.xcodeproj/project.pbxproj create mode 100644 lib/whereami/_ios-xcode/WhereAmI.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 lib/whereami/_mac-xcode/.gitignore create mode 100644 lib/whereami/_mac-xcode/WhereAmI.xcodeproj/project.pbxproj create mode 100644 lib/whereami/_mac-xcode/WhereAmI.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 lib/whereami/_win-vs14/.gitignore create mode 100644 lib/whereami/_win-vs14/Common.props create mode 100644 lib/whereami/_win-vs14/Debug.props create mode 100644 lib/whereami/_win-vs14/Executable.vcxproj create mode 100644 lib/whereami/_win-vs14/Library.vcxproj create mode 100644 lib/whereami/_win-vs14/Release.props create mode 100644 lib/whereami/_win-vs14/WhereAmI.sln create mode 100644 lib/whereami/_win-vs14/x64.props create mode 100644 lib/whereami/_win-vs14/x86.props create mode 100644 lib/whereami/example/executable.c create mode 100644 lib/whereami/example/library.c create mode 100644 lib/whereami/src/whereami.c create mode 100644 lib/whereami/src/whereami.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 901fcc9..7515936 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,11 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STRE set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") endif() +# Enable POSIX threads +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -lpthread") +endif() + # Make sure Xcode uses libc++ instead of libstdc++, allowing us to use the C++14 standard library prior to OS X 10.9 if("${CMAKE_GENERATOR}" STREQUAL "Xcode") add_compile_options(-stdlib=libc++) @@ -44,6 +49,10 @@ elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8") endif() +if(${UNIX}) + add_definitions(-DHAVE_UNISTD_H) +endif() + # Enable project folders set_property(GLOBAL PROPERTY USE_FOLDERS ON) @@ -53,7 +62,7 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) set(Boost_USE_STATIC_LIBS ON) # Use static libs set(Boost_USE_MULTITHREADED ON) # Enable multithreading support set(Boost_USE_STATIC_RUNTIME ON) # Use static C++ runtime -find_package(Boost REQUIRED COMPONENTS filesystem locale system) +find_package(Boost 1.58 REQUIRED COMPONENTS filesystem locale system) include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) # ... C++ Format @@ -116,11 +125,16 @@ set(webRTCFiles ) add_library(webRTC ${webRTCFiles}) target_compile_options(webRTC PRIVATE ${disableWarningsFlags}) +target_compile_options(webRTC PRIVATE -pthread -lpthread) if (NOT WIN32) target_compile_definitions(webRTC PRIVATE WEBRTC_POSIX) endif() set_target_properties(webRTC PROPERTIES FOLDER lib) +# ... whereami +include_directories(SYSTEM "lib/whereami/src") +add_library(whereami lib/whereami/src/whereami.c) + # ... Flite include_directories("lib/flite-1.4/include" "lib/flite-1.4") set(fliteFiles @@ -230,7 +244,7 @@ set(SOURCE_FILES src/Lazy.h ) add_executable(rhubarb ${SOURCE_FILES}) -target_link_libraries(rhubarb ${Boost_LIBRARIES} cppFormat sphinxbase pocketSphinx flite webRTC) +target_link_libraries(rhubarb ${Boost_LIBRARIES} cppFormat sphinxbase pocketSphinx flite webRTC whereami) target_compile_options(rhubarb PUBLIC ${enableWarningsFlags}) # Define test project @@ -258,7 +272,7 @@ set(TEST_FILES src/Lazy.h ) add_executable(runTests ${TEST_FILES}) -target_link_libraries(runTests ${Boost_LIBRARIES} gtest gmock gmock_main flite cppFormat) +target_link_libraries(runTests ${Boost_LIBRARIES} gtest gmock gmock_main flite cppFormat whereami) set(CPACK_PACKAGE_NAME ${appName}) string(REPLACE " " "-" CPACK_PACKAGE_NAME "${CPACK_PACKAGE_NAME}") diff --git a/LICENSE.md b/LICENSE.md index 8922c83..6baf9cf 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -175,3 +175,25 @@ The [WebRTC](https://chromium.googlesource.com/external/webrtc) library is relea > * Neither the name of Google nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. > THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +### `[whereami]` Where Am I? + +The [Where Am I?](https://github.com/gpakosz/whereami) library is released under the **DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE**. + +> DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE +> Version 2, December 2004 +> +> Copyright (C) 2004 Sam Hocevar +> +> Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed. +> +> DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION +> +> 0. You just DO WHAT THE FUCK YOU WANT TO. +> 1. Bla bla bla +> 2. Montesqieu et camembert, vive la France, zut alors! +> +> WTFPLv2 is very permissive, see http://www.wtfpl.net/faq/ +> +> However, if this WTFPLV2 is REALLY a blocker and is the reason you can't use this project, contact me and I'll dual license it. + diff --git a/lib/whereami/.gitattributes b/lib/whereami/.gitattributes new file mode 100644 index 0000000..8b92a98 --- /dev/null +++ b/lib/whereami/.gitattributes @@ -0,0 +1,30 @@ +* text=auto + +# sources +*.h text diff=cpp +*.c text diff=cpp +*.cpp text diff=cpp +*.rb text diff=ruby +*.html text diff=html +*.m text diff=objc + +# shell scripts +*.sh eol=lf + +# GNU Makefile +Makefile text eol=lf + +# Autotools +*.am text eol=lf + +# Android +*.mk text eol=lf + +# Xcode files +*.pbxproj text eol=lf merge=union + +# Visual Studio files +*.sln text eol=crlf merge=union +*.vcxproj text eol=crlf merge=union +*.vcxproj.filters text eol=crlf merge=union +*.props text eol=crlf diff --git a/lib/whereami/.gitignore b/lib/whereami/.gitignore new file mode 100644 index 0000000..d8107df --- /dev/null +++ b/lib/whereami/.gitignore @@ -0,0 +1,5 @@ +.DS_Store +*~ +*.swp + +/bin diff --git a/lib/whereami/LICENSE b/lib/whereami/LICENSE new file mode 100644 index 0000000..1c594b3 --- /dev/null +++ b/lib/whereami/LICENSE @@ -0,0 +1,25 @@ +-------------------------------------------------------------------------------- + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2004 Sam Hocevar + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. + 1. Bla bla bla + 2. Montesqieu et camembert, vive la France, zut alors! + +-------------------------------------------------------------------------------- + +WTFPLv2 is very permissive, see http://www.wtfpl.net/faq/ + +However, if this WTFPLV2 is REALLY a blocker and is the reason you can't use +this project, contact me and I'll dual license it. + +-------------------------------------------------------------------------------- diff --git a/lib/whereami/README.md b/lib/whereami/README.md new file mode 100644 index 0000000..cb0379a --- /dev/null +++ b/lib/whereami/README.md @@ -0,0 +1,118 @@ +# Where Am I? + +A drop-in two files library to locate the current executable and the current +module on the file system. + +Supported platforms: + +- Windows +- Linux +- Mac +- iOS +- Android +- QNX Neutrino +- FreeBSD + +Just drop `whereami.h` and `whereami.c` into your build and get started. (see +also [customizing compilation]) + +[customizing compilation]: #customizing-compilation + +-------------------------------------------------------------------------------- + +## Usage + +- `wai_getExecutablePath()` returns the path of the enclosing executable +- `wai_getModulePath()` returns the path of the enclosing module + +Example usage: + +- first call `int length = wai_getExecutablePath(NULL, 0, NULL);` to retrieve + the length of the path +- allocate the destination buffer with `path = (char*)malloc(length + 1);` +- call `wai_getExecutablePath(path, length, &dirname_length)` again to retrieve + the path +- add a terminal `NUL` character with `path[length] = '\0';` + +Here is the output of the example: + + $ make -C _gnu-make + $ cp ./bin/mac-x86_64/library.dylib /tmp/ + $ ./bin/mac-x86_64/executable --load-library=/tmp/library.dylib + + executable path: /Users/gregory/Projects/whereami/bin/mac-x86_64/executable + dirname: /Users/gregory/Projects/whereami/bin/mac-x86_64 + basename: executable + module path: /Users/gregory/Projects/whereami/bin/mac-x86_64/executable + dirname: /Users/gregory/Projects/whereami/bin/mac-x86_64 + basename: executable + + library loaded + executable path: /Users/gregory/Projects/whereami/bin/mac-x86_64/executable + dirname: /Users/gregory/Projects/whereami/bin/mac-x86_64 + basename: executable + module path: /private/tmp/library.dylib + dirname: /private/tmp + basename: library.dylib + library unloaded + +-------------------------------------------------------------------------------- + +## Customizing compilation + +You can customize the library's behavior by defining the following macros: + +- `WAI_FUNCSPEC` +- `WAI_PREFIX` +- `WAI_MALLOC` +- `WAI_REALLOC` +- `WAI_FREE` + +## Compiling for Windows + +There is a Visual Studio 2015 solution in the `_win-vs14/` folder. + +## Compiling for Linux or Mac + +There is a GNU Make 3.81 `MakeFile` in the `_gnu-make/` folder: + + $ make -C _gnu-make/ + +## Compiling for Mac + +See above if you want to compile from command line. Otherwise there is an Xcode +project located in the `_mac-xcode/` folder. + +## Compiling for iOS + +There is an Xcode project located in the `_ios-xcode/` folder. + +If you prefer compiling from command line and deploying to a jailbroken device +through SSH, use: + + $ make -C _gnu-make/ binsubdir=ios CC="$(xcrun --sdk iphoneos --find clang) -isysroot $(xcrun --sdk iphoneos --show-sdk-path) -arch armv7 -arch armv7s -arch arm64" postbuild="codesign -s 'iPhone Developer'" + +## Compiling for Android + +You will have to install the Android NDK, and point the `$NDK_ROOT` environment +variable to the NDK path: e.g. `export NDK_ROOT=/opt/android-ndk` (without a +trailing `/` character). + +Next, the easy way is to make a standalone Android toolchain with the following +command: + + $ $NDK_ROOT/build/tools/make-standalone-toolchain.sh --system=$(uname -s | tr [A-Z] [a-z])-$(uname -m) --platform=android-3 --arch=arm --install-dir=/tmp/android + +Now you can compile the self test and self benchmark programs by running: + + $ make -C _gnu-make/ libsuffix=.so binsubdir=android CC=/tmp/android/bin/arm-linux-androideabi-gcc CFLAGS='-march=armv7-a -mfloat-abi=softfp -O2' + +-------------------------------------------------------------------------------- + +If you find this library useful and decide to use it in your own projects please +drop me a line [@gpakosz]. + +If you use it in a commercial project, consider using [Gittip]. + +[@gpakosz]: https://twitter.com/gpakosz +[Gittip]: https://www.gittip.com/gpakosz/ diff --git a/lib/whereami/_gnu-make/Makefile b/lib/whereami/_gnu-make/Makefile new file mode 100644 index 0000000..665cdc2 --- /dev/null +++ b/lib/whereami/_gnu-make/Makefile @@ -0,0 +1,103 @@ +.PHONY: build clean + +# directories +ifeq ($(realpath .),) + $(error your version of Make doesn't support $$(realpath names...) - please use GNU Make 3.81 or later) +endif + +ifeq ($(platform),) + __uname_s := $(shell sh -c 'uname -s 2>/dev/null | tr [A-Z] [a-z] || echo unknown-platform') + __uname_m := $(shell sh -c 'uname -m 2>/dev/null | tr [A-Z] [a-z] || echo unknown-architecture') + + ifeq ($(__uname_s),linux) + override platform := linux + override architecture := $(__uname_m) + endif + ifeq ($(__uname_s),darwin) + override platform := mac + override architecture := $(__uname_m) + endif + ifeq ($(findstring mingw,$(__uname_s)),mingw) + override platform := windows + override architecture := $(if $(findstring MINGW32,$(MSYSTEM)),i686,$(if $(findstring MINGW64,$(MSYSTEM)),x86_64,)) + ifeq ($(CC),cc) + override CC := gcc + endif + endif + ifeq ($(__uname_s),freebsd) + override platform := freebsd + override architecture := $(__uname_m) + endif +endif +ifeq ($(architecture),) + override architecture := unknown-architecture +endif + +prefix := $(realpath ..) +srcdir := $(realpath ../src) +exampledir := $(realpath ../example) +testdir := $(realpath ../test) +buildir := $(realpath .)/build +binsubdir := $(platform)-$(architecture) +bindir := $(prefix)/bin/$(binsubdir) + +CFLAGS := -O2 -g -Wall -pedantic -Werror -std=c99 +CXXFLAGS := -O2 -g -Wall -pedantic -Werror + +ifeq ($(platform),linux) +LDFLAGS += -ldl +CFLAGS += -D_XOPEN_SOURCE=500 -fpic +CXXFLAGS += -fpic +endif +ifeq ($(platform),mac) +CFLAGS += -D_DARWIN_C_SOURCE +endif +ifeq ($(platform),freebsd) +CFLAGS += -fpic +CXXFLAGS += -fpic +endif + +ifeq ($(platform),mac) +libsuffix := .dylib +endif +ifeq ($(platform),linux) +libsuffix := .so +endif +ifeq ($(platform),windows) +libsuffix := .dll +endif +ifeq ($(platform),freebsd) +libsuffix := .so +endif + +.PHONY: build-executable +build: build-executable +build-executable: $(bindir)/executable $(bindir)/executable-cpp + +$(bindir)/executable: $(srcdir)/whereami.c $(srcdir)/whereami.h $(exampledir)/executable.c + mkdir -p $(@D) + $(CC) -o $@ -I $(srcdir) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(filter-out %.h,$^) + $(if $(postbuild),$(postbuild) $@) + +$(bindir)/executable-cpp: $(srcdir)/whereami.c $(srcdir)/whereami.h $(exampledir)/executable.c + mkdir -p $(@D) + $(CXX) -x c++ -o $@ -I $(srcdir) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(filter-out %.h,$^) + $(if $(postbuild),$(postbuild) $@) + +.PHONY: build-library +build: build-library +build-library: $(bindir)/library$(libsuffix) $(bindir)/library-cpp$(libsuffix) + +$(bindir)/library$(libsuffix): $(srcdir)/whereami.c $(srcdir)/whereami.h $(exampledir)/library.c + mkdir -p $(@D) + $(CC) -shared -o $@ -I $(srcdir) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(filter-out %.h,$^) + $(if $(postbuild),$(postbuild) $@) + +$(bindir)/library-cpp$(libsuffix): $(srcdir)/whereami.c $(srcdir)/whereami.h $(exampledir)/library.c + mkdir -p $(@D) + $(CXX) -x c++ -shared -o $@ -I $(srcdir) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(filter-out %.h,$^) + $(if $(postbuild),$(postbuild) $@) + +clean: + rm -rf $(buildir) + rm -rf $(bindir) diff --git a/lib/whereami/_ios-xcode/.gitignore b/lib/whereami/_ios-xcode/.gitignore new file mode 100644 index 0000000..8e82f86 --- /dev/null +++ b/lib/whereami/_ios-xcode/.gitignore @@ -0,0 +1,2 @@ +xcuserdata/ +xcshareddata/ diff --git a/lib/whereami/_ios-xcode/WhereAmI-Info.plist b/lib/whereami/_ios-xcode/WhereAmI-Info.plist new file mode 100644 index 0000000..a9088fb --- /dev/null +++ b/lib/whereami/_ios-xcode/WhereAmI-Info.plist @@ -0,0 +1,47 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + ${PRODUCT_NAME} + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + net.pempek.${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + LSRequiresIPhoneOS + + UIRequiredDeviceCapabilities + + armv7 + + UIRequiresFullScreen + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/lib/whereami/_ios-xcode/WhereAmI.xcodeproj/project.pbxproj b/lib/whereami/_ios-xcode/WhereAmI.xcodeproj/project.pbxproj new file mode 100644 index 0000000..2d7dc12 --- /dev/null +++ b/lib/whereami/_ios-xcode/WhereAmI.xcodeproj/project.pbxproj @@ -0,0 +1,327 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 1A1E0A8D1A4486A300611947 /* whereami.c in Sources */ = {isa = PBXBuildFile; fileRef = 1A1E0A8B1A4486A300611947 /* whereami.c */; }; + 1A1E0A8F1A4486A900611947 /* executable.c in Sources */ = {isa = PBXBuildFile; fileRef = 1A1E0A8E1A4486A900611947 /* executable.c */; }; + 1A1E0AAC1A4486FB00611947 /* library.c in Sources */ = {isa = PBXBuildFile; fileRef = 1A1E0AAB1A4486FB00611947 /* library.c */; }; + 1A1E0AAD1A44880600611947 /* whereami.c in Sources */ = {isa = PBXBuildFile; fileRef = 1A1E0A8B1A4486A300611947 /* whereami.c */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 1A1E0A921A4486E800611947 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = "include/$(PRODUCT_NAME)"; + dstSubfolderSpec = 16; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 1A1E0A891A44868400611947 /* WhereAmI-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "WhereAmI-Info.plist"; sourceTree = ""; }; + 1A1E0A8B1A4486A300611947 /* whereami.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = whereami.c; sourceTree = ""; }; + 1A1E0A8C1A4486A300611947 /* whereami.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = whereami.h; sourceTree = ""; }; + 1A1E0A8E1A4486A900611947 /* executable.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = executable.c; sourceTree = ""; }; + 1A1E0A941A4486E800611947 /* library.dylib */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = library.dylib; sourceTree = BUILT_PRODUCTS_DIR; }; + 1A1E0AAB1A4486FB00611947 /* library.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = library.c; sourceTree = ""; }; + 1A98F9C917A4018400BF09FF /* executable.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = executable.app; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 1A1E0A911A4486E800611947 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 1A98F9C617A4018400BF09FF /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 1A7335C3182EC2E000691A33 /* src */ = { + isa = PBXGroup; + children = ( + 1A1E0A8B1A4486A300611947 /* whereami.c */, + 1A1E0A8C1A4486A300611947 /* whereami.h */, + ); + name = src; + path = ../src; + sourceTree = ""; + }; + 1A7335C4182EC30100691A33 /* example */ = { + isa = PBXGroup; + children = ( + 1A1E0AAB1A4486FB00611947 /* library.c */, + 1A1E0A8E1A4486A900611947 /* executable.c */, + ); + name = example; + path = ../example; + sourceTree = ""; + }; + 1A98F9C017A4018400BF09FF = { + isa = PBXGroup; + children = ( + 1A1E0A891A44868400611947 /* WhereAmI-Info.plist */, + 1A7335C3182EC2E000691A33 /* src */, + 1A7335C4182EC30100691A33 /* example */, + 1A98F9CA17A4018400BF09FF /* Products */, + ); + sourceTree = ""; + }; + 1A98F9CA17A4018400BF09FF /* Products */ = { + isa = PBXGroup; + children = ( + 1A98F9C917A4018400BF09FF /* executable.app */, + 1A1E0A941A4486E800611947 /* library.dylib */, + ); + name = Products; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 1A1E0A931A4486E800611947 /* library */ = { + isa = PBXNativeTarget; + buildConfigurationList = 1A1E0AA51A4486E900611947 /* Build configuration list for PBXNativeTarget "library" */; + buildPhases = ( + 1A1E0A901A4486E800611947 /* Sources */, + 1A1E0A911A4486E800611947 /* Frameworks */, + 1A1E0A921A4486E800611947 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = library; + productName = library; + productReference = 1A1E0A941A4486E800611947 /* library.dylib */; + productType = "com.apple.product-type.library.static"; + }; + 1A98F9C817A4018400BF09FF /* executable */ = { + isa = PBXNativeTarget; + buildConfigurationList = 1A98F9E617A4018400BF09FF /* Build configuration list for PBXNativeTarget "executable" */; + buildPhases = ( + 1A98F9C517A4018400BF09FF /* Sources */, + 1A98F9C617A4018400BF09FF /* Frameworks */, + 1A98F9C717A4018400BF09FF /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = executable; + productName = WhereAmI; + productReference = 1A98F9C917A4018400BF09FF /* executable.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 1A98F9C117A4018400BF09FF /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0460; + ORGANIZATIONNAME = "Gregory Pakosz"; + TargetAttributes = { + 1A1E0A931A4486E800611947 = { + CreatedOnToolsVersion = 6.1.1; + }; + }; + }; + buildConfigurationList = 1A98F9C417A4018400BF09FF /* Build configuration list for PBXProject "WhereAmI" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 1A98F9C017A4018400BF09FF; + productRefGroup = 1A98F9CA17A4018400BF09FF /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 1A98F9C817A4018400BF09FF /* executable */, + 1A1E0A931A4486E800611947 /* library */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 1A98F9C717A4018400BF09FF /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 1A1E0A901A4486E800611947 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 1A1E0AAC1A4486FB00611947 /* library.c in Sources */, + 1A1E0AAD1A44880600611947 /* whereami.c in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 1A98F9C517A4018400BF09FF /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 1A1E0A8D1A4486A300611947 /* whereami.c in Sources */, + 1A1E0A8F1A4486A900611947 /* executable.c in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 1A1E0AA61A4486E900611947 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + EXECUTABLE_EXTENSION = dylib; + EXECUTABLE_PREFIX = ""; + MACH_O_TYPE = mh_dylib; + }; + name = Debug; + }; + 1A1E0AA71A4486E900611947 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + EXECUTABLE_EXTENSION = dylib; + EXECUTABLE_PREFIX = ""; + MACH_O_TYPE = mh_dylib; + }; + name = Release; + }; + 1A98F9E417A4018400BF09FF /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + ../src, + /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, + ); + INFOPLIST_FILE = "WhereAmI-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; + ONLY_ACTIVE_ARCH = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 1A98F9E517A4018400BF09FF /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; + COPY_PHASE_STRIP = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_OPTIMIZATION_LEVEL = 2; + GCC_PREPROCESSOR_DEFINITIONS = NDEBUG; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + ../src, + /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, + ); + INFOPLIST_FILE = "WhereAmI-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; + OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 1A98F9E717A4018400BF09FF /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + }; + name = Debug; + }; + 1A98F9E817A4018400BF09FF /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 1A1E0AA51A4486E900611947 /* Build configuration list for PBXNativeTarget "library" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1A1E0AA61A4486E900611947 /* Debug */, + 1A1E0AA71A4486E900611947 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 1A98F9C417A4018400BF09FF /* Build configuration list for PBXProject "WhereAmI" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1A98F9E417A4018400BF09FF /* Debug */, + 1A98F9E517A4018400BF09FF /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 1A98F9E617A4018400BF09FF /* Build configuration list for PBXNativeTarget "executable" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1A98F9E717A4018400BF09FF /* Debug */, + 1A98F9E817A4018400BF09FF /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 1A98F9C117A4018400BF09FF /* Project object */; +} diff --git a/lib/whereami/_ios-xcode/WhereAmI.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/lib/whereami/_ios-xcode/WhereAmI.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..3524150 --- /dev/null +++ b/lib/whereami/_ios-xcode/WhereAmI.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/lib/whereami/_mac-xcode/.gitignore b/lib/whereami/_mac-xcode/.gitignore new file mode 100644 index 0000000..8e82f86 --- /dev/null +++ b/lib/whereami/_mac-xcode/.gitignore @@ -0,0 +1,2 @@ +xcuserdata/ +xcshareddata/ diff --git a/lib/whereami/_mac-xcode/WhereAmI.xcodeproj/project.pbxproj b/lib/whereami/_mac-xcode/WhereAmI.xcodeproj/project.pbxproj new file mode 100644 index 0000000..e3549d9 --- /dev/null +++ b/lib/whereami/_mac-xcode/WhereAmI.xcodeproj/project.pbxproj @@ -0,0 +1,333 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 1A1E0A801A4484DC00611947 /* whereami.c in Sources */ = {isa = PBXBuildFile; fileRef = 1A1E0A7E1A4484DC00611947 /* whereami.c */; }; + 1A1E0A811A4484DC00611947 /* whereami.c in Sources */ = {isa = PBXBuildFile; fileRef = 1A1E0A7E1A4484DC00611947 /* whereami.c */; }; + 1A1E0A821A4484DC00611947 /* whereami.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A1E0A7F1A4484DC00611947 /* whereami.h */; }; + 1A1E0A851A4484ED00611947 /* executable.c in Sources */ = {isa = PBXBuildFile; fileRef = 1A1E0A831A4484EA00611947 /* executable.c */; }; + 1A1E0A861A4484EF00611947 /* library.c in Sources */ = {isa = PBXBuildFile; fileRef = 1A1E0A841A4484EA00611947 /* library.c */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 1A98F9FF17A4249200BF09FF /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 1A1E0A7A1A44841F00611947 /* library.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = library.dylib; sourceTree = BUILT_PRODUCTS_DIR; }; + 1A1E0A7E1A4484DC00611947 /* whereami.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = whereami.c; sourceTree = ""; }; + 1A1E0A7F1A4484DC00611947 /* whereami.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = whereami.h; sourceTree = ""; }; + 1A1E0A831A4484EA00611947 /* executable.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = executable.c; sourceTree = ""; }; + 1A1E0A841A4484EA00611947 /* library.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = library.c; sourceTree = ""; }; + 1A98FA0117A4249200BF09FF /* executable */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = executable; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 1A1E0A771A44841F00611947 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 1A98F9FE17A4249200BF09FF /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 1A42F178182EB9EF00F3880C /* src */ = { + isa = PBXGroup; + children = ( + 1A1E0A7E1A4484DC00611947 /* whereami.c */, + 1A1E0A7F1A4484DC00611947 /* whereami.h */, + ); + name = src; + path = ../src; + sourceTree = ""; + }; + 1A42F17A182EB9FE00F3880C /* example */ = { + isa = PBXGroup; + children = ( + 1A1E0A831A4484EA00611947 /* executable.c */, + 1A1E0A841A4484EA00611947 /* library.c */, + ); + name = example; + path = ../example; + sourceTree = ""; + }; + 1A98F9F817A4249200BF09FF = { + isa = PBXGroup; + children = ( + 1A42F178182EB9EF00F3880C /* src */, + 1A42F17A182EB9FE00F3880C /* example */, + 1A98FA0217A4249200BF09FF /* Products */, + ); + sourceTree = ""; + }; + 1A98FA0217A4249200BF09FF /* Products */ = { + isa = PBXGroup; + children = ( + 1A98FA0117A4249200BF09FF /* executable */, + 1A1E0A7A1A44841F00611947 /* library.dylib */, + ); + name = Products; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + 1A1E0A781A44841F00611947 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 1A1E0A821A4484DC00611947 /* whereami.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + 1A1E0A791A44841F00611947 /* library */ = { + isa = PBXNativeTarget; + buildConfigurationList = 1A1E0A7B1A44841F00611947 /* Build configuration list for PBXNativeTarget "library" */; + buildPhases = ( + 1A1E0A761A44841F00611947 /* Sources */, + 1A1E0A771A44841F00611947 /* Frameworks */, + 1A1E0A781A44841F00611947 /* Headers */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = library; + productName = library; + productReference = 1A1E0A7A1A44841F00611947 /* library.dylib */; + productType = "com.apple.product-type.library.dynamic"; + }; + 1A98FA0017A4249200BF09FF /* executable */ = { + isa = PBXNativeTarget; + buildConfigurationList = 1A98FA0A17A4249200BF09FF /* Build configuration list for PBXNativeTarget "executable" */; + buildPhases = ( + 1A98F9FD17A4249200BF09FF /* Sources */, + 1A98F9FE17A4249200BF09FF /* Frameworks */, + 1A98F9FF17A4249200BF09FF /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = executable; + productName = WhereAmI; + productReference = 1A98FA0117A4249200BF09FF /* executable */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 1A98F9F917A4249200BF09FF /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0610; + ORGANIZATIONNAME = "Gregory Pakosz"; + TargetAttributes = { + 1A1E0A791A44841F00611947 = { + CreatedOnToolsVersion = 6.1.1; + }; + }; + }; + buildConfigurationList = 1A98F9FC17A4249200BF09FF /* Build configuration list for PBXProject "WhereAmI" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 1A98F9F817A4249200BF09FF; + productRefGroup = 1A98FA0217A4249200BF09FF /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 1A98FA0017A4249200BF09FF /* executable */, + 1A1E0A791A44841F00611947 /* library */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 1A1E0A761A44841F00611947 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 1A1E0A811A4484DC00611947 /* whereami.c in Sources */, + 1A1E0A861A4484EF00611947 /* library.c in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 1A98F9FD17A4249200BF09FF /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 1A1E0A801A4484DC00611947 /* whereami.c in Sources */, + 1A1E0A851A4484ED00611947 /* executable.c in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 1A1E0A7C1A44841F00611947 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 1A1E0A7D1A44841F00611947 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; + 1A98FA0817A4249200BF09FF /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "compiler-default"; + CLANG_CXX_LIBRARY = "compiler-default"; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + ../src, + /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, + ); + MACOSX_DEPLOYMENT_TARGET = 10.8; + ONLY_ACTIVE_ARCH = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + }; + name = Debug; + }; + 1A98FA0917A4249200BF09FF /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "compiler-default"; + CLANG_CXX_LIBRARY = "compiler-default"; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_OPTIMIZATION_LEVEL = 2; + GCC_PREPROCESSOR_DEFINITIONS = NDEBUG; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + ../src, + /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, + ); + MACOSX_DEPLOYMENT_TARGET = 10.8; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + }; + name = Release; + }; + 1A98FA0B17A4249200BF09FF /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + }; + name = Debug; + }; + 1A98FA0C17A4249200BF09FF /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 1A1E0A7B1A44841F00611947 /* Build configuration list for PBXNativeTarget "library" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1A1E0A7C1A44841F00611947 /* Debug */, + 1A1E0A7D1A44841F00611947 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 1A98F9FC17A4249200BF09FF /* Build configuration list for PBXProject "WhereAmI" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1A98FA0817A4249200BF09FF /* Debug */, + 1A98FA0917A4249200BF09FF /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 1A98FA0A17A4249200BF09FF /* Build configuration list for PBXNativeTarget "executable" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1A98FA0B17A4249200BF09FF /* Debug */, + 1A98FA0C17A4249200BF09FF /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 1A98F9F917A4249200BF09FF /* Project object */; +} diff --git a/lib/whereami/_mac-xcode/WhereAmI.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/lib/whereami/_mac-xcode/WhereAmI.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..3524150 --- /dev/null +++ b/lib/whereami/_mac-xcode/WhereAmI.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/lib/whereami/_win-vs14/.gitignore b/lib/whereami/_win-vs14/.gitignore new file mode 100644 index 0000000..b85cfa2 --- /dev/null +++ b/lib/whereami/_win-vs14/.gitignore @@ -0,0 +1,9 @@ +/build +/ipch + +*.suo +*.sdf +*.opensdf +*.user +*.sln.docstates +*.opendb diff --git a/lib/whereami/_win-vs14/Common.props b/lib/whereami/_win-vs14/Common.props new file mode 100644 index 0000000..457886e --- /dev/null +++ b/lib/whereami/_win-vs14/Common.props @@ -0,0 +1,40 @@ + + + + ..\bin\Windows$(PLATFORM_SUFFIX)-$(ARCH)$(CONF_SUFFIX) + ..\lib\Windows$(PLATFORM_SUFFIX)-$(ARCH)-vs11$(CONF_SUFFIX) + build\$(ProjectName)-win$(PLATFORM_SUFFIX)-$(ARCH)-vs11$(CONF_SUFFIX) + + + $(BUILD_DIR)\ + $(BIN_DIR)\ + false + + + + _CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + /we4013 /wd4820 /we4289 /wd4342 /wd4347 /wd4514 /we4545 /we4546 /we4547 /we4548 /we4549 /we4619 /we4623 /we4625 /we4626 /wd4710 /we4836 /we4905 /we4906 /we4928 /we4946 /wd4986 /wd4711 /wd4350 /wd4255 /wd4668 + NotUsing + true + EnableAllWarnings + false + + + true + Console + /time %(AdditionalOptions) + + + + + $(BIN_DIR) + + + $(LIB_DIR) + + + $(BUILD_DIR) + + + \ No newline at end of file diff --git a/lib/whereami/_win-vs14/Debug.props b/lib/whereami/_win-vs14/Debug.props new file mode 100644 index 0000000..116ddaf --- /dev/null +++ b/lib/whereami/_win-vs14/Debug.props @@ -0,0 +1,21 @@ + + + + -Debug + + + + Disabled + Level3 + ProgramDatabase + MultiThreadedDebug + true + OnlyExplicitInline + + + + + $(CONF_SUFFIX) + + + diff --git a/lib/whereami/_win-vs14/Executable.vcxproj b/lib/whereami/_win-vs14/Executable.vcxproj new file mode 100644 index 0000000..cb45a0e --- /dev/null +++ b/lib/whereami/_win-vs14/Executable.vcxproj @@ -0,0 +1,114 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + + + + + + + + Win32Proj + WhereAmI + {4F614870-9A09-4661-9963-7DF73803240B} + + + + Application + true + v140 + + + Application + true + v140 + + + Application + false + v140 + true + + + Application + false + v140 + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ../src;%(AdditionalIncludeDirectories) + + + + + ../src;%(AdditionalIncludeDirectories) + + + + + /we4013 /wd4820 /we4289 /wd4342 /wd4347 /wd4514 /we4545 /we4546 /we4547 /we4548 /we4549 /we4619 /we4623 /we4625 /we4626 /wd4710 /we4836 /we4905 /we4906 /we4928 /we4946 /wd4986 /wd4711 /wd4350 /Qvec-report:2 + ../src;%(AdditionalIncludeDirectories) + /we4013 /wd4820 /we4289 /wd4342 /wd4347 /wd4514 /we4545 /we4546 /we4547 /we4548 /we4549 /we4619 /we4623 /we4625 /we4626 /wd4710 /we4836 /we4905 /we4906 /we4928 /we4946 /wd4986 /wd4711 /wd4350 /wd4255 /wd4668 /Qvec-report:2 + + + + + ../src;%(AdditionalIncludeDirectories) + /we4013 /wd4820 /we4289 /wd4342 /wd4347 /wd4514 /we4545 /we4546 /we4547 /we4548 /we4549 /we4619 /we4623 /we4625 /we4626 /wd4710 /we4836 /we4905 /we4906 /we4928 /we4946 /wd4986 /wd4711 /wd4350 /wd4255 /wd4668 /Qvec-report:2 + + + + + + \ No newline at end of file diff --git a/lib/whereami/_win-vs14/Library.vcxproj b/lib/whereami/_win-vs14/Library.vcxproj new file mode 100644 index 0000000..bac9708 --- /dev/null +++ b/lib/whereami/_win-vs14/Library.vcxproj @@ -0,0 +1,113 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + + + + + + + + Win32Proj + WhereAmI + {D53572AD-B43A-4507-9BB2-F330F942912B} + + + + DynamicLibrary + true + v140 + + + DynamicLibrary + true + v140 + + + DynamicLibrary + false + true + v140 + + + DynamicLibrary + false + true + v140 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ../src;%(AdditionalIncludeDirectories) + + + + + ../src;%(AdditionalIncludeDirectories) + + + + + ../src;%(AdditionalIncludeDirectories) + /we4013 /wd4820 /we4289 /wd4342 /wd4347 /wd4514 /we4545 /we4546 /we4547 /we4548 /we4549 /we4619 /we4623 /we4625 /we4626 /wd4710 /we4836 /we4905 /we4906 /we4928 /we4946 /wd4986 /wd4711 /wd4350 /wd4255 /wd4668 /Qvec-report:2 + + + + + ../src;%(AdditionalIncludeDirectories) + /we4013 /wd4820 /we4289 /wd4342 /wd4347 /wd4514 /we4545 /we4546 /we4547 /we4548 /we4549 /we4619 /we4623 /we4625 /we4626 /wd4710 /we4836 /we4905 /we4906 /we4928 /we4946 /wd4986 /wd4711 /wd4350 /wd4255 /wd4668 /Qvec-report:2 + + + + + + \ No newline at end of file diff --git a/lib/whereami/_win-vs14/Release.props b/lib/whereami/_win-vs14/Release.props new file mode 100644 index 0000000..88bc1c2 --- /dev/null +++ b/lib/whereami/_win-vs14/Release.props @@ -0,0 +1,39 @@ + + + + + + + false + + + + MaxSpeed + AnySuitable + true + Speed + true + true + true + NDEBUG;%(PreprocessorDefinitions) + true + Level3 + ProgramDatabase + MultiThreaded + false + /d2Zi+ %(AdditionalOptions) + + + UseLinkTimeCodeGeneration + true + + + true + + + + + $(CONF_SUFFIX) + + + diff --git a/lib/whereami/_win-vs14/WhereAmI.sln b/lib/whereami/_win-vs14/WhereAmI.sln new file mode 100644 index 0000000..20360e9 --- /dev/null +++ b/lib/whereami/_win-vs14/WhereAmI.sln @@ -0,0 +1,38 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.31101.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Executable", "Executable.vcxproj", "{4F614870-9A09-4661-9963-7DF73803240B}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Library", "Library.vcxproj", "{D53572AD-B43A-4507-9BB2-F330F942912B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4F614870-9A09-4661-9963-7DF73803240B}.Debug|Win32.ActiveCfg = Debug|Win32 + {4F614870-9A09-4661-9963-7DF73803240B}.Debug|Win32.Build.0 = Debug|Win32 + {4F614870-9A09-4661-9963-7DF73803240B}.Debug|x64.ActiveCfg = Debug|x64 + {4F614870-9A09-4661-9963-7DF73803240B}.Debug|x64.Build.0 = Debug|x64 + {4F614870-9A09-4661-9963-7DF73803240B}.Release|Win32.ActiveCfg = Release|Win32 + {4F614870-9A09-4661-9963-7DF73803240B}.Release|Win32.Build.0 = Release|Win32 + {4F614870-9A09-4661-9963-7DF73803240B}.Release|x64.ActiveCfg = Release|x64 + {4F614870-9A09-4661-9963-7DF73803240B}.Release|x64.Build.0 = Release|x64 + {D53572AD-B43A-4507-9BB2-F330F942912B}.Debug|Win32.ActiveCfg = Debug|Win32 + {D53572AD-B43A-4507-9BB2-F330F942912B}.Debug|Win32.Build.0 = Debug|Win32 + {D53572AD-B43A-4507-9BB2-F330F942912B}.Debug|x64.ActiveCfg = Debug|x64 + {D53572AD-B43A-4507-9BB2-F330F942912B}.Debug|x64.Build.0 = Debug|x64 + {D53572AD-B43A-4507-9BB2-F330F942912B}.Release|Win32.ActiveCfg = Release|Win32 + {D53572AD-B43A-4507-9BB2-F330F942912B}.Release|Win32.Build.0 = Release|Win32 + {D53572AD-B43A-4507-9BB2-F330F942912B}.Release|x64.ActiveCfg = Release|x64 + {D53572AD-B43A-4507-9BB2-F330F942912B}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/lib/whereami/_win-vs14/x64.props b/lib/whereami/_win-vs14/x64.props new file mode 100644 index 0000000..9d4d031 --- /dev/null +++ b/lib/whereami/_win-vs14/x64.props @@ -0,0 +1,16 @@ + + + + x64 + + + + MachineX64 + + + + + $(ARCH) + + + diff --git a/lib/whereami/_win-vs14/x86.props b/lib/whereami/_win-vs14/x86.props new file mode 100644 index 0000000..d1f9bd7 --- /dev/null +++ b/lib/whereami/_win-vs14/x86.props @@ -0,0 +1,19 @@ + + + + x86 + + + + MachineX86 + + + StreamingSIMDExtensions2 + + + + + $(ARCH) + + + \ No newline at end of file diff --git a/lib/whereami/example/executable.c b/lib/whereami/example/executable.c new file mode 100644 index 0000000..fd8f695 --- /dev/null +++ b/lib/whereami/example/executable.c @@ -0,0 +1,126 @@ +#include +#include +#include + +#include + +#if defined(_WIN32) + +#define WIN32_LEAN_AND_MEAN +#if defined(_MSC_VER) +#pragma warning(push, 3) +#endif +#include + +#define RTLD_LAZY 1 +#define RTLD_NOW 2 +#define RTLD_GLOBAL 4 +#define RTLD_LOCAL 8 + +static void* dlopen(const char* fileName, int mode) +{ + wchar_t buffer[MAX_PATH]; + + if (MultiByteToWideChar(CP_UTF8, 0, fileName, -1, buffer, sizeof(buffer) / sizeof(*buffer))) + { + wchar_t buffer_[MAX_PATH]; + + GetFullPathNameW(buffer, sizeof(buffer_) / sizeof(*buffer_), buffer_, NULL); + + return (void*)LoadLibraryW(buffer_); + } + + return NULL; +} + +static int dlclose(void* handle) +{ + return FreeLibrary((HMODULE)handle) ? 0 : -1; +} + +static const char* dlerror(void) +{ + DWORD error; + + error = GetLastError(); + + if (error) + { + static char message[1024]; + + FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, error, MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), message, sizeof(message), NULL); + + return message; + } + + return "no error"; +} + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + +#else + +#include + +#endif + +int main(int argc, char** argv) +{ + char* path = NULL; + int length, dirname_length; + int i; + + length = wai_getExecutablePath(NULL, 0, &dirname_length); + if (length > 0) + { + path = (char*)malloc(length + 1); + if (!path) + abort(); + wai_getExecutablePath(path, length, &dirname_length); + path[length] = '\0'; + + printf("executable path: %s\n", path); + path[dirname_length] = '\0'; + printf(" dirname: %s\n", path); + printf(" basename: %s\n", path + dirname_length + 1); + free(path); + } + + length = wai_getModulePath(NULL, 0, &dirname_length); + if (length > 0) + { + path = (char*)malloc(length + 1); + if (!path) + abort(); + wai_getModulePath(path, length, &dirname_length); + path[length] = '\0'; + + printf("module path: %s\n", path); + path[dirname_length] = '\0'; + printf(" dirname: %s\n", path); + printf(" basename: %s\n", path + dirname_length + 1); + free(path); + } + + for (i = 1; i < argc; ++i) + { + if (strncmp(argv[i], "--load-library=", 15) == 0) + { + char* name = argv[i] + 15; + void* handle; + + printf("\n"); + + handle = dlopen(name, RTLD_NOW); + if (!handle) + printf("failed to load library: %s\n", dlerror()); + + if (handle) + dlclose(handle); + } + } + + return 0; +} diff --git a/lib/whereami/example/library.c b/lib/whereami/example/library.c new file mode 100644 index 0000000..cd5f0dd --- /dev/null +++ b/lib/whereami/example/library.c @@ -0,0 +1,84 @@ +#include +#include + +#include + +#if defined(__GNUC__) && !defined(_WIN32) +__attribute__((constructor)) +#endif +static void load() +{ + char* path = NULL; + int length, dirname_length; + + printf("library loaded\n"); + + length = wai_getExecutablePath(NULL, 0, &dirname_length); + if (length > 0) + { + path = (char*)malloc(length + 1); + wai_getExecutablePath(path, length, &dirname_length); + path[length] = '\0'; + + printf("executable path: %s\n", path); + path[dirname_length] = '\0'; + printf(" dirname: %s\n", path); + printf(" basename: %s\n", path + dirname_length + 1); + free(path); + } + + length = wai_getModulePath(NULL, 0, &dirname_length); + if (length > 0) + { + path = (char*)malloc(length + 1); + wai_getModulePath(path, length, &dirname_length); + path[length] = '\0'; + + printf("module path: %s\n", path); + path[dirname_length] = '\0'; + printf(" dirname: %s\n", path); + printf(" basename: %s\n", path + dirname_length + 1); + free(path); + } +} + +#if defined(__GNUC__) && !defined(_WIN32) +__attribute__((constructor)) +__attribute__((destructor)) +#endif +static void unload() +{ + printf("library unloaded\n"); +} + +#if defined(_WIN32) + +#define WIN32_LEAN_AND_MEAN +#if defined(_MSC_VER) +#pragma warning(push, 3) +#endif +#include + +BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + load(); + break; + case DLL_THREAD_ATTACH: + break; + case DLL_THREAD_DETACH: + break; + case DLL_PROCESS_DETACH: + unload(); + break; + } + return TRUE; +} + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + +#endif diff --git a/lib/whereami/src/whereami.c b/lib/whereami/src/whereami.c new file mode 100644 index 0000000..19d3781 --- /dev/null +++ b/lib/whereami/src/whereami.c @@ -0,0 +1,660 @@ +// (‑●‑●)> released under the WTFPL v2 license, by Gregory Pakosz (@gpakosz) +// https://github.com/gpakosz/whereami + +// in case you want to #include "whereami.c" in a larger compilation unit +#if !defined(WHEREAMI_H) +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(WAI_MALLOC) || !defined(WAI_FREE) || !defined(WAI_REALLOC) +#include +#endif + +#if !defined(WAI_MALLOC) +#define WAI_MALLOC(size) malloc(size) +#endif + +#if !defined(WAI_FREE) +#define WAI_FREE(p) free(p) +#endif + +#if !defined(WAI_REALLOC) +#define WAI_REALLOC(p, size) realloc(p, size) +#endif + +#ifndef WAI_NOINLINE +#if defined(_MSC_VER) +#define WAI_NOINLINE __declspec(noinline) +#elif defined(__GNUC__) +#define WAI_NOINLINE __attribute__((noinline)) +#else +#error unsupported compiler +#endif +#endif + +#if defined(_MSC_VER) +#define WAI_RETURN_ADDRESS() _ReturnAddress() +#elif defined(__GNUC__) +#define WAI_RETURN_ADDRESS() __builtin_extract_return_addr(__builtin_return_address(0)) +#else +#error unsupported compiler +#endif + +#if defined(_WIN32) + +#define WIN32_LEAN_AND_MEAN +#if defined(_MSC_VER) +#pragma warning(push, 3) +#endif +#include +#include +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + +static int WAI_PREFIX(getModulePath_)(HMODULE module, char* out, int capacity, int* dirname_length) +{ + wchar_t buffer1[1]; + wchar_t buffer2[MAX_PATH]; + wchar_t* path = NULL; + int length = -1; + + for (;;) + { + DWORD size; + int length_; + + size = GetModuleFileNameW(module, buffer1, sizeof(buffer1) / sizeof(buffer1[0])); + + if (size == 0) + break; + else if (size == (DWORD)(sizeof(buffer1) / sizeof(buffer1[0]))) + { + DWORD size_ = size; + do + { + wchar_t* path_; + + path_ = (wchar_t*)WAI_REALLOC(path, sizeof(wchar_t) * size_ * 2); + if (!path_) + break; + size_ *= 2; + path = path_; + size = GetModuleFileNameW(module, path, size_); + } + while (size == size_); + + if (size == size_) + break; + } + else + path = buffer1; + + if (!_wfullpath(buffer2, path, MAX_PATH)) + break; + length_ = WideCharToMultiByte(CP_UTF8, 0, buffer2, -1, out, capacity, NULL, NULL); + + if (length_ == 0) + length_ = WideCharToMultiByte(CP_UTF8, 0, buffer2, -1, NULL, 0, NULL, NULL); + if (length_ == 0) + break; + + if (length_ <= capacity && dirname_length) + { + int i; + + for (i = length_ - 1; i >= 0; --i) + { + if (out[i] == '\\') + { + *dirname_length = i; + break; + } + } + } + + length = length_; + + break; + } + + if (path != buffer1) + WAI_FREE(path); + + return length; +} + +WAI_NOINLINE +WAI_FUNCSPEC +int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length) +{ + return WAI_PREFIX(getModulePath_)(NULL, out, capacity, dirname_length); +} + +WAI_NOINLINE +WAI_FUNCSPEC +int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length) +{ + HMODULE module; + int length = -1; + +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable: 4054) +#endif + if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCTSTR)WAI_RETURN_ADDRESS(), &module)) +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + { + length = WAI_PREFIX(getModulePath_)(module, out, capacity, dirname_length); + } + + return length; +} + +#elif defined(__linux__) + +#include +#include +#include +#include +#ifndef __STDC_FORMAT_MACROS +#define __STDC_FORMAT_MACROS +#endif +#include + +#if !defined(WAI_PROC_SELF_EXE) +#define WAI_PROC_SELF_EXE "/proc/self/exe" +#endif + +WAI_FUNCSPEC +int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length) +{ + char buffer[PATH_MAX]; + char* resolved = NULL; + int length = -1; + + for (;;) + { + resolved = realpath(WAI_PROC_SELF_EXE, buffer); + if (!resolved) + break; + + length = (int)strlen(resolved); + if (length <= capacity) + { + memcpy(out, resolved, length); + + if (dirname_length) + { + int i; + + for (i = length - 1; i >= 0; --i) + { + if (out[i] == '/') + { + *dirname_length = i; + break; + } + } + } + } + + break; + } + + return length; +} + +#if !defined(WAI_PROC_SELF_MAPS_RETRY) +#define WAI_PROC_SELF_MAPS_RETRY 5 +#endif + +#if !defined(WAI_PROC_SELF_MAPS) +#define WAI_PROC_SELF_MAPS "/proc/self/maps" +#endif + +#if defined(__ANDROID__) || defined(ANDROID) +#include +#include +#endif + +WAI_NOINLINE +WAI_FUNCSPEC +int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length) +{ + int length = -1; + FILE* maps = NULL; + int i; + + for (i = 0; i < WAI_PROC_SELF_MAPS_RETRY; ++i) + { + maps = fopen(WAI_PROC_SELF_MAPS, "r"); + if (!maps) + break; + + for (;;) + { + char buffer[PATH_MAX < 1024 ? 1024 : PATH_MAX]; + uint64_t low, high; + char perms[5]; + uint64_t offset; + uint32_t major, minor; + char path[PATH_MAX]; + uint32_t inode; + + if (!fgets(buffer, sizeof(buffer), maps)) + break; + + if (sscanf(buffer, "%" PRIx64 "-%" PRIx64 " %s %" PRIx64 " %x:%x %u %s\n", &low, &high, perms, &offset, &major, &minor, &inode, path) == 8) + { + uint64_t addr = (uint64_t)(uintptr_t)WAI_RETURN_ADDRESS(); + if (low <= addr && addr <= high) + { + char* resolved; + + resolved = realpath(path, buffer); + if (!resolved) + break; + + length = (int)strlen(resolved); +#if defined(__ANDROID__) || defined(ANDROID) + if (length > 4 + &&buffer[length - 1] == 'k' + &&buffer[length - 2] == 'p' + &&buffer[length - 3] == 'a' + &&buffer[length - 4] == '.') + { + int fd = open(path, O_RDONLY); + char* begin; + char* p; + + begin = (char*)mmap(0, offset, PROT_READ, MAP_SHARED, fd, 0); + p = begin + offset; + + while (p >= begin) // scan backwards + { + if (*((uint32_t*)p) == 0x04034b50UL) // local file header found + { + uint16_t length_ = *((uint16_t*)(p + 26)); + + if (length + 2 + length_ < (int)sizeof(buffer)) + { + memcpy(&buffer[length], "!/", 2); + memcpy(&buffer[length + 2], p + 30, length_); + length += 2 + length_; + } + + break; + } + + p -= 4; + } + + munmap(begin, offset); + close(fd); + } +#endif + if (length <= capacity) + { + memcpy(out, resolved, length); + + if (dirname_length) + { + int i; + + for (i = length - 1; i >= 0; --i) + { + if (out[i] == '/') + { + *dirname_length = i; + break; + } + } + } + } + + break; + } + } + } + + fclose(maps); + + if (length != -1) + break; + } + + return length; +} + +#elif defined(__APPLE__) + +#define _DARWIN_BETTER_REALPATH +#include +#include +#include +#include +#include + +WAI_FUNCSPEC +int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length) +{ + char buffer1[PATH_MAX]; + char buffer2[PATH_MAX]; + char* path = buffer1; + char* resolved = NULL; + int length = -1; + + for (;;) + { + uint32_t size = (uint32_t)sizeof(buffer1); + if (_NSGetExecutablePath(path, &size) == -1) + { + path = (char*)WAI_MALLOC(size); + if (!_NSGetExecutablePath(path, &size)) + break; + } + + resolved = realpath(path, buffer2); + if (!resolved) + break; + + length = (int)strlen(resolved); + if (length <= capacity) + { + memcpy(out, resolved, length); + + if (dirname_length) + { + int i; + + for (i = length - 1; i >= 0; --i) + { + if (out[i] == '/') + { + *dirname_length = i; + break; + } + } + } + } + + break; + } + + if (path != buffer1) + WAI_FREE(path); + + return length; +} + +WAI_NOINLINE +WAI_FUNCSPEC +int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length) +{ + char buffer[PATH_MAX]; + char* resolved = NULL; + int length = -1; + + for(;;) + { + Dl_info info; + + if (dladdr(WAI_RETURN_ADDRESS(), &info)) + { + resolved = realpath(info.dli_fname, buffer); + if (!resolved) + break; + + length = (int)strlen(resolved); + if (length <= capacity) + { + memcpy(out, resolved, length); + + if (dirname_length) + { + int i; + + for (i = length - 1; i >= 0; --i) + { + if (out[i] == '/') + { + *dirname_length = i; + break; + } + } + } + } + } + + break; + } + + return length; +} + +#elif defined(__QNXNTO__) + +#include +#include +#include +#include +#include + +#if !defined(WAI_PROC_SELF_EXE) +#define WAI_PROC_SELF_EXE "/proc/self/exefile" +#endif + +WAI_FUNCSPEC +int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length) +{ + char buffer1[PATH_MAX]; + char buffer2[PATH_MAX]; + char* resolved = NULL; + FILE* self_exe = NULL; + int length = -1; + + for (;;) + { + self_exe = fopen(WAI_PROC_SELF_EXE, "r"); + if (!self_exe) + break; + + if (!fgets(buffer1, sizeof(buffer1), self_exe)) + break; + + resolved = realpath(buffer1, buffer2); + if (!resolved) + break; + + length = (int)strlen(resolved); + if (length <= capacity) + { + memcpy(out, resolved, length); + + if (dirname_length) + { + int i; + + for (i = length - 1; i >= 0; --i) + { + if (out[i] == '/') + { + *dirname_length = i; + break; + } + } + } + } + + break; + } + + fclose(self_exe); + + return length; +} + +WAI_FUNCSPEC +int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length) +{ + char buffer[PATH_MAX]; + char* resolved = NULL; + int length = -1; + + for(;;) + { + Dl_info info; + + if (dladdr(WAI_RETURN_ADDRESS(), &info)) + { + resolved = realpath(info.dli_fname, buffer); + if (!resolved) + break; + + length = (int)strlen(resolved); + if (length <= capacity) + { + memcpy(out, resolved, length); + + if (dirname_length) + { + int i; + + for (i = length - 1; i >= 0; --i) + { + if (out[i] == '/') + { + *dirname_length = i; + break; + } + } + } + } + } + + break; + } + + return length; +} + +#elif defined(__FreeBSD__) + +#include +#include +#include +#include +#include +#include + +WAI_FUNCSPEC +int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length) +{ + char buffer1[PATH_MAX]; + char buffer2[PATH_MAX]; + char* path = buffer1; + char* resolved = NULL; + int length = -1; + + for (;;) + { + int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; + size_t size = sizeof(buffer1); + + if (sysctl(mib, (u_int)(sizeof(mib) / sizeof(mib[0])), path, &size, NULL, 0) != 0) + break; + + resolved = realpath(path, buffer2); + if (!resolved) + break; + + length = (int)strlen(resolved); + if (length <= capacity) + { + memcpy(out, resolved, length); + + if (dirname_length) + { + int i; + + for (i = length - 1; i >= 0; --i) + { + if (out[i] == '/') + { + *dirname_length = i; + break; + } + } + } + } + + break; + } + + if (path != buffer1) + WAI_FREE(path); + + return length; +} + +WAI_NOINLINE +WAI_FUNCSPEC +int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length) +{ + char buffer[PATH_MAX]; + char* resolved = NULL; + int length = -1; + + for(;;) + { + Dl_info info; + + if (dladdr(WAI_RETURN_ADDRESS(), &info)) + { + resolved = realpath(info.dli_fname, buffer); + if (!resolved) + break; + + length = (int)strlen(resolved); + if (length <= capacity) + { + memcpy(out, resolved, length); + + if (dirname_length) + { + int i; + + for (i = length - 1; i >= 0; --i) + { + if (out[i] == '/') + { + *dirname_length = i; + break; + } + } + } + } + } + + break; + } + + return length; +} + +#else + +#error unsupported platform + +#endif + +#ifdef __cplusplus +} +#endif diff --git a/lib/whereami/src/whereami.h b/lib/whereami/src/whereami.h new file mode 100644 index 0000000..6c81af8 --- /dev/null +++ b/lib/whereami/src/whereami.h @@ -0,0 +1,65 @@ +// (‑●‑●)> released under the WTFPL v2 license, by Gregory Pakosz (@gpakosz) +// https://github.com/gpakosz/whereami + +#ifndef WHEREAMI_H +#define WHEREAMI_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef WAI_FUNCSPEC + #define WAI_FUNCSPEC +#endif +#ifndef WAI_PREFIX +#define WAI_PREFIX(function) wai_##function +#endif + +/** + * Returns the path to the current executable. + * + * Usage: + * - first call `int length = wai_getExecutablePath(NULL, 0, NULL);` to + * retrieve the length of the path + * - allocate the destination buffer with `path = (char*)malloc(length + 1);` + * - call `wai_getExecutablePath(path, length, NULL)` again to retrieve the + * path + * - add a terminal NUL character with `path[length] = '\0';` + * + * @param out destination buffer, optional + * @param capacity destination buffer capacity + * @param dirname_length optional recipient for the length of the dirname part + * of the path. + * + * @return the length of the executable path on success (without a terminal NUL + * character), otherwise `-1` + */ +WAI_FUNCSPEC +int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length); + +/** + * Returns the path to the current module + * + * Usage: + * - first call `int length = wai_getModulePath(NULL, 0, NULL);` to retrieve + * the length of the path + * - allocate the destination buffer with `path = (char*)malloc(length + 1);` + * - call `wai_getModulePath(path, length, NULL)` again to retrieve the path + * - add a terminal NUL character with `path[length] = '\0';` + * + * @param out destination buffer, optional + * @param capacity destination buffer capacity + * @param dirname_length optional recipient for the length of the dirname part + * of the path. + * + * @return the length of the module path on success (without a terminal NUL + * character), otherwise `-1` + */ +WAI_FUNCSPEC +int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length); + +#ifdef __cplusplus +} +#endif + +#endif // #ifndef WHEREAMI_H diff --git a/src/centiseconds.cpp b/src/centiseconds.cpp index 9e7d978..f548688 100644 --- a/src/centiseconds.cpp +++ b/src/centiseconds.cpp @@ -1,6 +1,6 @@ #include #include -#include "Centiseconds.h" +#include "centiseconds.h" std::ostream& operator <<(std::ostream& stream, const centiseconds cs) { return stream << cs.count() << "cs"; diff --git a/src/phoneExtraction.h b/src/phoneExtraction.h index 1f5d14d..b0fea11 100644 --- a/src/phoneExtraction.h +++ b/src/phoneExtraction.h @@ -2,7 +2,7 @@ #include "audio/AudioClip.h" #include "Phone.h" -#include "progressBar.h" +#include "ProgressBar.h" #include "BoundedTimeline.h" BoundedTimeline detectPhones( diff --git a/src/platformTools.cpp b/src/platformTools.cpp index 36e0339..581c1d0 100644 --- a/src/platformTools.cpp +++ b/src/platformTools.cpp @@ -5,125 +5,29 @@ #include #include #include - #include "platformTools.h" +#include using boost::filesystem::path; using std::string; -constexpr int InitialBufferSize = 256; - -#if (BOOST_OS_CYGWIN || BOOST_OS_WINDOWS) - - #include - - path getBinPathImpl() { - std::vector buffer(InitialBufferSize); - - // Try to get the executable path with a buffer of MAX_PATH characters. - DWORD result = GetModuleFileNameW(0, buffer.data(), buffer.size()); - - // As long the function returns the buffer size, it is indicating that the buffer - // was too small. Keep doubling the buffer size until it fits. - while (result == buffer.size()) { - buffer.resize(buffer.size() * 2); - result = GetModuleFileNameW(0, buffer.data(), buffer.size()); - } - - // If the function returned 0, something went wrong - if (result == 0) { - DWORD error = GetLastError(); - throw std::runtime_error(fmt::format("`GetModuleFileNameW` failed. Error code: {0}", error)); - } - - return path(buffer.data()); - } - -#elif (BOOST_OS_MACOS) - - #include - - path getBinPathImpl() { - std::vector buffer(InitialBufferSize); - uint32_t size = buffer.size(); - int result = _NSGetExecutablePath(buffer.data(), &size); - if (result == -1) { - // Insufficient buffer. Resize. - buffer.resize(size); - result = _NSGetExecutablePath(buffer.data(), &size); - } - if (result != 0) { - throw std::runtime_error(fmt::format("`_NSGetExecutablePath` failed. Error code: {0}", result)); - } - return path(buffer.data()); - } - -#elif (BOOST_OS_SOLARIS) - - #include - - path getBinPathImpl() { - const char* executableName = getexecname(); - if (!executableName) { - throw std::runtime_error("`getexecname` failed.")); - } - return path(executableName); - } - -#elif (BOOST_OS_BSD) - - #include - #include - - path getBinPathImpl() { - // Determine required buffer size - std::array mib = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; - size_t size = 0; - sysctl(mib.data(), mib.size(), nullptr, &size, nullptr, 0); - - // Get path - std::vector buffer(size); - int result = sysctl(mib.data(), mib.size(), buffer.data(), &size, nullptr, 0); - if (result == -1) { - throw std::runtime_error(fmt::format("`sysctl` failed. Error code: {0}", errno)); - } - - return path(std::string(buffer, size)); - } - -#elif (BOOST_OS_LINUX) - - #include - #include - - path getBinPathImpl() { - // Determine required buffer size - stat info; - const char* selfPath = "/proc/self/exe"; - int result = lstat(selfPath, &stat); - if (result == -1) { - throw std::runtime_error(fmt::format("`lstat` failed. Error code: {0}", errno)); - } - - // Get path - std::vector buffer(info.st_size); - result = readlink(selfPath, buffer.data(), buffer.size()); - if (result == -1) { - throw std::runtime_error(fmt::format("`readlink` failed. Error code: {0}", errno)); - } - - return path(std::string(buffer, buffer.size())); - } - -#else - - #error "Unsupported platform." - -#endif - path getBinPath() { try { - static path binPath(boost::filesystem::canonical(getBinPathImpl()).make_preferred()); + // Determine path length + int pathLength = wai_getExecutablePath(nullptr, 0, nullptr); + if (pathLength == -1) { + throw std::runtime_error("Error determining path length."); + } + + // Get path + std::vector buffer(pathLength); + if (wai_getExecutablePath(buffer.data(), buffer.size(), nullptr) == -1) { + throw std::runtime_error("Error reading path."); + } + + // Convert to boost::filesystem::path + string pathString(buffer.data(), buffer.size()); + static path binPath(boost::filesystem::canonical(pathString).make_preferred()); return binPath; } catch (...) { std::throw_with_nested(std::runtime_error("Could not determine path of bin directory.") ); @@ -142,9 +46,8 @@ path getTempFilePath() { } std::tm getLocalTime(const time_t& time) { - // Xcode doesn't support localtime_s. tm timeInfo; -#if (BOOST_OS_MACOS) +#if (BOOST_OS_UNIX || BOOST_OS_MACOS) localtime_r(&time, &timeInfo); #else localtime_s(&timeInfo, &time); @@ -153,9 +56,8 @@ std::tm getLocalTime(const time_t& time) { } std::string errorNumberToString(int errorNumber) { - // Xcode doesn't support strerror_s. char message[256]; -#if (BOOST_OS_MACOS) +#if (BOOST_OS_UNIX || BOOST_OS_MACOS) strerror_r(errorNumber, message, sizeof message); #else strerror_s(message, sizeof message, errorNumber);