Skip to content

Instantly share code, notes, and snippets.

@aredington
Created February 18, 2022 16:29
Show Gist options
  • Save aredington/a70b013179609d9182dba019f6ed076a to your computer and use it in GitHub Desktop.
Save aredington/a70b013179609d9182dba019f6ed076a to your computer and use it in GitHub Desktop.
How bad can we make a makefile tree?
#!/usr/bin/env ruby
File.open("Makefile","w") do |f|
targets = (1..6).to_a.repeated_permutation(6).map{|a| "t#{a.join}"}.join(" ")
f.puts("all: #{targets}\n\n")
(1..6).each do |root_target|
f.puts "t#{root_target}:\n"
f.puts "\tmkdir -p o#{root_target}\n"
f.puts "\techo #{root_target} > ./o#{root_target}/seed.txt\n\n"
end
(2..6).each do |depth|
(1..6).to_a.repeated_permutation(depth).each do |p|
f.puts "t#{p.join}: t#{p[0..-2].join}\n"
dir = p.map{|i| "o#{i}"}.join("/")
parent_dir = p[0..-2].map{|i| "o#{i}"}.join("/")
digit = p[-1]
f.puts "\tmkdir -p #{dir}\n"
f.puts "\tcat #{parent_dir}/seed.txt | sed 's/$$/#{digit}/' > #{dir}/seed.txt\n\n"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment