#!/usr/bin/env escript
%% -*- erlang -*-

%%
%% %CopyrightBegin%
%%
%% SPDX-License-Identifier: Apache-2.0
%%
%% Copyright Ericsson AB 2020-2025. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%%     http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%
%% %CopyrightEnd%
%%

-define(YCF, "yielding_c_fun").

main([]) ->
    YCF = case os:type() of
              {win32, _} ->
                  ?YCF ++ ".exe";
              _ ->
                  ?YCF
          end,
    RootDir = code:root_dir(),
    PureBootstrapYCF = filename:join([RootDir, "bin", YCF]),
    case file:read_file_info(PureBootstrapYCF) of
        {ok, _} ->
            io:format("~s~n", [PureBootstrapYCF]),
            halt(0);
        {error, _} ->
            ok
    end,
    InstalledYCF = filename:join([RootDir,
                                  "erts-" ++ erlang:system_info(version),
                                  "bin",
                                  YCF]),
    case file:read_file_info(InstalledYCF) of
        {ok, _} ->
            io:format("~s~n", [InstalledYCF]),
            halt(0);
        {error, _} ->
            io:format("No '~s' found in used bootstrap system under '~s'~n",
                      [YCF, RootDir]),
            halt(1)
    end,
    ok.
