pull/1/head
sandyx 11 months ago
commit a05e43525d

@ -0,0 +1,89 @@
#!/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"
def error(msg)
puts "error: #{msg}"
exit(1)
end
#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
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")
print "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

@ -0,0 +1,2 @@
chmod +x rub
cp rub /usr/local/bin/rub

@ -0,0 +1,9 @@
#Rub
>to install
```
#sh install
```
>to run
```
$rub
```

3
rub

@ -0,0 +1,3 @@
#!/usr/bin/ruby
require "#{Dir.pwd}/build.rb"
Loading…
Cancel
Save