From f50cd2892ac7cd4746396fb0461fe02bc9a3d1db Mon Sep 17 00:00:00 2001
From: John Preston <johnprestonmail@gmail.com>
Date: Sun, 28 Aug 2016 13:36:51 -0600
Subject: [PATCH] First attempt to build OS X version using GYP/Ninja.

Utils and codegen builds are ready, bundle is not prepared yet.
---
 Telegram/SourceFiles/_other/genlang.cpp |   9 +-
 Telegram/SourceFiles/_other/packer.cpp  |   9 +-
 Telegram/SourceFiles/stdafx.cpp         |   6 --
 Telegram/gyp/Telegram.gyp               | 112 +++++++-----------------
 Telegram/gyp/codegen.gyp                |   3 +
 Telegram/gyp/codegen_rules.gypi         |  16 ++--
 Telegram/gyp/common.gypi                |  52 +++++++----
 Telegram/gyp/common_executable.gypi     |   1 +
 Telegram/gyp/qt.gypi                    | 109 ++++++++++++++---------
 Telegram/gyp/refresh.sh                 |  13 +++
 Telegram/gyp/settings_mac.gypi          |  64 ++++++++++++++
 Telegram/gyp/telegram_linux.gypi        |  36 ++++++++
 Telegram/gyp/telegram_mac.gypi          |  68 ++++++++++++++
 Telegram/gyp/telegram_qrc.gypi          |  50 +++++++++++
 Telegram/gyp/telegram_win.gypi          |  83 ++++++++++++++++++
 Telegram/gyp/utils.gyp                  |  75 +++++++++++-----
 16 files changed, 516 insertions(+), 190 deletions(-)
 create mode 100755 Telegram/gyp/refresh.sh
 create mode 100644 Telegram/gyp/settings_mac.gypi
 create mode 100644 Telegram/gyp/telegram_linux.gypi
 create mode 100644 Telegram/gyp/telegram_mac.gypi
 create mode 100644 Telegram/gyp/telegram_qrc.gypi
 create mode 100644 Telegram/gyp/telegram_win.gypi

diff --git a/Telegram/SourceFiles/_other/genlang.cpp b/Telegram/SourceFiles/_other/genlang.cpp
index f8924fadb..17cb66065 100644
--- a/Telegram/SourceFiles/_other/genlang.cpp
+++ b/Telegram/SourceFiles/_other/genlang.cpp
@@ -27,14 +27,7 @@ Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
 #endif
 
 #ifdef Q_OS_MAC
-Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin)
-Q_IMPORT_PLUGIN(QDDSPlugin)
-Q_IMPORT_PLUGIN(QICNSPlugin)
-Q_IMPORT_PLUGIN(QICOPlugin)
-Q_IMPORT_PLUGIN(QTgaPlugin)
-Q_IMPORT_PLUGIN(QTiffPlugin)
-Q_IMPORT_PLUGIN(QWbmpPlugin)
-Q_IMPORT_PLUGIN(QWebpPlugin)
+//Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin)
 #endif
 
 typedef unsigned int uint32;
diff --git a/Telegram/SourceFiles/_other/packer.cpp b/Telegram/SourceFiles/_other/packer.cpp
index 08f17ccb5..95acbaea3 100644
--- a/Telegram/SourceFiles/_other/packer.cpp
+++ b/Telegram/SourceFiles/_other/packer.cpp
@@ -23,14 +23,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
 #include <QtCore/QtPlugin>
 
 #ifdef Q_OS_MAC
-Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin)
-Q_IMPORT_PLUGIN(QDDSPlugin)
-Q_IMPORT_PLUGIN(QICNSPlugin)
-Q_IMPORT_PLUGIN(QICOPlugin)
-Q_IMPORT_PLUGIN(QTgaPlugin)
-Q_IMPORT_PLUGIN(QTiffPlugin)
-Q_IMPORT_PLUGIN(QWbmpPlugin)
-Q_IMPORT_PLUGIN(QWebpPlugin)
+//Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin)
 #endif
 
 bool AlphaChannel = false;
diff --git a/Telegram/SourceFiles/stdafx.cpp b/Telegram/SourceFiles/stdafx.cpp
index 0cef37654..680dd0cd3 100644
--- a/Telegram/SourceFiles/stdafx.cpp
+++ b/Telegram/SourceFiles/stdafx.cpp
@@ -30,12 +30,6 @@ Q_IMPORT_PLUGIN(QWebpPlugin)
 #elif defined Q_OS_MAC // Q_OS_WIN
 Q_IMPORT_PLUGIN(QGenericEnginePlugin)
 Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin)
-Q_IMPORT_PLUGIN(QDDSPlugin)
-Q_IMPORT_PLUGIN(QICNSPlugin)
-Q_IMPORT_PLUGIN(QICOPlugin)
-Q_IMPORT_PLUGIN(QTgaPlugin)
-Q_IMPORT_PLUGIN(QTiffPlugin)
-Q_IMPORT_PLUGIN(QWbmpPlugin)
 Q_IMPORT_PLUGIN(QWebpPlugin)
 #elif defined Q_OS_LINUX // Q_OS_LINUX
 Q_IMPORT_PLUGIN(QComposePlatformInputContextPlugin)
diff --git a/Telegram/gyp/Telegram.gyp b/Telegram/gyp/Telegram.gyp
index fe41c5951..574af1a3f 100644
--- a/Telegram/gyp/Telegram.gyp
+++ b/Telegram/gyp/Telegram.gyp
@@ -24,6 +24,7 @@
       'libs_loc': '../../../Libraries',
       'src_loc': '../SourceFiles',
       'res_loc': '../Resources',
+      'minizip_loc': '../ThirdParty/minizip',
       'style_files': [
         '<(res_loc)/basic.style',
         '<(res_loc)/basic_types.style',
@@ -35,13 +36,14 @@
         '<(src_loc)/profile/profile.style',
         '<(src_loc)/ui/widgets/widgets.style',
       ],
-      'qrc_files': [
-        '<(res_loc)/telegram.qrc',
-        '<(res_loc)/telegram_emojis.qrc',
-      ],
+      'mac_target': '10.8',
     },
     'includes': [
       'common_executable.gypi',
+      'telegram_qrc.gypi',
+      'telegram_win.gypi',
+      'telegram_mac.gypi',
+      'telegram_linux.gypi',
       'qt.gypi',
       'codegen_rules.gypi',
     ],
@@ -61,12 +63,14 @@
       '<(src_loc)',
       '<(SHARED_INTERMEDIATE_DIR)',
       '<(libs_loc)/breakpad/src',
+      '<(libs_loc)/crashpad/crashpad',
+      '<(libs_loc)/crashpad/crashpad/third_party/mini_chromium/mini_chromium',
       '<(libs_loc)/lzma/C',
       '<(libs_loc)/libexif-0.6.20',
       '<(libs_loc)/zlib-1.2.8',
       '<(libs_loc)/ffmpeg',
       '<(libs_loc)/openal-soft/include',
-      '../ThirdParty/minizip',
+      '<(minizip_loc)',
     ],
     'library_dirs': [
       '<(libs_loc)/ffmpeg',
@@ -277,6 +281,12 @@
       '<(src_loc)/overview/overview_layout.h',
       '<(src_loc)/pspecific_win.cpp',
       '<(src_loc)/pspecific_win.h',
+      '<(src_loc)/pspecific_mac.cpp',
+      '<(src_loc)/pspecific_mac.h',
+      '<(src_loc)/pspecific_mac_p.mm',
+      '<(src_loc)/pspecific_mac_p.h',
+      '<(src_loc)/pspecific_linux.cpp',
+      '<(src_loc)/pspecific_linux.h',
       '<(src_loc)/platform/linux/linux_gdk_helper.cpp',
       '<(src_loc)/platform/linux/linux_gdk_helper.h',
       '<(src_loc)/platform/linux/linux_libs.cpp',
@@ -407,20 +417,6 @@
       '<(src_loc)/window/top_bar_widget.h',
     ],
     'configurations': {
-      'Debug': {
-        'include_dirs': [
-          '<(libs_loc)/openssl_debug/Debug/include',
-        ],
-        'library_dirs': [
-          '<(libs_loc)/lzma/C/Util/LzmaLib/Debug',
-          '<(libs_loc)/libexif-0.6.20/win32/Debug',
-          '<(libs_loc)/opus/win32/VS2010/Win32/Debug',
-          '<(libs_loc)/openal-soft/build/Debug',
-          '<(libs_loc)/zlib-1.2.8/contrib/vstudio/vc11/x86/ZlibStatDebug',
-          '<(libs_loc)/openssl_debug/Debug/lib',
-          '<(libs_loc)/breakpad/src/client/windows/Debug',
-        ],
-      },
       'Release': {
         'conditions': [
           ['"<(official_build_target)" != ""', {
@@ -429,79 +425,18 @@
             ],
           }],
         ],
-        'include_dirs': [
-          '<(libs_loc)/openssl/Release/include',
-        ],
-        'library_dirs': [
-          '<(libs_loc)/lzma/C/Util/LzmaLib/Release',
-          '<(libs_loc)/libexif-0.6.20/win32/Release',
-          '<(libs_loc)/opus/win32/VS2010/Win32/Release',
-          '<(libs_loc)/openal-soft/build/Release',
-          '<(libs_loc)/zlib-1.2.8/contrib/vstudio/vc11/x86/ZlibStatRelease',
-          '<(libs_loc)/openssl/Release/lib',
-          '<(libs_loc)/breakpad/src/client/windows/Release',
-        ],
       },
     },
-    'libraries': [
-      'libeay32',
-      'ssleay32',
-      'Crypt32',
-      'zlibstat',
-      'LzmaLib',
-      'lib_exif',
-      'UxTheme',
-      'DbgHelp',
-      'OpenAL32',
-      'common',
-      'libavformat\libavformat.a',
-      'libavcodec\libavcodec.a',
-      'libavutil\libavutil.a',
-      'libswresample\libswresample.a',
-      'libswscale\libswscale.a',
-      'opus',
-      'celt',
-      'silk_common',
-      'silk_float',
-      'lib\common',
-      'lib\exception_handler',
-      'lib\crash_generation_client',
-    ],
     'conditions': [
       [ '"<(official_build_target)" != ""', {
         'dependencies': [
           'utils.gyp:Packer',
         ],
       }],
-      [ 'build_linux', {
-        'variables': {
-          'qrc_files': [
-            '<(res_loc)/telegram_linux.qrc',
-          ],
-        }
-      }],
-      [ 'build_mac', {
-        'variables': {
-          'qrc_files': [
-            '<(res_loc)/telegram_mac.qrc',
-          ],
-        }
-      }],
-      [ 'build_win', {
-        'msvs_precompiled_source': '<(src_loc)/stdafx.cpp',
-        'msvs_precompiled_header': '<(src_loc)/stdafx.h',
-        'msbuild_toolset': 'v140_xp',     #Windows7.1SDK
-        'sources': [
-          '<(res_loc)/winrc/Telegram.rc',
-        ],
-        'variables': {
-          'qrc_files': [
-            '<(res_loc)/telegram_wnd.qrc',
-          ],
-        }
-      }],
       [ '"<(build_linux)" != "1"', {
         'sources!': [
+          '<(src_loc)/pspecific_linux.cpp',
+          '<(src_loc)/pspecific_linux.h',
           '<(src_loc)/platform/linux/linux_gdk_helper.cpp',
           '<(src_loc)/platform/linux/linux_gdk_helper.h',
           '<(src_loc)/platform/linux/linux_libs.cpp',
@@ -514,12 +449,25 @@
       }],
       [ '"<(build_mac)" != "1"', {
         'sources!': [
+          '<(src_loc)/pspecific_mac.cpp',
+          '<(src_loc)/pspecific_mac.h',
+          '<(src_loc)/pspecific_mac_p.mm',
+          '<(src_loc)/pspecific_mac_p.h',
           '<(src_loc)/platform/mac/main_window_mac.mm',
           '<(src_loc)/platform/mac/main_window_mac.h',
         ],
       }],
       [ '"<(build_win)" != "1"', {
+        'sources': [
+          '<(minizip_loc)/crypt.h',
+          '<(minizip_loc)/ioapi.c',
+          '<(minizip_loc)/ioapi.h',
+          '<(minizip_loc)/zip.c',
+          '<(minizip_loc)/zip.h',
+        ],
         'sources!': [
+          '<(src_loc)/pspecific_win.cpp',
+          '<(src_loc)/pspecific_win.h',
           '<(src_loc)/platform/win/main_window_win.cpp',
           '<(src_loc)/platform/win/main_window_win.h',
           '<(src_loc)/platform/win/windows_app_user_model_id.cpp',
diff --git a/Telegram/gyp/codegen.gyp b/Telegram/gyp/codegen.gyp
index ecdd46014..208c90530 100644
--- a/Telegram/gyp/codegen.gyp
+++ b/Telegram/gyp/codegen.gyp
@@ -24,6 +24,7 @@
       'libs_loc': '../../../Libraries',
       'src_loc': '../SourceFiles',
       'gen_loc': '../GeneratedFiles',
+      'mac_target': '10.10',
     },
     'includes': [
       'common_executable.gypi',
@@ -45,6 +46,7 @@
     'variables': {
       'libs_loc': '../../../Libraries',
       'src_loc': '../SourceFiles',
+      'mac_target': '10.10',
     },
     'includes': [
       'common_executable.gypi',
@@ -88,6 +90,7 @@
     'variables': {
       'libs_loc': '../../../Libraries',
       'src_loc': '../SourceFiles',
+      'mac_target': '10.10',
     },
     'includes': [
       'common_executable.gypi',
diff --git a/Telegram/gyp/codegen_rules.gypi b/Telegram/gyp/codegen_rules.gypi
index a437037e9..3c5cc5592 100644
--- a/Telegram/gyp/codegen_rules.gypi
+++ b/Telegram/gyp/codegen_rules.gypi
@@ -21,7 +21,7 @@
   'actions': [{
     'action_name': 'update_sprites',
     'inputs': [
-      '<(PRODUCT_DIR)/codegen_style.exe',
+      '<(PRODUCT_DIR)/codegen_style<(exe_ext)',
       '<(res_loc)/basic.style',
       '<(res_loc)/art/sprite.png',
       '<(res_loc)/art/sprite_200x.png',
@@ -31,7 +31,7 @@
       '<(res_loc)/art/sprite_150x.png',
     ],
     'action': [
-      '<(PRODUCT_DIR)/codegen_style.exe',
+      '<(PRODUCT_DIR)/codegen_style<(exe_ext)',
       '-I<(res_loc)', '-I<(src_loc)',
       '--skip-styles', '<(res_loc)/basic.style',
     ],
@@ -71,7 +71,7 @@
   }, {
     'action_name': 'codegen_lang',
     'inputs': [
-      '<(PRODUCT_DIR)/MetaLang.exe',
+      '<(PRODUCT_DIR)/MetaLang<(exe_ext)',
       '<(res_loc)/langs/lang.strings',
     ],
     'outputs': [
@@ -79,7 +79,7 @@
       '<(SHARED_INTERMEDIATE_DIR)/lang_auto.h',
     ],
     'action': [
-      '<(PRODUCT_DIR)/MetaLang.exe',
+      '<(PRODUCT_DIR)/MetaLang<(exe_ext)',
       '-lang_in', '<(res_loc)/langs/lang.strings',
       '-lang_out', '<(SHARED_INTERMEDIATE_DIR)/lang_auto',
     ],
@@ -88,7 +88,7 @@
   }, {
     'action_name': 'codegen_numbers',
     'inputs': [
-      '<(PRODUCT_DIR)/codegen_numbers.exe',
+      '<(PRODUCT_DIR)/codegen_numbers<(exe_ext)',
       '<(res_loc)/numbers.txt',
     ],
     'outputs': [
@@ -96,7 +96,7 @@
       '<(SHARED_INTERMEDIATE_DIR)/numbers.h',
     ],
     'action': [
-      '<(PRODUCT_DIR)/codegen_numbers.exe',
+      '<(PRODUCT_DIR)/codegen_numbers<(exe_ext)',
       '-o<(SHARED_INTERMEDIATE_DIR)', '<(res_loc)/numbers.txt',
     ],
     'message': 'codegen_numbers-ing numbers.txt..',
@@ -106,7 +106,7 @@
     'rule_name': 'codegen_style',
     'extension': 'style',
     'inputs': [
-      '<(PRODUCT_DIR)/codegen_style.exe',
+      '<(PRODUCT_DIR)/codegen_style<(exe_ext)',
       '<(SHARED_INTERMEDIATE_DIR)/update_dependent_styles.timestamp',
     ],
     'outputs': [
@@ -114,7 +114,7 @@
       '<(SHARED_INTERMEDIATE_DIR)/styles/style_<(RULE_INPUT_ROOT).cpp',
     ],
     'action': [
-      '<(PRODUCT_DIR)/codegen_style.exe',
+      '<(PRODUCT_DIR)/codegen_style<(exe_ext)',
       '-I<(res_loc)', '-I<(src_loc)', '--skip-sprites',
       '-o<(SHARED_INTERMEDIATE_DIR)/styles', '<(RULE_INPUT_PATH)',
     ],
diff --git a/Telegram/gyp/common.gypi b/Telegram/gyp/common.gypi
index 750d157b7..d230c81fd 100644
--- a/Telegram/gyp/common.gypi
+++ b/Telegram/gyp/common.gypi
@@ -21,31 +21,44 @@
   'variables': {
     'variables': {
       'variables': {
-        'build_os%': '<(OS)',
+        'variables': {
+          'variables': {
+            'build_os%': '<(OS)',
+          },
+          'build_os%': '<(build_os)',
+          'conditions': [
+            [ 'build_os == "win"', {
+              'build_win': 1,
+            }, {
+              'build_win': 0,
+            }],
+            [ 'build_os == "mac"', {
+              'build_mac': 1,
+            }, {
+              'build_mac': 0,
+            }],
+            [ 'build_os == "linux"', {
+              'build_linux': 1,
+            }, {
+              'build_linux': 0,
+            }],
+          ],
+        },
+        'build_os%': '<(build_os)',
+        'build_win%': '<(build_win)',
+        'build_mac%': '<(build_mac)',
+        'build_linux%': '<(build_linux)',
       },
       'build_os%': '<(build_os)',
-      'conditions': [
-        [ 'build_os == "win"', {
-          'build_win': 1,
-        }, {
-          'build_win': 0,
-        }],
-        [ 'build_os == "mac"', {
-          'build_mac': 1,
-        }, {
-          'build_mac': 0,
-        }],
-        [ 'build_os == "linux"', {
-          'build_linux': 1,
-        }, {
-          'build_linux': 0,
-        }],
-      ],
+      'build_win%': '<(build_win)',
+      'build_mac%': '<(build_mac)',
+      'build_linux%': '<(build_linux)',
     },
     'build_os%': '<(build_os)',
     'build_win%': '<(build_win)',
     'build_mac%': '<(build_mac)',
     'build_linux%': '<(build_linux)',
+    'mac_target%': '10.8',
 
     # GYP does not support per-configuration libraries :(
     # So they will be emulated through additional link flags,
@@ -54,13 +67,16 @@
       [ 'build_win', {
         'ld_lib_prefix': '',
         'ld_lib_postfix': '.lib',
+        'exe_ext': '.exe',
       }, {
         'ld_lib_prefix': '-l',
         'ld_lib_postfix': '',
+        'exe_ext': '',
       }],
     ],
     'ld_lib_prefix': '<(ld_lib_prefix)',
     'ld_lib_postfix': '<(ld_lib_postfix)',
+    'exe_ext': '<(exe_ext)',
 
     'library%': 'static_library',
 
diff --git a/Telegram/gyp/common_executable.gypi b/Telegram/gyp/common_executable.gypi
index 5fa96f580..28be1d73d 100644
--- a/Telegram/gyp/common_executable.gypi
+++ b/Telegram/gyp/common_executable.gypi
@@ -25,5 +25,6 @@
   'includes': [
     'common.gypi',
     'settings_win.gypi',
+    'settings_mac.gypi',
   ],
 }
diff --git a/Telegram/gyp/qt.gypi b/Telegram/gyp/qt.gypi
index 4e394e034..d3ae26b1b 100644
--- a/Telegram/gyp/qt.gypi
+++ b/Telegram/gyp/qt.gypi
@@ -21,51 +21,61 @@
   'variables': {
     'variables': {
       'variables': {
+        'variables': {
+          'qt_libs': [
+            'Qt5Core',
+            'qtpcre',
+            'Qt5Gui',
+            'qtfreetype',
+            'Qt5Widgets',
+            'qtharfbuzzng',
+            'Qt5Network',
+            'Qt5PlatformSupport',
+            'Qt5PrintSupport',
+            'qwebp',
+          ],
+        },
         'qt_version%': '5.6.0',
+        'conditions': [
+          [ 'build_win', {
+            'qt_lib_prefix': '<(ld_lib_prefix)',
+            'qt_lib_debug_postfix': 'd<(ld_lib_postfix)',
+            'qt_lib_release_postfix': '<(ld_lib_postfix)',
+            'qt_libs': [
+              '<@(qt_libs)',
+              'qtmain',
+              'qwindows',
+            ],
+          }],
+          [ 'build_mac', {
+            'qt_lib_prefix': '<(ld_lib_prefix)',
+            'qt_lib_debug_postfix': '_debug<(ld_lib_postfix)',
+            'qt_lib_release_postfix': '<(ld_lib_postfix)',
+            'qt_libs': [
+              '<@(qt_libs)',
+              'qgenericbearer',
+              'qcocoa',
+            ],
+          }],
+        ],
       },
       'qt_version%': '<(qt_version)',
-      'qt_version_loc': '<!(python -c "print(\'<(qt_version)\'.replace(\'.\', \'_\')))',
-      'qtlibs_debug': [
-        '<(ld_lib_prefix)Qt5Cored<(ld_lib_postfix)',
-        '<(ld_lib_prefix)qtmaind<(ld_lib_postfix)',
-        '<(ld_lib_prefix)qtpcred<(ld_lib_postfix)',
-        '<(ld_lib_prefix)Qt5Guid<(ld_lib_postfix)',
-        '<(ld_lib_prefix)qtfreetyped<(ld_lib_postfix)',
-        '<(ld_lib_prefix)Qt5Widgetsd<(ld_lib_postfix)',
-        '<(ld_lib_prefix)qtharfbuzzngd<(ld_lib_postfix)',
-        '<(ld_lib_prefix)Qt5Networkd<(ld_lib_postfix)',
-        '<(ld_lib_prefix)Qt5PlatformSupportd<(ld_lib_postfix)',
-        '<(ld_lib_prefix)imageformats\qwebpd<(ld_lib_postfix)',
+      'qt_version_loc': '<!(python -c "print(\'<(qt_version)\'.replace(\'.\', \'_\'))")',
+      'qt_libs_debug': [
+        '<!@(python -c "for s in \'<@(qt_libs)\'.split(\' \'): print(\'<(qt_lib_prefix)\' + s + \'<(qt_lib_debug_postfix)\')")',
       ],
-      'qtlibs_release': [
-        '<(ld_lib_prefix)Qt5Core<(ld_lib_postfix)',
-        '<(ld_lib_prefix)qtmain<(ld_lib_postfix)',
-        '<(ld_lib_prefix)qtpcre<(ld_lib_postfix)',
-        '<(ld_lib_prefix)Qt5Gui<(ld_lib_postfix)',
-        '<(ld_lib_prefix)qtfreetype<(ld_lib_postfix)',
-        '<(ld_lib_prefix)Qt5Widgets<(ld_lib_postfix)',
-        '<(ld_lib_prefix)qtharfbuzzng<(ld_lib_postfix)',
-        '<(ld_lib_prefix)Qt5Network<(ld_lib_postfix)',
-        '<(ld_lib_prefix)Qt5PlatformSupport<(ld_lib_postfix)',
-        '<(ld_lib_prefix)imageformats\qwebp<(ld_lib_postfix)',
+      'qt_libs_release': [
+        '<!@(python -c "for s in \'<@(qt_libs)\'.split(\' \'): print(\'<(qt_lib_prefix)\' + s + \'<(qt_lib_release_postfix)\')")',
       ],
     },
+    'qt_libs_debug': [ '<@(qt_libs_debug)' ],
+    'qt_libs_release': [ '<@(qt_libs_release)' ],
     'qt_version%': '<(qt_version)',
     'conditions': [
       [ 'build_win', {
-        'qtlibs_debug': [
-          '<(ld_lib_prefix)platforms/qwindowsd<(ld_lib_postfix)',
-          '<@(qtlibs_debug)',
-        ],
-        'qtlibs_release': [
-          '<(ld_lib_prefix)platforms/qwindows<(ld_lib_postfix)',
-          '<@(qtlibs_release)',
-        ],
         'qt_loc': '../../../Libraries/qt<(qt_version_loc)/qtbase',
       }, {
-        'qtlibs_debug': [ '<@(qtlibs_debug)' ],
-        'qtlibs_release': [ '<@(qtlibs_release)' ],
-        'qt_loc': '/usr/local/qt<(qt_version_loc)/qtbase',
+        'qt_loc': '/usr/local/tdesktop/Qt-<(qt_version)',
       }],
     ],
   },
@@ -77,11 +87,19 @@
           'msvs_settings': {
             'VCLinkerTool': {
               'AdditionalDependencies': [
-                '<@(qtlibs_debug)'
+                '<@(qt_libs_debug)',
               ],
             },
           },
         }],
+        [ 'build_mac', {
+          'xcode_settings': {
+            'OTHER_LDFLAGS': [
+              '<@(qt_libs_debug)',
+              '/usr/local/lib/libz.a',
+            ],
+          },
+        }],
       ],
     },
     'Release': {
@@ -90,11 +108,19 @@
           'msvs_settings': {
             'VCLinkerTool': {
               'AdditionalDependencies': [
-                '<@(qtlibs_release)',
+                '<@(qt_libs_release)',
               ],
             },
           },
         }],
+        [ 'build_mac', {
+          'xcode_settings': {
+            'OTHER_LDFLAGS': [
+              '<@(qt_libs_release)',
+              '/usr/local/lib/libz.a',
+            ],
+          },
+        }],
       ],
     },
   },
@@ -107,6 +133,9 @@
   'library_dirs': [
     '<(qt_loc)/lib',
     '<(qt_loc)/plugins',
+    '<(qt_loc)/plugins/bearer',
+    '<(qt_loc)/plugins/platforms',
+    '<(qt_loc)/plugins/imageformats',
   ],
   'defines': [
     'QT_WIDGETS_LIB',
@@ -122,13 +151,13 @@
       '<(SHARED_INTERMEDIATE_DIR)/<(_target_name)/moc/moc_<(RULE_INPUT_ROOT).cpp',
     ],
     'action': [
-      '<(qt_loc)/bin/moc.exe',
+      '<(qt_loc)/bin/moc<(exe_ext)',
 
       # Silence "Note: No relevant classes found. No output generated."
       '--no-notes',
 
-      '<!@(python -c "for s in \'<@(_defines)\'.split(\' \'): print(\'-D\' + s))',
-      # '<!@(python -c "for s in \'<@(_include_dirs)\'.split(\' \'): print(\'-I\' + s))',
+      '<!@(python -c "for s in \'<@(_defines)\'.split(\' \'): print(\'-D\' + s)")',
+      # '<!@(python -c "for s in \'<@(_include_dirs)\'.split(\' \'): print(\'-I\' + s)")',
       '<(RULE_INPUT_PATH)',
       '-o', '<(SHARED_INTERMEDIATE_DIR)/<(_target_name)/moc/moc_<(RULE_INPUT_ROOT).cpp',
     ],
@@ -144,7 +173,7 @@
       '<(SHARED_INTERMEDIATE_DIR)/<(_target_name)/qrc/qrc_<(RULE_INPUT_ROOT).cpp',
     ],
     'action': [
-      '<(qt_loc)/bin/rcc.exe',
+      '<(qt_loc)/bin/rcc<(exe_ext)',
       '-name', '<(RULE_INPUT_ROOT)',
       '-no-compress',
       '<(RULE_INPUT_PATH)',
diff --git a/Telegram/gyp/refresh.sh b/Telegram/gyp/refresh.sh
new file mode 100755
index 000000000..078deb300
--- /dev/null
+++ b/Telegram/gyp/refresh.sh
@@ -0,0 +1,13 @@
+set -e
+FullExecPath=$PWD
+pushd `dirname $0` > /dev/null
+FullScriptPath=`pwd`
+popd > /dev/null
+
+cd $FullScriptPath
+gyp --depth=. --generator-output=../.. -Goutput_dir=out Telegram.gyp --format=xcode
+cd ../..
+
+cd $FullExecPath
+exit
+
diff --git a/Telegram/gyp/settings_mac.gypi b/Telegram/gyp/settings_mac.gypi
new file mode 100644
index 000000000..2ea8e5693
--- /dev/null
+++ b/Telegram/gyp/settings_mac.gypi
@@ -0,0 +1,64 @@
+# This file is part of Telegram Desktop,
+# the official desktop version of Telegram messaging app, see https://telegram.org
+#
+# Telegram Desktop 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 3 of the License, or
+# (at your option) any later version.
+#
+# It 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.
+#
+# In addition, as a special exception, the copyright holders give permission
+# to link the code of portions of this program with the OpenSSL library.
+#
+# Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
+# Copyright (c) 2014 John Preston, https://desktop.telegram.org
+
+{
+  'conditions': [
+    [ 'build_mac', {
+      'variables': {
+        'mac_frameworks': [
+          'Cocoa',
+          'CoreFoundation',
+          'CoreServices',
+          'CoreText',
+          'CoreGraphics',
+          'OpenGL',
+          'VideoToolbox',
+          'VideoDecodeAcceleration',
+          'AudioUnit',
+          'ApplicationServices',
+          'Foundation',
+          'AGL',
+          'Security',
+          'SystemConfiguration',
+          'Carbon',
+          'AudioToolbox',
+          'CoreAudio',
+          'QuartzCore',
+          'AVFoundation',
+          'CoreMedia',
+          'AppKit',
+          'CoreWLAN',
+          'IOKit',
+        ],
+      },
+      'xcode_settings': {
+        'OTHER_CPLUSPLUSFLAGS': [
+          '-std=c++14',
+          '-Wno-switch',
+          '-stdlib=libc++',
+        ],
+        'OTHER_LDFLAGS': [
+          '-stdlib=libc++',
+          '<!@(python -c "for s in \'<@(mac_frameworks)\'.split(\' \'): print(\'-framework \' + s)")',
+        ],
+        'MACOSX_DEPLOYMENT_TARGET': '<(mac_target)',
+      },
+    }],
+  ],
+}
diff --git a/Telegram/gyp/telegram_linux.gypi b/Telegram/gyp/telegram_linux.gypi
new file mode 100644
index 000000000..2275bcd0c
--- /dev/null
+++ b/Telegram/gyp/telegram_linux.gypi
@@ -0,0 +1,36 @@
+# This file is part of Telegram Desktop,
+# the official desktop version of Telegram messaging app, see https://telegram.org
+#
+# Telegram Desktop 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 3 of the License, or
+# (at your option) any later version.
+#
+# It 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.
+#
+# In addition, as a special exception, the copyright holders give permission
+# to link the code of portions of this program with the OpenSSL library.
+#
+# Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
+# Copyright (c) 2014 John Preston, https://desktop.telegram.org
+
+{
+  'conditions': [[ 'build_linux', {
+    'include_dirs': [
+      '/usr/local/include',
+      '<(libs_loc)/openssl-xcode/include'
+    ],
+    'library_dirs': [
+      '/usr/local/lib',
+      '<(libs_loc)/libexif-0.6.20/libexif/.libs',
+    ],
+    'libraries': [
+      '-lssl',
+      '-lcrypto',
+      '-llzma',
+    ],
+  }]],
+}
diff --git a/Telegram/gyp/telegram_mac.gypi b/Telegram/gyp/telegram_mac.gypi
new file mode 100644
index 000000000..2ebab5259
--- /dev/null
+++ b/Telegram/gyp/telegram_mac.gypi
@@ -0,0 +1,68 @@
+# This file is part of Telegram Desktop,
+# the official desktop version of Telegram messaging app, see https://telegram.org
+#
+# Telegram Desktop 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 3 of the License, or
+# (at your option) any later version.
+#
+# It 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.
+#
+# In addition, as a special exception, the copyright holders give permission
+# to link the code of portions of this program with the OpenSSL library.
+#
+# Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
+# Copyright (c) 2014 John Preston, https://desktop.telegram.org
+
+{
+  'conditions': [[ 'build_mac', {
+    'xcode_settings': {
+      'GCC_PREFIX_HEADER': '<(src_loc)/stdafx.h',
+      'GCC_PRECOMPILE_PREFIX_HEADER': 'YES',
+    },
+    'include_dirs': [
+      '/usr/local/include',
+      '<(libs_loc)/openssl-xcode/include'
+    ],
+    'library_dirs': [
+      '/usr/local/lib',
+      '<(libs_loc)/libexif-0.6.20/libexif/.libs',
+      '<(libs_loc)/openssl-xcode',
+    ],
+    'configurations': {
+      'Debug': {
+        'library_dirs': [
+          '<(libs_loc)/crashpad/crashpad/out/Debug',
+        ],
+      },
+      'Release': {
+        'library_dirs': [
+          '<(libs_loc)/crashpad/crashpad/out/Release',
+        ],
+      },
+    },
+    'libraries': [
+      '-lcups',
+      '-lbsm',
+      '-lm',
+      '-lssl',
+      '-lcrypto',
+      '-llzma',
+      '-lopenal',
+      '-lopus',
+      '-lexif',
+      '-lavcodec',
+      '-lavformat',
+      '-lswscale',
+      '-lswresample',
+      '-lavutil',
+      '-liconv',
+      '-lbase',
+      '-lcrashpad_client',
+      '-lcrashpad_util',
+    ],
+  }]],
+}
diff --git a/Telegram/gyp/telegram_qrc.gypi b/Telegram/gyp/telegram_qrc.gypi
new file mode 100644
index 000000000..8a4096f71
--- /dev/null
+++ b/Telegram/gyp/telegram_qrc.gypi
@@ -0,0 +1,50 @@
+# This file is part of Telegram Desktop,
+# the official desktop version of Telegram messaging app, see https://telegram.org
+#
+# Telegram Desktop 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 3 of the License, or
+# (at your option) any later version.
+#
+# It 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.
+#
+# In addition, as a special exception, the copyright holders give permission
+# to link the code of portions of this program with the OpenSSL library.
+#
+# Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
+# Copyright (c) 2014 John Preston, https://desktop.telegram.org
+
+{
+  'variables': {
+    'qrc_files': [
+      '<(res_loc)/telegram.qrc',
+      '<(res_loc)/telegram_emojis.qrc',
+    ],
+  },
+  'conditions': [
+    [ 'build_linux', {
+      'variables': {
+        'qrc_files': [
+          '<(res_loc)/telegram_linux.qrc',
+        ],
+      }
+    }],
+    [ 'build_mac', {
+      'variables': {
+        'qrc_files': [
+          '<(res_loc)/telegram_mac.qrc',
+        ],
+      },
+    }],
+    [ 'build_win', {
+      'variables': {
+        'qrc_files': [
+          '<(res_loc)/telegram_wnd.qrc',
+        ],
+      }
+    }],
+  ],
+}
diff --git a/Telegram/gyp/telegram_win.gypi b/Telegram/gyp/telegram_win.gypi
new file mode 100644
index 000000000..3122e624b
--- /dev/null
+++ b/Telegram/gyp/telegram_win.gypi
@@ -0,0 +1,83 @@
+# This file is part of Telegram Desktop,
+# the official desktop version of Telegram messaging app, see https://telegram.org
+#
+# Telegram Desktop 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 3 of the License, or
+# (at your option) any later version.
+#
+# It 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.
+#
+# In addition, as a special exception, the copyright holders give permission
+# to link the code of portions of this program with the OpenSSL library.
+#
+# Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
+# Copyright (c) 2014 John Preston, https://desktop.telegram.org
+
+{
+  'conditions': [[ 'build_win', {
+    'msvs_precompiled_source': '<(src_loc)/stdafx.cpp',
+    'msvs_precompiled_header': '<(src_loc)/stdafx.h',
+    'msbuild_toolset': 'v140_xp',     #Windows7.1SDK
+    'sources': [
+      '<(res_loc)/winrc/Telegram.rc',
+    ],
+    'libraries': [
+      'libeay32',
+      'ssleay32',
+      'Crypt32',
+      'zlibstat',
+      'LzmaLib',
+      'UxTheme',
+      'DbgHelp',
+      'lib_exif',
+      'OpenAL32',
+      'common',
+      'libavformat/libavformat.a',
+      'libavcodec/libavcodec.a',
+      'libavutil/libavutil.a',
+      'libswresample/libswresample.a',
+      'libswscale/libswscale.a',
+      'opus',
+      'celt',
+      'silk_common',
+      'silk_float',
+      'lib/common',
+      'lib/exception_handler',
+      'lib/crash_generation_client',
+    ],
+    'configurations': {
+      'Debug': {
+        'include_dirs': [
+          '<(libs_loc)/openssl_debug/Debug/include',
+        ],
+        'library_dirs': [
+          '<(libs_loc)/openssl_debug/Debug/lib',
+          '<(libs_loc)/lzma/C/Util/LzmaLib/Debug',
+          '<(libs_loc)/libexif-0.6.20/win32/Debug',
+          '<(libs_loc)/opus/win32/VS2010/Win32/Debug',
+          '<(libs_loc)/openal-soft/build/Debug',
+          '<(libs_loc)/zlib-1.2.8/contrib/vstudio/vc11/x86/ZlibStatDebug',
+          '<(libs_loc)/breakpad/src/client/windows/Debug',
+        ],
+      },
+      'Release': {
+        'include_dirs': [
+          '<(libs_loc)/openssl/Release/include',
+        ],
+        'library_dirs': [
+          '<(libs_loc)/openssl/Release/lib',
+          '<(libs_loc)/lzma/C/Util/LzmaLib/Release',
+          '<(libs_loc)/libexif-0.6.20/win32/Release',
+          '<(libs_loc)/opus/win32/VS2010/Win32/Release',
+          '<(libs_loc)/openal-soft/build/Release',
+          '<(libs_loc)/zlib-1.2.8/contrib/vstudio/vc11/x86/ZlibStatRelease',
+          '<(libs_loc)/breakpad/src/client/windows/Release',
+        ],
+      },
+    },
+  }]],
+}
diff --git a/Telegram/gyp/utils.gyp b/Telegram/gyp/utils.gyp
index 1ff4110b7..3c13fac83 100644
--- a/Telegram/gyp/utils.gyp
+++ b/Telegram/gyp/utils.gyp
@@ -65,17 +65,28 @@
     'variables': {
       'libs_loc': '../../../Libraries',
       'src_loc': '../SourceFiles',
+      'mac_target': '10.10',
     },
     'includes': [
       'common_executable.gypi',
       'qt.gypi',
     ],
-    'libraries': [
-      'libeay32',
-      'ssleay32',
-      'Crypt32',
-      'zlibstat',
-      'LzmaLib',
+    'conditions': [
+      [ 'build_win', {
+        'libraries': [
+          'libeay32',
+          'ssleay32',
+          'Crypt32',
+          'zlibstat',
+          'LzmaLib',
+        ],
+      }, {
+        'libraries': [
+          '-lssl',
+          '-lcrypto',
+          '-llzma',
+        ],
+      }],
     ],
 
     'include_dirs': [
@@ -89,23 +100,47 @@
     ],
     'configurations': {
       'Debug': {
-        'include_dirs': [
-          '<(libs_loc)/openssl_debug/Debug/include',
-        ],
-        'library_dirs': [
-          '<(libs_loc)/lzma/C/Util/LzmaLib/Debug',
-          '<(libs_loc)/zlib-1.2.8/contrib/vstudio/vc11/x86/ZlibStatDebug',
-          '<(libs_loc)/openssl_debug/Debug/lib',
+        'conditions': [
+          [ 'build_win', {
+            'include_dirs': [
+              '<(libs_loc)/openssl_debug/Debug/include',
+            ],
+            'library_dirs': [
+              '<(libs_loc)/openssl_debug/Debug/lib',
+              '<(libs_loc)/lzma/C/Util/LzmaLib/Debug',
+              '<(libs_loc)/zlib-1.2.8/contrib/vstudio/vc11/x86/ZlibStatDebug',
+            ],
+          }, {
+            'include_dirs': [
+              '/usr/local/include',
+              '<(libs_loc)/openssl-xcode/include'
+            ],
+            'library_dirs': [
+              '/usr/local/lib',
+            ],
+          }]
         ],
       },
       'Release': {
-        'include_dirs': [
-          '<(libs_loc)/openssl/Release/include',
-        ],
-        'library_dirs': [
-          '<(libs_loc)/lzma/C/Util/LzmaLib/Release',
-          '<(libs_loc)/zlib-1.2.8/contrib/vstudio/vc11/x86/ZlibStatRelease',
-          '<(libs_loc)/openssl/Release/lib',
+        'conditions': [
+          [ 'build_win', {
+            'include_dirs': [
+              '<(libs_loc)/openssl/Release/include',
+            ],
+            'library_dirs': [
+              '<(libs_loc)/openssl/Release/lib',
+              '<(libs_loc)/lzma/C/Util/LzmaLib/Release',
+              '<(libs_loc)/zlib-1.2.8/contrib/vstudio/vc11/x86/ZlibStatRelease',
+            ],
+          }, {
+            'include_dirs': [
+              '/usr/local/include',
+              '<(libs_loc)/openssl-xcode/include'
+            ],
+            'library_dirs': [
+              '/usr/local/lib',
+            ],
+          }]
         ],
       },
     },