Class: Bake::LibElements

Inherits:
Object
  • Object
show all
Defined in:
lib/bake/libElement.rb

Class Method Summary collapse

Class Method Details

.adaptPath(path, block, prefix) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/bake/libElement.rb', line 42

def self.adaptPath(path, block, prefix)
  adaptedPath = path
  if not File.is_absolute?(path)
    prefix ||= File.rel_from_to_project(@@projectDir, block.projectDir)
    adaptedPath = prefix + path if prefix
    adaptedPath = Pathname.new(adaptedPath).cleanpath.to_s
  end
  #adaptedPath = "\"" + adaptedPath + "\"" if adaptedPath.include?(" ")
  [adaptedPath, prefix]
end

.addOwnLib(block) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/bake/libElement.rb', line 53

def self.addOwnLib(block)
  if block.library
    adaptedPath, prefix = adaptPath(block.library.archive_name, block, prefix)
    cb = block.library.compileBlock
    if (block.prebuild and File.exist?adaptedPath) or
       (!cb.nil? and !(cb.calcSources(true, true) - cb.source_files_ignored_in_lib).empty?)
      if Bake.options.abs_path_in
        adaptedPath = File.expand_path(adaptedPath, @projectDir)
      end
      @@linker_libs_array << adaptedPath
      @@source_libraries << adaptedPath
    end
  end
  le = block.library ? block.library : (block.executable ? block.executable : nil)
  if le
    cb = le.compileBlock
    if !cb.nil? && !cb.object_files_ignored_in_lib.nil?
      cb.object_files_ignored_in_lib.each do |ldirect|
        adaptedPath, prefix = adaptPath(ldirect, block, prefix)
        if (!block.prebuild or File.exist?adaptedPath)
          if Bake.options.abs_path_in
            adaptedPath = File.expand_path(adaptedPath, @projectDir)
          end
          @@linker_libs_array << adaptedPath
          @@source_libraries << adaptedPath
        end
      end
    end
  end
end

.calc_linker_lib_string(block, tcs) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bake/libElement.rb', line 21

def self.calc_linker_lib_string(block, tcs)
  @@lib_path_set = []
  @@dep_set = Set.new
  @@linker = tcs[:LINKER]
  @@projectDir = block.projectDir
  @@source_libraries = []
  @@linker_libs_array = []
  @@withpath = []

  levels = @@linker[:LINK_ONLY_DIRECT_DEPS] ? 1 : -1
  collect_recursive(block, levels)
  @@source_libraries.reverse!
  @@lib_path_set.reverse!
  if @@linker[:LIST_MODE] and not @@lib_path_set.empty?
    @@linker_libs_array.unshift (@@linker[:LIB_PATH_FLAG] + @@lib_path_set.join(","));
  end
  @@linker_libs_array.reverse!

  return [@@source_libraries + @@withpath, @@linker_libs_array]
end

.calcLibElements(block) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/bake/libElement.rb', line 137

def self.calcLibElements(block)
  lib_elements = [] # value = array pairs [type, name/path string]

  block.config.libStuff.each do |l|
    if (Metamodel::UserLibrary === l)
      ln = l.name
      ls = nil
      if l.name.include?("/")
        pos = l.name.rindex("/")
        ls = block.convPath(l.name[0..pos-1], l)
        ln = l.name[pos+1..-1]
      end
      lib_elements << LibElement.new(LibElement::SEARCH_PATH, ls) if !ls.nil?
      lib_elements << LibElement.new(LibElement::USERLIB, ln)
    elsif (Metamodel::ExternalLibrarySearchPath === l)
      lib_elements << LibElement.new(LibElement::SEARCH_PATH, block.convPath(l))
    elsif (Metamodel::ExternalLibrary === l)
      ln = l.name
      ls = nil
      if l.name.include?("/")
        pos = l.name.rindex("/")
        ls = block.convPath(l.name[0..pos-1], l)
        ln = l.name[pos+1..-1]
      end
      if l.search
        lib_elements << LibElement.new(LibElement::SEARCH_PATH, ls) if !ls.nil?
        lib_elements << LibElement.new(LibElement::LIB, ln)
      else
        ln = ls + "/" + ln unless ls.nil?
        lib_elements << LibElement.new(LibElement::LIB_WITH_PATH, ln)
      end
    elsif (Metamodel::Dependency === l)
      lib_elements << LibElement.new(LibElement::DEPENDENCY, l.name+","+l.config)
    end

  end

  return lib_elements
end

.collect_recursive(block, levels = -1)) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/bake/libElement.rb', line 84

def self.collect_recursive(block, levels = -1)
  return if @@dep_set.include?block
  @@dep_set << block

  prefix = nil

  if levels != 0
    lib_elements = calcLibElements(block)
    lib_elements += block.lib_elements unless block.lib_elements.nil?

    lib_elements.reverse.each do |elem|
      case elem.type
      when LibElement::LIB
        @@linker_libs_array << "#{@@linker[:LIB_FLAG]}#{elem.value}"
      when LibElement::USERLIB
        @@linker_libs_array << "#{@@linker[:USER_LIB_FLAG]}#{elem.value}"
      when LibElement::LIB_WITH_PATH
        adaptedPath, prefix = adaptPath(elem.value, block, prefix)
        @@linker_libs_array <<  adaptedPath
        @@withpath << adaptedPath
      when LibElement::SEARCH_PATH
        adaptedPath, prefix = adaptPath(elem.value, block, prefix)
        lpf = "#{@@linker[:LIB_PATH_FLAG]}#{adaptedPath}"
  
        if not @@lib_path_set.include?adaptedPath
          @@lib_path_set << adaptedPath
          @@linker_libs_array << lpf if @@linker[:LIST_MODE] == false
        end
  
        # must be moved to the end, so delete it...
        ind1 = @@lib_path_set.index(adaptedPath)
        ind2 = @@linker_libs_array.index(lpf)
        @@lib_path_set.delete_at(ind1)      if not ind1.nil?
        @@linker_libs_array.delete_at(ind2) if not ind2.nil?
  
        # end place it at the end again
        @@lib_path_set << adaptedPath
        @@linker_libs_array << lpf if @@linker[:LIST_MODE] == false
  
      when LibElement::DEPENDENCY
        if Blocks::ALL_BLOCKS.include?elem.value
          bb = Blocks::ALL_BLOCKS[elem.value]
          collect_recursive(bb, levels-1)
        else
          # TODO: warning or error?
        end
      end
    end
  end
  addOwnLib(block)
end