blob: fabf46f7734ccf9ac1b25bca83861f1c9d44366b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
require 'fileutils'
namespace :build do
@vendor_dir = '../vendor'
@include_dir = "#{@vendor_dir}/include"
@library_dir = "#{@vendor_dir}/lib"
@bytecode_header_path = "../build/temp"
desc "Build the engine"
task :mruby do
Dir.chdir("core/mruby") do
#Dir.each_child("build/repos") do |repo_dir|
# Dir.each_child("build/repos/#{repo_dir}") do |gem_dir|
# puts "Checking updates for: #{gem_dir}"
# Dir.chdir("build/repos/#{repo_dir}/#{gem_dir}") do
# system('git pull')
# end
# end
#end
system('env MRUBY_CONFIG=../mruby_build.rb rake')
#FileUtils.cp("build/web/lib/libmruby.a", "../../vendor/web/lib/mruby/")
FileUtils.cp("build/host/lib/libmruby.a", "../../vendor/tux/lib/")
#FileUtils.cp("build/win/lib/libmruby.a", "../vendor/lib/win/mruby/")
end
end
desc "Build Raylib"
task :raylib do
Dir.chdir("core/raylib/src") do
`make clean`
puts 'building...'
`make PLATFORM=PLATFORM_DESKTOP`
puts
puts 'installing, this should prompt you to enter password unless you are already in sudo'
`sudo DESTDIR=#{File.expand_path('../../../vendor/tux')} make install`
`make clean`
#`make PLATFORM=PLATFORM_WEB`
#`sudo DESTDIR=/path/u/want make install`
#`make clean`
end
end
#desc 'Export to single file'
task :single_file do
result = ''
main = File.read('game/main.rb')
tmp = main.lines(chomp: true).select do |line|
line.include? 'require '
end
tmp.each do |file|
file.delete_prefix!('require ')
result += "#{File.read("game/#{file[1, file.length - 2]}")}\n"
end
result += main.lines.reject do |line|
line.include? 'require '
end.join
Dir.mkdir("build/temp") unless File.exists?("build/temp")
File.write('build/temp/main.rb', result)
end
#desc 'Compile the game to bytecode'
task :bytecode => :single_file do
Dir.mkdir("build/temp") unless File.exists?("build/temp")
Dir.chdir("build/temp") do
system("../../mruby/bin/mrbc -Bbytecode -obytecode.h main.rb")
end
end
desc 'Build the game for web'
task :web => :bytecode do
Dir.mkdir("build/web") unless File.exists?("build/web")
#Dir.chdir("build/web") do
Dir.chdir("game") do
system("emcc -Os -Wall -I#{@include_dir}/raylib -I#{@include_dir}/mruby -I#{@bytecode_header_path} #{@vendor_dir}/boilerplate.c #{@library_dir}/web/mruby/libmruby.a #{@library_dir}/web/raylib/libraylib.a -o ../build/web/index.html -s USE_GLFW=3 -DPLATFORM_WEB --preload-file ./assets --shell-file #{@vendor_dir}/html/minshell.html -s TOTAL_MEMORY=268435456") # -s ASYNCIFY
end
end
desc 'Build the game for Linux'
task :tux => :bytecode do
Dir.mkdir("build/tux") unless File.exists?("build/tux")
#Dir.chdir("build/tux") do
Dir.chdir("game") do
system("zig cc -target native #{@vendor_dir}/boilerplate.c -o ../build/tux/game -lGL -lm -lpthread -ldl -lrt -lX11 -I#{@bytecode_header_path} -I#{@include_dir}/raylib -I#{@include_dir}/mruby #{@library_dir}/tux/mruby/libmruby.a #{@library_dir}/tux/raylib/libraylib.a")
system("rsync -r ./assets ../build/tux")
end
end
#desc 'Build the game for Window'
#task :win do
# Dir.mkdir("build/win") unless File.exists?("build/win")
# Dir.chdir("build/win") do
# system('zig cc -target x86_64-windows-gnu ../template/game.c -o game -lwinmm -lgdi32 -lopengl32 -I../../mruby/include -I../../raylib/src ../../raylib_lib_files/raylib.lib ../../mruby/build/host/lib/libmruby.a')
# end
#end
end
desc 'Launch the game'
task :playtest => "build:single_file" do
Dir.chdir("game") do
system("../mruby/build/host/bin/mruby ../build/temp/main.rb")
end
end
task :p => :playtest
namespace :clean do
desc "Clean the mruby build folders"
task :mruby do
Dir.chdir("core/mruby") do
system('rake deep_clean')
end
end
task :raylib do
puts 'Not implemented yet'
end
end
desc "Create a server and open your game in your browser"
task :serve do
link = "http://localhost:8000/index.html"
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
system "start #{link}"
elsif RbConfig::CONFIG['host_os'] =~ /darwin/
system "open #{link}"
elsif RbConfig::CONFIG['host_os'] =~ /linux|bsd/
system "xdg-open #{link}"
end
`ruby -run -ehttpd build/web/ -p8000`
end
task :s => :serve
|