daily pastebin goal
33%
SHARE
TWEET

Untitled

a guest Mar 22nd, 2018 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Get all the dependencies of RGBDS assembly files recursively,
  2. # and output them using Make dependency syntax.
  3.  
  4. def dependencies_in(asm_file_paths)
  5.     asm_file_paths = asm_file_paths.clone
  6.     dependencies = {} of String => Set(String)
  7.  
  8.     asm_file_paths.each do |asm_file_path|
  9.         if !dependencies.has_key? asm_file_path
  10.             asm_dependencies, bin_dependencies = shallow_dependencies_of asm_file_path
  11.             dependencies[asm_file_path] = asm_dependencies | bin_dependencies
  12.             asm_file_paths.concat asm_dependencies.to_a
  13.         end
  14.     end
  15.  
  16.     return dependencies
  17. end
  18.  
  19. def shallow_dependencies_of(asm_file_path)
  20.     asm_dependencies = Set(String).new
  21.     bin_dependencies = Set(String).new
  22.  
  23.     File.each_line asm_file_path do |line|
  24.         keyword_match = line.match /^\s*(INC(?:LUDE|BIN))/i
  25.         next if !keyword_match
  26.  
  27.         keyword = keyword_match[1].upcase
  28.         line = line.split(';', 1)[0]
  29.         path = line[line.index('"').not_nil! + 1...line.rindex('"').not_nil!]
  30.         if keyword == "INCLUDE"
  31.             asm_dependencies << path
  32.         else
  33.             bin_dependencies << path
  34.         end
  35.     end
  36.  
  37.     return asm_dependencies, bin_dependencies
  38. end
  39.  
  40. if ARGV.size == 0
  41.     puts "Usage: #{PROGRAM_NAME.split('/')[-1]} <paths to assembly files...>"
  42.     exit 1
  43. end
  44.  
  45. dependencies_in(ARGV).each do |file, dependencies|
  46.     # It seems that if A depends on B which depends on C, and
  47.     # C is modified, Make needs you to change the modification
  48.     # time of B too. That's the reason for the "@touch $@".
  49.     puts "#{file}: #{dependencies.join(' ')}\n\t@touch $@" if !dependencies.empty?
  50. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top