Skip to content

Instantly share code, notes, and snippets.

@ageldama
Created May 17, 2022 13:00
Show Gist options
  • Save ageldama/c18cd1ad1671fde808e552aeb886b318 to your computer and use it in GitHub Desktop.
Save ageldama/c18cd1ad1671fde808e552aeb886b318 to your computer and use it in GitHub Desktop.
Rakefile: cc with separated build dir
require 'pathname'
SRCS = FileList['**/*.c']
DSTS = SRCS.ext('o').pathmap('build/%d/%f').map do |f|
Pathname.new(f).cleanpath.to_s
end
DST_TO_SRC_H = DSTS.zip(SRCS).to_h
task :compile => DSTS
task :clean do |t|
DSTS.each do |f|
rm f, force: true
end
end
rule '.o' => ->(f){DSTS.zip(SRCS).to_h[f]} do |t|
mkdir_p t.name.pathmap('%d')
sh "cc -c -o #{t.name} #{t.source}"
end
task :default => :compile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment