~statik/ubuntu/maverick/erlang/erlang-merge-testing

« back to all changes in this revision

Viewing changes to erts/boot/src/boot_linker.erl

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-05-01 10:14:38 UTC
  • mfrom: (3.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090501101438-6qlr6rsdxgyzrg2z
Tags: 1:13.b-dfsg-2
* Cleaned up patches: removed unneeded patch which helped to support
  different SCTP library versions, made sure that changes for m68k
  architecture applied only when building on this architecture.
* Removed duplicated information from binary packages descriptions.
* Don't require libsctp-dev build-dependency on solaris-i386 architecture
  which allows to build Erlang on Nexenta (thanks to Tim Spriggs for
  the suggestion).

Show diffs side-by-side

added added

removed removed

Lines of Context:
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/.
6
 
%% 
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
10
 
%% under the License.
11
 
%% 
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.''
15
 
%% 
16
 
%%     $Id$
17
 
%%
18
 
 
19
 
-module(boot_linker).
20
 
 
21
 
-export([link/5, stub/0]).
22
 
 
23
 
-import(lists, [map/2, member/2]).
24
 
 
25
 
-use([lists]).
26
 
 
27
 
-include("stub.hrl").
28
 
 
29
 
-include_lib("kernel/include/file.hrl").
30
 
 
31
 
link(Type, OutFile, EnvDict, BeamCode, Bin) ->
32
 
    EnvBin = make_env_string(Type, EnvDict),
33
 
    case Type of
34
 
        windows ->
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);
39
 
        unix ->
40
 
            make_program(OutFile, EnvBin, BeamCode, Bin)
41
 
    end.
42
 
 
43
 
make_env_string(Type, Dict) ->
44
 
    Str = map(fun({Key, Val}) ->
45
 
                      case (member($=, Key) or member($:, Key))of
46
 
                          true ->
47
 
                              exit({bad_key, Key});
48
 
                          false ->
49
 
                              case (member($\r, Val) or member($\n, Val)) of
50
 
                                  true ->
51
 
                                      exit({bad_value, Val});
52
 
                                  false ->
53
 
                                      [Key,$=,Val,separator(Type)]
54
 
                              end
55
 
                      end
56
 
              end, Dict),
57
 
    list_to_binary(Str).
58
 
 
59
 
separator(windows) -> "\r\n";
60
 
separator(unix)    -> "\n".
61
 
    
62
 
make_program(OutFile, Env, BeamCode, Code) ->
63
 
    %% erlang:display({boot_linker,make,OutFile}),
64
 
    Head = case os:getenv("ERL_BEAM_EVM") of
65
 
               false ->
66
 
                   "#!/usr/bin/env beam_evm\n";
67
 
               BeamEvm ->
68
 
                   ["#!/bin/sh\n",
69
 
                    "exec " ++ BeamEvm ++ " $0 ${1+\"$@\"}\n"]
70
 
           end,
71
 
    Data = [Head,
72
 
            Env,
73
 
            ":", integer_to_list(size(BeamCode)), "\n", BeamCode,
74
 
            ":", integer_to_list(size(Code)),  "\n", Code,
75
 
            "--end--\n"],
76
 
    prim_file:write_file(OutFile, Data),
77
 
    prim_file:write_file_info(OutFile, #file_info{mode=8#755}),
78
 
    true.