Created
May 4, 2019 21:47
-
-
Save mohkale/5a6dcc029de3d8d32e2554ecf33522da to your computer and use it in GitHub Desktop.
Simple C Project Rakefile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OBJ_DIRECTORY = "obj" | |
BIN_DIRECTORY = "bin" | |
COMPILER = 'g++' | |
FORMAT = "cpp" | |
source_files = FileList["*.#{FORMAT}"] | |
OUTPUT_FILE = File.join "./", BIN_DIRECTORY, "main.exe" | |
directory OBJ_DIRECTORY | |
directory BIN_DIRECTORY | |
gpp_args = "-std=c++11 -Wall -Werror=format-security -Werror=implicit-function-declaration -I includes" | |
task :run => :build do | |
sh OUTPUT_FILE | |
end | |
file OUTPUT_FILE => source_files.pathmap('obj/%X.o') do |task, args| | |
Rake::Task[BIN_DIRECTORY].invoke # build binary folder if it doesn't exist | |
sh "#{COMPILER} #{gpp_args} #{FileList.new task.sources} -o #{OUTPUT_FILE}" | |
end | |
rule(".o" => [ | |
Proc.new { |path| File.basename path.pathmap('%X') + ".#{FORMAT}" }, | |
]) do |task, args| | |
Rake::Task[OBJ_DIRECTORY].invoke # build object folder | |
sh "#{COMPILER} #{gpp_args} -c #{task.source} -o #{task}" | |
end | |
task :clean do | |
sh "rm -rf #{OBJ_DIRECTORY}/* #{BIN_DIRECTORY}/*" | |
end | |
task :default => :build | |
task :build => OUTPUT_FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment