You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
1.6 KiB
Ruby
89 lines
1.6 KiB
Ruby
#!/usr/bin/ruby
|
|
|
|
#I'll put this in here as an example
|
|
|
|
# make a folder called src and a folder called build
|
|
# then put some c source code in src
|
|
# then run rub and watch it build
|
|
|
|
# of course you could make your own build.rb to build any project
|
|
|
|
# ruby might not let you modify CONSTANTS
|
|
# so put a $ in front of the name which makes
|
|
# them global and not CONSTANT
|
|
$CC="gcc"
|
|
CFLAGS="-O1 -march=native -std=c11 -fmacro-prefix-map=src="
|
|
$EFLAGS = "" #extra flags
|
|
APPNAME="chess"
|
|
SRCDIR="src"
|
|
BUILDDIR="build"
|
|
INCLUDE=""
|
|
LIB="-lraylib"
|
|
|
|
#handle argument parsing yourself
|
|
def parse(arg)
|
|
case arg
|
|
when "clean"
|
|
`rm build/*`
|
|
`rm #{APPNAME}`
|
|
exit(0)
|
|
|
|
when "debug"
|
|
$EFLAGS = "-DDEBUG"
|
|
main
|
|
|
|
when arg.split("=")[0] = "cc"
|
|
$CC = arg.split("=")[1]
|
|
main
|
|
|
|
else
|
|
error "unknown argument: #{arg}"
|
|
end
|
|
end
|
|
|
|
#same as above
|
|
def args
|
|
case ARGV.count
|
|
when 0
|
|
main
|
|
when 1
|
|
parse(ARGV[0])
|
|
else
|
|
puts "too many arguments"
|
|
end
|
|
end
|
|
|
|
#main build function
|
|
def main
|
|
if Dir.children(SRCDIR).count == 0
|
|
error("src directory empty")
|
|
end
|
|
|
|
threads = []
|
|
|
|
Dir.each_child(SRCDIR) {|x|
|
|
threads << Thread.new {
|
|
system("#{$CC} #{INCLUDE} #{CFLAGS} #{$EFLAGS} -c #{SRCDIR}/#{x} -o #{BUILDDIR}/#{File.basename(x, ".*") + ".o"}") if x.end_with?(".c")
|
|
message "compiled: #{x}\n" if x.end_with?(".c")
|
|
}
|
|
}
|
|
|
|
threads.each{ |t| t.join }
|
|
|
|
#wait for each thread to finish
|
|
until threads.map { |t| t.alive? }.include?(false)
|
|
end
|
|
|
|
build = Dir.each_child(BUILDDIR)
|
|
o_files = []
|
|
build.each { |s|
|
|
o_files.append("#{BUILDDIR}/#{s}")
|
|
}
|
|
|
|
`#{$CC} #{CFLAGS} #{$EFLAGS} #{o_files.join(" ")} -o #{APPNAME} #{LIB}`
|
|
exit(0)
|
|
end
|
|
|
|
#run some functions
|
|
args
|