anchor.diff:  %% Public API
   %% ===================================================================
   
  -%% Port driver name - determined by app name
  -%% Source files (or c_src/*.c by default)
  -%% Pre-compile hook (optional)
  -%% Env variables
  -
  -compile(Config, _AppFile) ->
  -    %% Compose list of sources from config file -- default to c_src/*.c
  +%% Supported configuration variables:
  +%%
  +%% * port_sources - Erlang list of files and/or wildcard strings to be compiled
  +%%
  +%% * port_envs - Erlang list of key/value pairs which will control the environment when
  +%%               running the compiler and linker. By default, the following variables
  +%%               are defined:
  +%%               CC       - C compiler
  +%%               CXX      - C++ compiler
  +%%               CFLAGS   - C compiler
  +%%               CXXFLAGS - C++ compiler
  +%%               LDFLAGS  - Link flags
  +%%               DRIVER_CFLAGS  - default -I paths for erts and ei
  +%%               DRIVER_LDFLAGS - default -L and -lerl_interface -lei
  +%%
  +%%               Note that if you wish to extend (vs. replace) these variables, you MUST
  +%%               include a shell-style reference in your definition. E.g. to extend CFLAGS,
  +%%               do something like:
  +%%
  +%%               {port_envs, [{"CFLAGS", "$CFLAGS -MyOtherOptions"}]}
  +%%
  +%%               It is also possible to specify platform specific options by specifying a triplet
  +%%               where the first string is a regex that is checked against erlang's system architecture
  +%%               string. E.g. to specify a CFLAG that only applies to x86_64 on linux do:
  +%%
  +%%               {port_envs, [{"x86_64.*-linux", "CFLAGS", "$CFLAGS -X86Options"}]}
  +%%
  +%% * port_pre_script - Tuple which specifies a pre-compilation script to run, and a filename that
  +%%                     exists as a result of the script running. 
  +%%
  +%% * port_cleanup_script - String that specifies a script to run during cleanup. Use this to remove
  +%%                         files/directories created by port_pre_script.
  +%%
  +
  +compile(Config, AppFile) ->
  +    %% Compose list of sources from config file -- defaults to c_src/*.c
       Sources = expand_sources(rebar_config:get_list(Config, port_sources, ["c_src/*.c"]), []),
       case Sources of
           [] ->
  
positive.code:                   orddict:from_list(OverrideEnvs),
                    orddict:from_list(DefaultEnvs)).
  
      
      
  
  compiler(".cc")  -> "$CXX";
  compiler(".cp")  -> "$CXX";
  compiler(".cxx") -> "$CXX";
  
negative.code: compiler(".c++") -> "$CXX";
  compiler(".C")   -> "$CXX";
  compiler(_)      -> "$CC".
  
  
  %%
  %% Given env. variable FOO we want to expand all references to
  %% it in InStr. References can have two forms: $FOO and ${FOO}
  %%
  expand_env_variable(InStr, VarName, VarValue) ->
  
      R1 = re:replace(InStr, "\\\$" ++ VarName, VarValue),
      re:replace(R1, "\\\${" ++ VarName ++ "}", VarValue, [{return, list}]).
  
  
  %%
  %% Filter a list of env vars such that only those which match the provided
  %% architecture regex (or do not have a regex) are returned.
  %%
  filter_envs([], Acc) ->
      lists:reverse(Acc);
  filter_envs([{ArchRegex, Key, Value} | Rest], Acc) ->
      case rebar_utils:is_arch(ArchRegex) of
          true ->
              filter_envs(Rest, [{Key, Value} | Acc]);
          false ->
              filter_envs(Rest, Acc)
      end;
  filter_envs([{Key, Value} | Rest], Acc) ->
      filter_envs(Rest, [{Key, Value} | Acc]).
  
  
  erts_dir() ->
      lists:concat([code:root_dir(), "/erts-", erlang:system_info(version)]).
  
  default_env() ->
      [{"CC", "gcc"},
       {"CXX", "g++"},
       {"CFLAGS", "-g -Wall -fPIC"},
       {"CXXFLAGS", "-g -Wall -fPIC"},
       {"darwin", "LDFLAGS", "-bundle -flat_namespace -undefined suppress"},
       {"linux", "LDFLAGS", "-shared"},
       {"DRIVER_CFLAGS", lists:concat([" -I", code:lib_dir(erl_interface, include),
                                       " -I", filename:join(erts_dir(), include),
                                       " "])},
       {"DRIVER_LDFLAGS", lists:concat([" -L", code:lib_dir(erl_interface, lib),
                                        " -lerl_interface -lei"])}].
  
  
  
  source_to_bin(Source) ->
      Ext = filename:extension(Source),
      filename:rootname(Source, Ext) ++ ".o".
  
  so_name(AppFile) ->
      %% Get the app name, which we'll use to generate the linked port driver name
      case rebar_app_utils:load_app_file(AppFile) of
          {ok, AppName, _} ->
              ok;
          error ->
              AppName = undefined,
              ?FAIL
      end,
  
      %% Construct the driver name 
      ?FMT("priv/~s_drv.so", [AppName]).
  
  