1
%% ``The contents of this file are subject to the Erlang Public License,
2
%% Version 1.1, (the "License"); you may not use this file except in
3
%% compliance with the License. You should have received a copy of the
4
%% Erlang Public License along with this software. If not, it can be
5
%% retrieved via the world wide web at http://www.erlang.org/.
7
%% Software distributed under the License is distributed on an "AS IS"
8
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
9
%% the License for the specific language governing rights and limitations
12
%% The Initial Developer of the Original Code is Ericsson Utvecklings AB.
13
%% Portions created by Ericsson are Copyright 2002, Ericsson Utvecklings
14
%% AB. All Rights Reserved.''
21
-export([link/5, stub/0]).
23
-import(lists, [map/2, member/2]).
29
-include_lib("kernel/include/file.hrl").
31
link(Type, OutFile, EnvDict, BeamCode, Bin) ->
32
EnvBin = make_env_string(Type, EnvDict),
35
%% io:format("calling coff pack: Stub:~p out=~p",
36
%% [size(stub()), OutFile]),
37
OutB = coff:pack(stub(), EnvBin, BeamCode, Bin),
38
file:write_file(OutFile, OutB);
40
make_program(OutFile, EnvBin, BeamCode, Bin)
43
make_env_string(Type, Dict) ->
44
Str = map(fun({Key, Val}) ->
45
case (member($=, Key) or member($:, Key))of
49
case (member($\r, Val) or member($\n, Val)) of
51
exit({bad_value, Val});
53
[Key,$=,Val,separator(Type)]
59
separator(windows) -> "\r\n";
60
separator(unix) -> "\n".
62
make_program(OutFile, Env, BeamCode, Code) ->
63
%% erlang:display({boot_linker,make,OutFile}),
64
Head = case os:getenv("ERL_BEAM_EVM") of
66
"#!/usr/bin/env beam_evm\n";
69
"exec " ++ BeamEvm ++ " $0 ${1+\"$@\"}\n"]
73
":", integer_to_list(size(BeamCode)), "\n", BeamCode,
74
":", integer_to_list(size(Code)), "\n", Code,
76
prim_file:write_file(OutFile, Data),
77
prim_file:write_file_info(OutFile, #file_info{mode=8#755}),