--- Telegram/gyp/qt_rcc.gypi.orig	2018-01-03 10:46:01 UTC
+++ Telegram/gyp/qt_rcc.gypi
@@ -15,7 +15,7 @@
       '<(SHARED_INTERMEDIATE_DIR)/<(_target_name)/qrc/qrc_<(RULE_INPUT_ROOT).cpp',
     ],
     'action': [
-      '<(qt_loc)/bin/rcc<(exe_ext)',
+      '%%QT_BINDIR%%/rcc',
       '-name', '<(RULE_INPUT_ROOT)',
       '-no-compress',
       '<(RULE_INPUT_PATH)',
--- Telegram/gyp/qt_moc.gypi.orig	2018-01-03 10:46:01 UTC
+++ Telegram/gyp/qt_moc.gypi
@@ -12,12 +12,12 @@
       '<(SHARED_INTERMEDIATE_DIR)/<(_target_name)/moc/moc_<(RULE_INPUT_ROOT).cpp',
     ],
     'action': [
-      '<(qt_loc)/bin/moc<(exe_ext)',
+      '%%QT_BINDIR%%/moc',
 
       # Silence "Note: No relevant classes found. No output generated."
       '--no-notes',
 
-      '<!@(python -c "for s in \'<@(_defines)\'.split(\' \'): print(\'-D\' + s)")',
+      '<!@(%%PYTHON_CMD%% -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',
--- Telegram/gyp/qt.gypi.orig	2018-01-03 10:46:01 UTC
+++ Telegram/gyp/qt.gypi
@@ -14,25 +14,21 @@
               [ 'build_macold', {
                 'qt_version%': '5.3.2',
               }, {
-                'qt_version%': '5.6.2',
+                'qt_version%': '%%QT_VERSION%%',
               }]
             ],
           },
           'qt_libs': [
-            'qwebp',
-            'Qt5PrintSupport',
-            'Qt5PlatformSupport',
             'Qt5Network',
             'Qt5Widgets',
             'Qt5Gui',
-            'qtharfbuzzng',
           ],
           'qt_version%': '<(qt_version)',
           'conditions': [
             [ 'build_macold', {
               'linux_path_qt%': '/usr/local/macold/Qt-<(qt_version)',
             }, {
-              'linux_path_qt%': '/usr/local/tdesktop/Qt-<(qt_version)',
+              'linux_path_qt%': '%%LOCALBASE%%/lib/qt',
             }]
           ]
         },
@@ -72,44 +68,25 @@
             ],
           }],
           [ 'build_linux', {
-            'qt_lib_prefix': 'lib',
-            'qt_lib_debug_postfix': '.a',
-            'qt_lib_release_postfix': '.a',
+            'qt_lib_prefix': '',
+            'qt_lib_debug_postfix': '',
+            'qt_lib_release_postfix': '',
             'qt_libs': [
-              'qxcb',
-              'Qt5XcbQpa',
-              'qconnmanbearer',
-              'qgenericbearer',
-              'qnmbearer',
               '<@(qt_libs)',
               'Qt5DBus',
               'Qt5Core',
-              'qtpcre',
-              'Xi',
-              'Xext',
-              'Xfixes',
-              'SM',
-              'ICE',
-              'fontconfig',
-              'expat',
-              'freetype',
-              'z',
-              'xcb-shm',
-              'xcb-xfixes',
-              'xcb-render',
-              'xcb-static',
             ],
           }],
         ],
       },
       'qt_version%': '<(qt_version)',
       'qt_loc_unix': '<(qt_loc_unix)',
-      'qt_version_loc': '<!(python -c "print(\'<(qt_version)\'.replace(\'.\', \'_\'))")',
+      'qt_version_loc': '<!(%%PYTHON_CMD%% -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)\')")',
+        '<!@(%%PYTHON_CMD%% -c "for s in \'<@(qt_libs)\'.split(\' \'): print(\'<(qt_lib_prefix)\' + s + \'<(qt_lib_debug_postfix)\')")',
       ],
       'qt_libs_release': [
-        '<!@(python -c "for s in \'<@(qt_libs)\'.split(\' \'): print(\'<(qt_lib_prefix)\' + s + \'<(qt_lib_release_postfix)\')")',
+        '<!@(%%PYTHON_CMD%% -c "for s in \'<@(qt_libs)\'.split(\' \'): print(\'<(qt_lib_prefix)\' + s + \'<(qt_lib_release_postfix)\')")',
       ],
     },
     'qt_libs_debug': [ '<@(qt_libs_debug)' ],
@@ -127,11 +104,6 @@
     # '<!@(python <(DEPTH)/list_sources.py [sources] <(qt_moc_list_sources_arg))'
     # where [sources] contains all your source files
     'qt_moc_list_sources_arg': '--moc-prefix SHARED_INTERMEDIATE_DIR/<(_target_name)/moc/moc_',
-
-    'linux_path_xkbcommon%': '/usr/local',
-    'linux_lib_ssl%': '/usr/local/ssl/lib/libssl.a',
-    'linux_lib_crypto%': '/usr/local/ssl/lib/libcrypto.a',
-    'linux_lib_icu%': 'libicutu.a libicui18n.a libicuuc.a libicudata.a',
   },
 
   'configurations': {
@@ -180,18 +152,18 @@
   },
 
   'include_dirs': [
-    '<(qt_loc)/include',
-    '<(qt_loc)/include/QtCore',
-    '<(qt_loc)/include/QtGui',
-    '<(qt_loc)/include/QtDBus',
-    '<(qt_loc)/include/QtCore/<(qt_version)',
-    '<(qt_loc)/include/QtGui/<(qt_version)',
-    '<(qt_loc)/include/QtCore/<(qt_version)/QtCore',
-    '<(qt_loc)/include/QtGui/<(qt_version)/QtGui',
+    '%%QT_INCDIR%%',
+    '%%QT_INCDIR%%/QtCore',
+    '%%QT_INCDIR%%/QtGui',
+    '%%QT_INCDIR%%/QtDBus',
+    '%%QT_INCDIR%%/QtCore/<(qt_version)',
+    '%%QT_INCDIR%%/QtGui/<(qt_version)',
+    '%%QT_INCDIR%%/QtCore/<(qt_version)/QtCore',
+    '%%QT_INCDIR%%/QtGui/<(qt_version)/QtGui',
   ],
   'library_dirs': [
-    '<(qt_loc)/lib',
-    '<(qt_loc)/plugins',
+    '%%LOCALBASE%%/lib',
+    '%%QT_LIBDIR%%/',
     '<(qt_loc)/plugins/bearer',
     '<(qt_loc)/plugins/platforms',
     '<(qt_loc)/plugins/imageformats',
@@ -204,33 +176,20 @@
   ],
   'conditions': [
     [ 'build_linux', {
-      'dependencies': [
-        '<(DEPTH)/linux_glibc_wraps.gyp:linux_glibc_wraps',
-      ],
       'library_dirs': [
         '<(qt_loc)/plugins/platforminputcontexts',
       ],
       'libraries': [
-        '<(PRODUCT_DIR)/obj.target/liblinux_glibc_wraps.a',
-        '<(linux_path_xkbcommon)/lib/libxkbcommon.a',
         '<@(qt_libs_release)',
-        '<(linux_lib_ssl)',
-        '<(linux_lib_crypto)',
-        '<!@(python -c "for s in \'<(linux_lib_icu)\'.split(\' \'): print(s)")',
-        '-lxcb',
+        '-lcrypto',
         '-lX11',
-        '-lX11-xcb',
-        '-ldbus-1',
-        '-ldl',
-        '-lgthread-2.0',
         '-lglib-2.0',
         '-lpthread',
       ],
       'include_dirs': [
-        '<(qt_loc)/mkspecs/linux-g++',
+        '%%QMAKESPEC%%',
       ],
       'ldflags': [
-        '-static-libstdc++',
         '-pthread',
         '-rdynamic',
       ],
--- Telegram/gyp/telegram_linux.gypi.orig	2018-01-03 10:46:01 UTC
+++ Telegram/gyp/telegram_linux.gypi
@@ -7,7 +7,7 @@
 {
   'conditions': [[ 'build_linux', {
     'variables': {
-      'not_need_gtk%': '<!(python -c "print(\'TDESKTOP_DISABLE_GTK_INTEGRATION\' in \'<(build_defines)\')")',
+      'not_need_gtk%': '<!(%%PYTHON_CMD%% -c "print(\'TDESKTOP_DISABLE_GTK_INTEGRATION\' in \'<(build_defines)\')")',
       'pkgconfig_libs': [
 # In order to work libxkbcommon must be linked statically,
 # PKGCONFIG links it like "-L/usr/local/lib -lxkbcommon"
@@ -20,10 +20,11 @@
       'linux_path_va%': '/usr/local',
       'linux_path_vdpau%': '/usr/local',
       'linux_path_breakpad%': '/usr/local',
-      'linux_path_opus_include%': '<(libs_loc)/opus/include',
+      'linux_path_opus_include%': '%%LOCALBASE%%/include/opus',
       'linux_path_range%': '/usr/local',
     },
     'include_dirs': [
+      '/usr/include/openssl-1.0',
       '/usr/local/include',
       '<(linux_path_ffmpeg)/include',
       '<(linux_path_openal)/include',
@@ -32,6 +33,7 @@
       '<(linux_path_range)/include',
     ],
     'library_dirs': [
+      '/usr/lib/openssl-1.0',
       '/usr/local/lib',
       '<(linux_path_ffmpeg)/lib',
       '<(linux_path_openal)/lib',
@@ -40,25 +42,15 @@
       '<(linux_path_breakpad)/lib',
     ],
     'libraries': [
-      'breakpad_client',
-      'composeplatforminputcontextplugin',
-      'ibusplatforminputcontextplugin',
-      'fcitxplatforminputcontextplugin',
-      'himeplatforminputcontextplugin',
-      'liblzma.a',
-      'libopenal.a',
-      'libavformat.a',
-      'libavcodec.a',
-      'libswresample.a',
-      'libswscale.a',
-      'libavutil.a',
-      'libopus.a',
-      'libva-x11.a',
-      'libva-drm.a',
-      'libva.a',
-      'libvdpau.a',
-      'libdrm.a',
-      'libz.a',
+      'openal',
+      'avformat',
+      'avcodec',
+      'swresample',
+      'swscale',
+      'avutil',
+      'minizip',
+      'opus',
+      'z',
 #      '<!(pkg-config 2> /dev/null --libs <@(pkgconfig_libs))',
     ],
     'cflags_cc': [
@@ -67,7 +59,6 @@
     'ldflags': [
       '-Wl,-wrap,aligned_alloc',
       '-Wl,-wrap,secure_getenv',
-      '-Wl,-wrap,clock_gettime',
       '-Wl,--no-as-needed,-lrt',
     ],
     'configurations': {
@@ -86,7 +77,7 @@
       },
     },
     'conditions': [
-      [ '"<!(uname -p)" == "x86_64"', {
+      [ '"<!(uname -m)" == "x86_64"', {
         # 32 bit version can't be linked with debug info or LTO,
         # virtual memory exhausted :(
         'cflags_c': [ '-g' ],
@@ -94,9 +85,9 @@
         'ldflags': [ '-g' ],
         'configurations': {
           'Release': {
-            'cflags_c': [ '-flto' ],
-            'cflags_cc': [ '-flto' ],
-            'ldflags': [ '-flto' ],
+            'cflags_c': [ %%CFLAGS%% ],
+            'cflags_cc': [ %%CXXFLAGS%% ],
+            'ldflags': [ %%LDFLAGS%% ],
           },
         },
       }, {
@@ -105,10 +96,7 @@
         ],
       }], ['not_need_gtk!="True"', {
         'cflags_cc': [
-          '<!(pkg-config 2> /dev/null --cflags appindicator-0.1)',
-          '<!(pkg-config 2> /dev/null --cflags gtk+-2.0)',
-          '<!(pkg-config 2> /dev/null --cflags glib-2.0)',
-          '<!(pkg-config 2> /dev/null --cflags dee-1.0)',
+          '<!(pkg-config 2> /dev/null --cflags gtk+-3.0)',
         ],
       }]
     ],
--- Telegram/gyp/Telegram.gyp.orig	2018-01-03 10:46:01 UTC
+++ Telegram/gyp/Telegram.gyp
@@ -49,7 +49,7 @@
         'pt-BR',
       ],
       'build_defines%': '',
-      'list_sources_command': 'python <(DEPTH)/list_sources.py --input <(DEPTH)/telegram_sources.txt --replace src_loc=<(src_loc)',
+      'list_sources_command': '%%PYTHON_CMD%% <(DEPTH)/list_sources.py --input <(DEPTH)/telegram_sources.txt --replace src_loc=<(src_loc)',
     },
     'includes': [
       'common_executable.gypi',
@@ -69,30 +69,20 @@
       'codegen.gyp:codegen_numbers',
       'codegen.gyp:codegen_style',
       'tests/tests.gyp:tests',
-      'utils.gyp:Updater',
       '../ThirdParty/libtgvoip/libtgvoip.gyp:libtgvoip',
       'crl.gyp:crl',
     ],
 
     'defines': [
-      'AL_LIBTYPE_STATIC',
       'AL_ALEXT_PROTOTYPES',
       'TGVOIP_USE_CXX11_LIB',
-      '<!@(python -c "for s in \'<(build_defines)\'.split(\',\'): print(s)")',
+      '<!@(%%PYTHON_CMD%% -c "for s in \'<(build_defines)\'.split(\',\'): print(s)")',
     ],
 
     'include_dirs': [
       '<(src_loc)',
       '<(SHARED_INTERMEDIATE_DIR)',
-      '<(libs_loc)/breakpad/src',
-      '<(libs_loc)/lzma/C',
-      '<(libs_loc)/zlib',
-      '<(libs_loc)/ffmpeg',
-      '<(libs_loc)/openal-soft/include',
-      '<(libs_loc)/opus/include',
-      '<(libs_loc)/range-v3/include',
-      '<(minizip_loc)',
-      '<(sp_media_key_tap_loc)',
+      '%%LOCALBASE%%/include/minizip',
       '<(emoji_suggestions_loc)',
       '<(submodules_loc)/GSL/include',
       '<(submodules_loc)/variant/include',
@@ -105,7 +95,7 @@
       'telegram_sources.txt',
     ],
     'sources!': [
-      '<!@(<(list_sources_command) <(qt_moc_list_sources_arg) --exclude_for <(build_os))',
+      '<!@(<(list_sources_command) <(qt_moc_list_sources_arg) --exclude_for linux)',
     ],
     'conditions': [
       [ '"<(official_build_target)" != ""', {
--- Telegram/ThirdParty/libtgvoip/libtgvoip.gyp.orig	2018-02-06 06:51:56 UTC
+++ Telegram/ThirdParty/libtgvoip/libtgvoip.gyp
@@ -13,11 +13,12 @@
         'variables': {
           'tgvoip_src_loc': '.',
           'official_build_target%': '',
-          'linux_path_opus_include%': '<(DEPTH)/../../../Libraries/opus/include',
+          'linux_path_opus_include%': '%%LOCALBASE%%/include/opus',
         },
         'include_dirs': [
           '<(tgvoip_src_loc)/webrtc_dsp',
           '<(linux_path_opus_include)',
+          '%%LOCALBASE%%/include/',
         ],
         'direct_dependent_settings': {
           'include_dirs': [
@@ -259,7 +260,7 @@
             },
           ],
           [
-            '"<(OS)" != "linux"', {
+            '"<(OS)" != "freebsd"', {
               'sources/': [['exclude', '<(tgvoip_src_loc)/os/linux/']],
             },
           ],
@@ -378,12 +379,13 @@
             },
           ],
           [
-            '"<(OS)" == "linux"', {
+            '"<(OS)" == "freebsd"', {
               'defines': [
                 'WEBRTC_POSIX',
               ],
               'cflags_cc': [
                 '-msse2',
+                '-std=c++11',
               ],
               'direct_dependent_settings': {
                 'libraries': [
--- Telegram/gyp/codegen_rules.gypi.orig	2018-02-06 06:53:18 UTC
+++ Telegram/gyp/codegen_rules.gypi
@@ -15,7 +15,7 @@
       '<(SHARED_INTERMEDIATE_DIR)/update_dependent_styles.timestamp',
     ],
     'action': [
-      'python', '<(DEPTH)/update_dependent.py', '--styles',
+      '%%PYTHON_CMD%%', '<(DEPTH)/update_dependent.py', '--styles',
       '-I', '<(res_loc)', '-I', '<(src_loc)',
       '-o', '<(SHARED_INTERMEDIATE_DIR)/update_dependent_styles.timestamp',
       '<@(style_files)',
@@ -26,13 +26,13 @@
     'inputs': [
       '<(DEPTH)/update_dependent.py',
       '<@(qrc_files)',
-      '<!@(python <(DEPTH)/update_dependent.py --qrc_list <@(qrc_files))',
+      '<!@(%%PYTHON_CMD%% <(DEPTH)/update_dependent.py --qrc_list <@(qrc_files))',
     ],
     'outputs': [
       '<(SHARED_INTERMEDIATE_DIR)/update_dependent_qrc.timestamp',
     ],
     'action': [
-      'python', '<(DEPTH)/update_dependent.py', '--qrc',
+      '%%PYTHON_CMD%%', '<(DEPTH)/update_dependent.py', '--qrc',
       '-o', '<(SHARED_INTERMEDIATE_DIR)/update_dependent_qrc.timestamp',
       '<@(qrc_files)',
     ],
@@ -109,7 +109,7 @@
       '<(SHARED_INTERMEDIATE_DIR)/scheme.h',
     ],
     'action': [
-      'python', '<(src_loc)/codegen/scheme/codegen_scheme.py',
+      '%%PYTHON_CMD%%', '<(src_loc)/codegen/scheme/codegen_scheme.py',
       '-o', '<(SHARED_INTERMEDIATE_DIR)', '<(res_loc)/scheme.tl',
     ],
     'message': 'codegen_scheme-ing scheme.tl..',
--- Telegram/gyp/tests/tests.gyp.orig	2018-02-06 06:53:50 UTC
+++ Telegram/gyp/tests/tests.gyp
@@ -13,7 +13,7 @@
     'src_loc': '../../SourceFiles',
     'submodules_loc': '../../ThirdParty',
     'mac_target': '10.10',
-    'list_tests_command': 'python <(DEPTH)/tests/list_tests.py --input <(DEPTH)/tests/tests_list.txt',
+    'list_tests_command': '%%PYTHON_CMD%% <(DEPTH)/tests/list_tests.py --input <(DEPTH)/tests/tests_list.txt',
   },
   'targets': [{
     'target_name': 'tests',
