| LEFT | RIGHT | 
|    1 project('adblockpluscore', license: ['GPL3']) |    1 project('adblockpluscore', license: ['GPL3'], meson_version: '>0.40.0') | 
|    2  |    2  | 
|    3 emcc = find_program('emcc') |    3 # locate emscripten-config | 
|    4 nodejs = find_program('node') |    4 python = import('python3').find_python() | 
 |    5 emscripten_config = get_option('emscripten-config') | 
 |    6 command = run_command(python, '-c', 'import os.path, sys;print(os.path.expanduse
     r(sys.argv[1]))', emscripten_config) | 
 |    7 if command.returncode() != 0 | 
 |    8   error(command.stderr().strip()) | 
 |    9 endif | 
 |   10 emscripten_config = command.stdout().strip() | 
 |   11 message('Emscripten config file: ' + emscripten_config) | 
|    5  |   12  | 
|    6 JS_LIBRARY = files('compiled/library.js') |   13 # locate emcc | 
 |   14 command = run_command(python, '-c', 'import sys;exec(open(sys.argv[1]).read());p
     rint(EMSCRIPTEN_ROOT)', emscripten_config) | 
 |   15 if command.returncode() != 0 | 
 |   16   error(command.stderr().strip()) | 
 |   17 endif | 
 |   18 emcc = join_paths(command.stdout().strip(), 'emcc') | 
 |   19 emcc = find_program(emcc) | 
 |   20  | 
 |   21 # locate node | 
 |   22 command = run_command(python, '-c', 'import sys;exec(open(sys.argv[1]).read());p
     rint(NODE_JS)', emscripten_config) | 
 |   23 if command.returncode() != 0 | 
 |   24   error(command.stderr().strip()) | 
 |   25 endif | 
 |   26 nodejs = find_program(command.stdout().strip(), 'node', 'nodejs') | 
 |   27  | 
 |   28 JS_LIBRARY = files(join_paths('compiled', 'library.js')) | 
 |   29 BINDINGS_JS_LIBRARY = files(join_paths('compiled', 'bindings', 'library.js')) | 
|    7 BINDINGS_GENERATOR = 'bindings.cpp.js' |   30 BINDINGS_GENERATOR = 'bindings.cpp.js' | 
|    8 BINDINGS_OUTPUT = 'bindings.js' |   31 BINDINGS_OUTPUT = 'bindings.js' | 
|    9 COMPILER_OUTPUT = 'compiled.js' |   32 COMPILER_OUTPUT = 'compiled.js' | 
|   10 # params for emcc compilation |   33 # params for emcc compilation | 
|   11 ADDITIONAL_PARAMS = ['-O3', '-m32', '-std=c++1z', '--memory-init-file', '0', |   34 ADDITIONAL_PARAMS = [ '-O3', '-m32', '-std=c++1z', '--memory-init-file', '0', | 
|   12                      '--emit-symbol-map', '-Wall', '-Werror', '-fno-exceptions', |   35                       '--emit-symbol-map', '-Wall', '-Werror', | 
|   13                      '-fno-rtti', '--js-library', JS_LIBRARY] |   36                       '-fno-rtti' ] | 
 |   37 # additional params just for core | 
 |   38 CORE_PARAMS = [ '-fno-exceptions' ] | 
 |   39  | 
|   14 DEFINES = [] |   40 DEFINES = [] | 
|   15 GENERATION_PARAMS = [ |   41 GENERATION_PARAMS = [ | 
|   16     ['SHELL_FILE', '"' + meson.source_root() + '/compiled/shell.js"'], |   42   ['SHELL_FILE', '"' + | 
|   17     ['ASM_JS', '2'],  # "almost asm" |   43    join_paths(meson.source_root(), 'compiled', 'shell.js') + | 
|   18     ['TOTAL_MEMORY', 16*1024*1024], |   44    '"'], | 
|   19     ['TOTAL_STACK', 1*1024*1024], |   45   ['ASM_JS', '2'],  # "almost asm" | 
|   20     ['ALLOW_MEMORY_GROWTH', 1], |   46   ['TOTAL_MEMORY', 16*1024*1024], | 
|   21     ['NO_EXIT_RUNTIME', 1], |   47   ['TOTAL_STACK', 1*1024*1024], | 
|   22     ['NO_DYNAMIC_EXECUTION', 1], |   48   ['ALLOW_MEMORY_GROWTH', 1], | 
|   23     ['NO_FILESYSTEM', 1], |   49   ['NO_EXIT_RUNTIME', 1], | 
|   24     ['INVOKE_RUN', 0], |   50   ['NO_DYNAMIC_EXECUTION', 1], | 
|   25     ['TEXTDECODER', 0], |   51   ['NO_FILESYSTEM', 1], | 
|   26     ['EXPORTED_RUNTIME_METHODS', '["cwrap", "ccall", "stringToAscii"]'] |   52   ['INVOKE_RUN', 0], | 
 |   53   ['TEXTDECODER', 0], | 
 |   54   ['EXPORTED_RUNTIME_METHODS', '["cwrap", "ccall", "stringToAscii"]'] | 
|   27 ] |   55 ] | 
|   28  |   56  | 
|   29 bindings_sources = files( |  | 
|   30     'compiled/bindings/generator.cpp', |  | 
|   31     'compiled/bindings/main.cpp', |  | 
|   32 ) |  | 
|   33 sources = files( |  | 
|   34     'compiled/bindings/runtime_utils.cpp', |  | 
|   35     'compiled/filter/ActiveFilter.cpp', |  | 
|   36     'compiled/filter/BlockingFilter.cpp', |  | 
|   37     'compiled/filter/CommentFilter.cpp', |  | 
|   38     'compiled/filter/ElemHideBase.cpp', |  | 
|   39     'compiled/filter/ElemHideEmulationFilter.cpp', |  | 
|   40     'compiled/filter/ElemHideException.cpp', |  | 
|   41     'compiled/filter/ElemHideFilter.cpp', |  | 
|   42     'compiled/filter/Filter.cpp', |  | 
|   43     'compiled/filter/InvalidFilter.cpp', |  | 
|   44     'compiled/filter/RegExpFilter.cpp', |  | 
|   45     'compiled/filter/WhitelistFilter.cpp', |  | 
|   46     'compiled/subscription/DownloadableSubscription.cpp', |  | 
|   47     'compiled/subscription/Subscription.cpp', |  | 
|   48     'compiled/subscription/UserDefinedSubscription.cpp', |  | 
|   49     'compiled/traceInit.cpp' |  | 
|   50 ) |  | 
|   51  |   57  | 
|   52 bindings_generator = custom_target('bindings-generator', |   58 shared_sources = [ | 
|   53                    input: bindings_sources + sources, |   59   'compiled/bindings/runtime_utils.cpp', | 
|   54                    output: BINDINGS_GENERATOR, |   60   'compiled/filter/ActiveFilter.cpp', | 
|   55                    command: [emcc, '-o', '@OUTPUT@', |   61   'compiled/filter/BlockingFilter.cpp', | 
|   56                              '-std=c++1z', '--js-library', JS_LIBRARY, |   62   'compiled/filter/CommentFilter.cpp', | 
|   57                              '--js-library', |   63   'compiled/filter/ElemHideBase.cpp', | 
|   58                              files('compiled/bindings/library.js'), |   64   'compiled/filter/ElemHideEmulationFilter.cpp', | 
|   59                              '@INPUT@']) |   65   'compiled/filter/ElemHideException.cpp', | 
|   60 bindings_output = custom_target('bindings-output', |   66   'compiled/filter/ElemHideFilter.cpp', | 
|   61                 input: bindings_generator, |   67   'compiled/filter/Filter.cpp', | 
|   62                 output: BINDINGS_OUTPUT, |   68   'compiled/filter/InvalidFilter.cpp', | 
|   63                 capture: true, |   69   'compiled/filter/RegExpFilter.cpp', | 
|   64                 command: [nodejs, '@INPUT@']) |   70   'compiled/filter/WhitelistFilter.cpp', | 
|   65  |   71   'compiled/storage/FilterStorage.cpp', | 
 |   72   'compiled/subscription/DownloadableSubscription.cpp', | 
 |   73   'compiled/subscription/Subscription.cpp', | 
 |   74   'compiled/subscription/UserDefinedSubscription.cpp', | 
 |   75 ] | 
 |   76 # sources specific to core | 
 |   77 core_sources = [ | 
 |   78   'compiled/traceInit.cpp', | 
 |   79 ] | 
 |   80 # sources for the bindings generator | 
 |   81 bindings_sources = [ | 
 |   82   'compiled/bindings/generator.cpp', | 
 |   83   'compiled/bindings/main.cpp', | 
 |   84 ] | 
|   66  |   85  | 
|   67 defines_args = [] |   86 defines_args = [] | 
|   68 foreach define : DEFINES |   87 foreach define : DEFINES | 
|   69         defines_args += '-D' + define |   88   defines_args += '-D' + define | 
|   70 endforeach |   89 endforeach | 
|   71  |   90  | 
|   72 generation_args = [] |   91 generation_args = [] | 
|   73 foreach param : GENERATION_PARAMS |   92 foreach param : GENERATION_PARAMS | 
|   74         generation_args += '-s' |   93   generation_args += '-s' | 
|   75         generation_args += param[0] + '=' + '@0@'.format(param[1]) |   94   generation_args += param[0] + '=' + '@0@'.format(param[1]) | 
|   76 endforeach |   95 endforeach | 
|   77  |   96  | 
|   78 optional_args = [] |   97 optional_args = [] | 
|   79 debug = get_option('buildtype') |   98 buildtype = get_option('buildtype') | 
|   80 if debug.startswith('debug') |   99 if buildtype.startswith('debug') | 
 |  100   optional_args += '-DDEBUG' | 
|   81   optional_args += '-g3' |  101   optional_args += '-g3' | 
|   82 endif |  102 endif | 
|   83 tracing = get_option('tracing') |  103 tracing = get_option('tracing') | 
|   84 if tracing |  104 if tracing | 
|   85   optional_args += '--tracing' |  105   optional_args += '--tracing' | 
|   86 endif |  106 endif | 
|   87  |  107  | 
|   88 compiler_output = custom_target('compiled.js', |  108 compiler_args = defines_args + generation_args + ADDITIONAL_PARAMS | 
|   89                 build_by_default: true, |  109  | 
|   90                 input: sources, |  110 # build objects. | 
|   91                 output: COMPILER_OUTPUT, |  111 core_objects = [] | 
|   92                 command: [emcc, '-o', '@OUTPUT@', '-std=c++1z', |  112 bindings_objects = [] | 
|   93                 '--post-js', bindings_output, '@INPUT@'] + |  113 shared_objects = [] | 
|   94                 defines_args + generation_args + |  114 foreach group : ['core', 'bindings', 'shared'] | 
|   95                 ADDITIONAL_PARAMS + optional_args) |  115   objects = [] | 
 |  116   foreach source_file : get_variable(group + '_sources') | 
 |  117     output_file = source_file.underscorify() + '.o' | 
 |  118     command = [ emcc, '-MD', '-MF', '@DEPFILE@', '-c', '-o', '@OUTPUT@', | 
 |  119                 '@INPUT@' ] + compiler_args | 
 |  120     if group != 'bindings' | 
 |  121       command += CORE_PARAMS + optional_args | 
 |  122     endif | 
 |  123     objects += custom_target(output_file, | 
 |  124                              input: files(source_file), | 
 |  125                              output: output_file, | 
 |  126                              depfile: output_file + '.deps', | 
 |  127                              command: command) | 
 |  128   endforeach | 
 |  129   # Ideally, we would call set_variable() here but that doesn't work with arrays | 
 |  130   # (see https://github.com/mesonbuild/meson/issues/1481). So we have to do this | 
 |  131   # shifting dance instead. | 
 |  132   core_objects = bindings_objects | 
 |  133   bindings_objects = shared_objects | 
 |  134   shared_objects = objects | 
 |  135 endforeach | 
 |  136  | 
 |  137 # link the binding generator | 
 |  138 bindings_generator = custom_target(BINDINGS_GENERATOR, | 
 |  139                                    input: bindings_objects + shared_objects, | 
 |  140                                    output: BINDINGS_GENERATOR, | 
 |  141                                    depend_files: [ JS_LIBRARY, BINDINGS_JS_LIBRA
     RY ], | 
 |  142                                    command: [ | 
 |  143                                      emcc, '-o', '@OUTPUT@', | 
 |  144                                      '--js-library', JS_LIBRARY, | 
 |  145                                      '--js-library', BINDINGS_JS_LIBRARY, | 
 |  146                                      '@INPUT@' | 
 |  147                                    ]) | 
 |  148 # run the binding generator | 
 |  149 bindings_output = custom_target(BINDINGS_OUTPUT, | 
 |  150                                 input: bindings_generator, | 
 |  151                                 output: BINDINGS_OUTPUT, | 
 |  152                                 capture: true, | 
 |  153                                 command: [nodejs, '@INPUT@']) | 
 |  154  | 
 |  155 # link the core | 
 |  156 output_file = join_paths(meson.source_root(), 'lib', COMPILER_OUTPUT) | 
 |  157 compiler_output = custom_target(COMPILER_OUTPUT, | 
 |  158                                 build_by_default: true, | 
 |  159                                 input: core_objects + shared_objects, | 
 |  160                                 output: COMPILER_OUTPUT, | 
 |  161                                 depend_files: [ JS_LIBRARY ], | 
 |  162                                 command: [ | 
 |  163                                   emcc, '-o', output_file, | 
 |  164                                   '--post-js', bindings_output, | 
 |  165                                   '--js-library', JS_LIBRARY, | 
 |  166                                   '@INPUT@' | 
 |  167                                 ] + compiler_args + optional_args) | 
| LEFT | RIGHT |