mcbuild 0.0.2 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mcbuild.rb +260 -46
- metadata +4 -4
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 7ea4f037ff215ebdc917095027295ba8645fa663
         | 
| 4 | 
            +
              data.tar.gz: 365c341ebb2cb8e3ec15de40df0153357045ef5a
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: c7c3c6fd1cd9c50dd488571260af948e506d0da9039f42b749f3baa9fa15ac0be5ead7baa6b85248d360a088270881f7e82a022e515e1f12001c7c5e281e40a9
         | 
| 7 | 
            +
              data.tar.gz: 7de5707dd0149b7f81b93118974447c0a6fc6223a839d5f32a09e7231f395b5b217dbe08eaa49b579b2b70fcf30189b0f684e2a2911cd7973c00ba31cfc5b6db
         | 
    
        data/lib/mcbuild.rb
    CHANGED
    
    | @@ -2,37 +2,148 @@ | |
| 2 2 | 
             
            require 'find'
         | 
| 3 3 | 
             
            require 'fileutils'
         | 
| 4 4 |  | 
| 5 | 
            +
            class MCConfig
         | 
| 6 | 
            +
            	def self.x86_64
         | 
| 7 | 
            +
            		'x86_64'
         | 
| 8 | 
            +
            	end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            	def self.armv6
         | 
| 11 | 
            +
            		'armv6'
         | 
| 12 | 
            +
            	end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            	def self.armv7
         | 
| 15 | 
            +
            		'armv7'
         | 
| 16 | 
            +
            	end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            	def self.armv7s
         | 
| 19 | 
            +
            		'armv7s'
         | 
| 20 | 
            +
            	end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            	def self.arm64
         | 
| 23 | 
            +
            		'arm64'
         | 
| 24 | 
            +
            	end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
            	def self.c89
         | 
| 27 | 
            +
            		'c89'
         | 
| 28 | 
            +
            	end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            	def self.c99
         | 
| 31 | 
            +
            		'c99'
         | 
| 32 | 
            +
            	end
         | 
| 33 | 
            +
            end
         | 
| 34 | 
            +
             | 
| 5 35 | 
             
            class MCBuild
         | 
| 36 | 
            +
            	def self.noArgs(valid_args)
         | 
| 37 | 
            +
            		ARGV.each { |arg|
         | 
| 38 | 
            +
            			valid_args.each { |va|
         | 
| 39 | 
            +
            				if va == arg
         | 
| 40 | 
            +
            					return
         | 
| 41 | 
            +
            				end
         | 
| 42 | 
            +
            			}
         | 
| 43 | 
            +
            		}
         | 
| 44 | 
            +
            		yield valid_args
         | 
| 45 | 
            +
            	end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
            	def self.printArgs(valid_args)
         | 
| 48 | 
            +
            		ARGV.each { |arg|
         | 
| 49 | 
            +
            			valid_args.each { |va|
         | 
| 50 | 
            +
            				if va == arg
         | 
| 51 | 
            +
            					return
         | 
| 52 | 
            +
            				end
         | 
| 53 | 
            +
            			}
         | 
| 54 | 
            +
            		}
         | 
| 55 | 
            +
            		puts "usage:"
         | 
| 56 | 
            +
            		valid_args.each { |arg|
         | 
| 57 | 
            +
            			puts "./build.rb #{arg}"
         | 
| 58 | 
            +
            		}
         | 
| 59 | 
            +
            	end
         | 
| 60 | 
            +
             
         | 
| 6 61 | 
             
            	def self.waitArg(arg)
         | 
| 7 62 | 
             
            		ARGV.each do |_arg|
         | 
| 8 63 | 
             
            			if _arg==arg
         | 
| 9 | 
            -
            				yield | 
| 10 | 
            -
            			else
         | 
| 11 | 
            -
            				puts "usage: ./script.rb #{arg}"
         | 
| 64 | 
            +
            				yield
         | 
| 12 65 | 
             
            			end
         | 
| 13 66 | 
             
            		end
         | 
| 14 67 | 
             
            	end
         | 
| 15 68 |  | 
| 16 | 
            -
            	def  | 
| 17 | 
            -
            		 | 
| 18 | 
            -
            			 | 
| 19 | 
            -
            		 | 
| 20 | 
            -
            			 | 
| 69 | 
            +
            	def self.clean(path)
         | 
| 70 | 
            +
            		begin
         | 
| 71 | 
            +
            			FileUtils.rm_rf(path)
         | 
| 72 | 
            +
            		rescue Exception => e
         | 
| 73 | 
            +
            			puts e
         | 
| 21 74 | 
             
            		end
         | 
| 22 75 | 
             
            	end
         | 
| 23 76 |  | 
| 24 | 
            -
            	 | 
| 25 | 
            -
             | 
| 26 | 
            -
            		 | 
| 77 | 
            +
            	#remove the last slash from path
         | 
| 78 | 
            +
            	def remove_slash(str)
         | 
| 79 | 
            +
            		arr = str.split('/')
         | 
| 80 | 
            +
            		ret = arr.first
         | 
| 81 | 
            +
            		arr.delete_at(0)
         | 
| 82 | 
            +
            		arr.each { |s|
         | 
| 83 | 
            +
            			if s != ''
         | 
| 84 | 
            +
            				ret += "/#{s}"
         | 
| 85 | 
            +
            			end
         | 
| 86 | 
            +
            		}
         | 
| 87 | 
            +
            		ret
         | 
| 88 | 
            +
            	end
         | 
| 89 | 
            +
             | 
| 90 | 
            +
            	def initialize(dir)
         | 
| 91 | 
            +
            		@d = remove_slash(dir)
         | 
| 92 | 
            +
            		@headers = []
         | 
| 93 | 
            +
            		@name = "mcdefault"
         | 
| 94 | 
            +
            		@fext = ".c"
         | 
| 95 | 
            +
            		@oext = ".o"
         | 
| 96 | 
            +
            		@aext = ".a"
         | 
| 97 | 
            +
            		@mach = "x86_64"
         | 
| 98 | 
            +
            		@std  = "c99"
         | 
| 99 | 
            +
            		@flags = ""
         | 
| 100 | 
            +
            		@outpath = "_build"
         | 
| 101 | 
            +
            		@excludes = []
         | 
| 102 | 
            +
            		@dependency = []
         | 
| 103 | 
            +
             | 
| 104 | 
            +
            		@compile_arg = " -I#{@d}/#{@outpath}/archive"
         | 
| 105 | 
            +
            		@link_arg    = " -L#{@d}/#{@outpath}/archive"
         | 
| 106 | 
            +
            	end
         | 
| 27 107 |  | 
| 28 | 
            -
             | 
| 108 | 
            +
            	def export_path
         | 
| 109 | 
            +
            		"#{@d}/#{@outpath}/archive"
         | 
| 110 | 
            +
            	end
         | 
| 29 111 |  | 
| 112 | 
            +
            	def name
         | 
| 113 | 
            +
            		@name
         | 
| 114 | 
            +
            	end
         | 
| 115 | 
            +
             | 
| 116 | 
            +
            	def headers
         | 
| 117 | 
            +
            		@headers
         | 
| 118 | 
            +
            	end
         | 
| 119 | 
            +
             | 
| 120 | 
            +
            	def excludes
         | 
| 121 | 
            +
            		@excludes
         | 
| 122 | 
            +
            	end
         | 
| 123 | 
            +
             | 
| 124 | 
            +
            	def set_headers(headers)
         | 
| 125 | 
            +
            		@headers = headers
         | 
| 126 | 
            +
            		self
         | 
| 127 | 
            +
            	end
         | 
| 128 | 
            +
             | 
| 129 | 
            +
            	def set_name(name)
         | 
| 130 | 
            +
            		@name = name
         | 
| 131 | 
            +
            		self
         | 
| 132 | 
            +
            	end	
         | 
| 133 | 
            +
             | 
| 134 | 
            +
            	def set_fext(fext)
         | 
| 30 135 | 
             
            		@fext = fext
         | 
| 136 | 
            +
            		self
         | 
| 137 | 
            +
            	end
         | 
| 138 | 
            +
             | 
| 139 | 
            +
            	def set_oext(oext)
         | 
| 31 140 | 
             
            		@oext = oext
         | 
| 141 | 
            +
            		self
         | 
| 142 | 
            +
            	end
         | 
| 143 | 
            +
             | 
| 144 | 
            +
            	def set_aext(aext)
         | 
| 32 145 | 
             
            		@aext = aext
         | 
| 33 | 
            -
            		 | 
| 34 | 
            -
            		@std = std
         | 
| 35 | 
            -
            		@outpath = outpath
         | 
| 146 | 
            +
            		self
         | 
| 36 147 | 
             
            	end
         | 
| 37 148 |  | 
| 38 149 | 
             
            	def set_arch(arch)
         | 
| @@ -40,94 +151,197 @@ class MCBuild | |
| 40 151 | 
             
            		self
         | 
| 41 152 | 
             
            	end
         | 
| 42 153 |  | 
| 154 | 
            +
            	def set_std(std)
         | 
| 155 | 
            +
            		@std = std
         | 
| 156 | 
            +
            		self
         | 
| 157 | 
            +
            	end
         | 
| 158 | 
            +
            	
         | 
| 159 | 
            +
            	def set_flags(flags)
         | 
| 160 | 
            +
            		@flags = flags
         | 
| 161 | 
            +
            		self
         | 
| 162 | 
            +
            	end
         | 
| 163 | 
            +
             | 
| 164 | 
            +
            	def set_outpath(outpath)
         | 
| 165 | 
            +
            		@outpath = outpath
         | 
| 166 | 
            +
            		self
         | 
| 167 | 
            +
            	end
         | 
| 168 | 
            +
             | 
| 169 | 
            +
            	def set_excludes(excludes)
         | 
| 170 | 
            +
            		@excludes = Array.new(excludes)
         | 
| 171 | 
            +
            		self
         | 
| 172 | 
            +
            	end
         | 
| 173 | 
            +
             | 
| 43 174 | 
             
            	def info
         | 
| 44 175 | 
             
            		puts "Monk-C compiler use settings:"
         | 
| 45 176 | 
             
            		puts "--------------------------------"
         | 
| 46 177 | 
             
            		puts "           CPU Arch -> #{@mach}"
         | 
| 47 178 | 
             
            		puts "         C standard -> #{@std}"
         | 
| 179 | 
            +
            		puts "               name -> #{@name}"
         | 
| 48 180 | 
             
            		puts " filename extension -> #{@fext}"
         | 
| 49 181 | 
             
            		puts "   output extension -> #{@oext}"
         | 
| 50 182 | 
             
            		puts "  archive extension -> #{@aext}"
         | 
| 183 | 
            +
            		puts "      compile flags -> #{@flags}"
         | 
| 184 | 
            +
            		puts "         source dir -> #{@d}"
         | 
| 185 | 
            +
            		puts "         export dir -> #{self.export_path}"
         | 
| 186 | 
            +
            		puts "           excludes -> #{self.excludes}"
         | 
| 51 187 | 
             
            		puts "--------------------------------"
         | 
| 52 188 | 
             
            		puts "C compiler infos:"
         | 
| 53 189 | 
             
            		puts "--------------------------------"
         | 
| 54 190 | 
             
            		system("cc --version")
         | 
| 55 191 | 
             
            		puts "--------------------------------"
         | 
| 192 | 
            +
            		self
         | 
| 56 193 | 
             
            	end
         | 
| 57 194 |  | 
| 58 195 | 
             
            	def clean
         | 
| 196 | 
            +
            		MCBuild.clean("#{@d}/#{@outpath}")
         | 
| 197 | 
            +
            		self
         | 
| 198 | 
            +
            	end
         | 
| 199 | 
            +
             | 
| 200 | 
            +
            	def prepare
         | 
| 59 201 | 
             
            		begin
         | 
| 60 202 | 
             
            			FileUtils.rm_rf("#{@d}/#{@outpath}")
         | 
| 203 | 
            +
            			FileUtils.mkdir_p "#{@d}/#{@outpath}/archive"
         | 
| 204 | 
            +
            			if @headers.count != 0
         | 
| 205 | 
            +
            				self.copy_headers
         | 
| 206 | 
            +
            			else
         | 
| 207 | 
            +
            				self.copy_headers_all
         | 
| 208 | 
            +
            			end
         | 
| 61 209 | 
             
            		rescue Exception => e
         | 
| 62 210 | 
             
            			puts e
         | 
| 63 211 | 
             
            		end
         | 
| 212 | 
            +
            		self
         | 
| 64 213 | 
             
            	end
         | 
| 65 214 |  | 
| 66 | 
            -
            	def  | 
| 67 | 
            -
            		 | 
| 68 | 
            -
             | 
| 215 | 
            +
            	def set_dependency(libs=[])
         | 
| 216 | 
            +
            		libs.each { |lib|
         | 
| 217 | 
            +
            			path = lib.export_path
         | 
| 218 | 
            +
            			name = lib.name
         | 
| 69 219 |  | 
| 70 | 
            -
            		libpath.each { |path|
         | 
| 71 220 | 
             
            			@compile_arg += " -I#{path}"
         | 
| 72 | 
            -
            			@link_arg | 
| 73 | 
            -
             | 
| 74 | 
            -
             | 
| 75 | 
            -
            		libs.each { |lib|
         | 
| 76 | 
            -
            			@link_arg += " -l#{lib}"
         | 
| 221 | 
            +
            			@link_arg    += " -L#{path}"
         | 
| 222 | 
            +
            			@link_arg    += " -l#{name}"
         | 
| 77 223 | 
             
            		}
         | 
| 78 | 
            -
             | 
| 79 224 | 
             
            		@link_arg += @compile_arg
         | 
| 225 | 
            +
            		self
         | 
| 226 | 
            +
            	end
         | 
| 80 227 |  | 
| 228 | 
            +
            	def prehash(string)
         | 
| 229 | 
            +
            		self
         | 
| 230 | 
            +
            	end
         | 
| 231 | 
            +
             | 
| 232 | 
            +
            	def copy_headers
         | 
| 81 233 | 
             
            		begin
         | 
| 82 | 
            -
            			 | 
| 83 | 
            -
             | 
| 234 | 
            +
            			Find.find(@d) { |header|
         | 
| 235 | 
            +
            				base = File.basename(header)
         | 
| 236 | 
            +
            				if @headers.include? base
         | 
| 237 | 
            +
            					puts "copying-> #{header}"
         | 
| 238 | 
            +
            					FileUtils.cp("#{header}", "#{@d}/#{@outpath}/archive")
         | 
| 239 | 
            +
            				end
         | 
| 240 | 
            +
            			}
         | 
| 84 241 | 
             
            		rescue Exception => e
         | 
| 85 242 | 
             
            			puts e
         | 
| 86 243 | 
             
            		end
         | 
| 244 | 
            +
            		self
         | 
| 87 245 | 
             
            	end
         | 
| 88 246 |  | 
| 89 | 
            -
            	def  | 
| 90 | 
            -
            		
         | 
| 91 | 
            -
            	end
         | 
| 92 | 
            -
             | 
| 93 | 
            -
            	def copy_headers(headers)
         | 
| 247 | 
            +
            	def copy_headers_all(except=[])
         | 
| 94 248 | 
             
            		begin
         | 
| 95 | 
            -
            			 | 
| 96 | 
            -
            				 | 
| 97 | 
            -
            				 | 
| 249 | 
            +
            			Find.find(@d) { |header|
         | 
| 250 | 
            +
            				ext = File.extname(header)
         | 
| 251 | 
            +
            				base = File.basename(header)
         | 
| 252 | 
            +
            				if (ext == ".h") && (!header.include? self.export_path)
         | 
| 253 | 
            +
            					if (except != nil) && (except.include? base)
         | 
| 254 | 
            +
            						puts "except: #{base}"
         | 
| 255 | 
            +
            					else
         | 
| 256 | 
            +
            						puts "copying-> #{header}"
         | 
| 257 | 
            +
            						FileUtils.cp("#{header}", self.export_path)
         | 
| 258 | 
            +
            					end
         | 
| 259 | 
            +
            				end
         | 
| 98 260 | 
             
            			}
         | 
| 99 261 | 
             
            		rescue Exception => e
         | 
| 100 262 | 
             
            			puts e
         | 
| 101 263 | 
             
            		end
         | 
| 264 | 
            +
            		self
         | 
| 102 265 | 
             
            	end
         | 
| 103 266 |  | 
| 104 267 | 
             
            	def compile_file(file)
         | 
| 105 268 | 
             
            		base = File.basename(file, ".c")
         | 
| 106 | 
            -
            		cmd = "cc -arch #{@mach} -std=#{@std} -c -o #{@d}/#{@outpath}/#{base}#{@oext} #{file} #{@compile_arg}"
         | 
| 269 | 
            +
            		cmd = "cc -arch #{@mach} -std=#{@std} #{@flags} -c -o #{@d}/#{@outpath}/#{base}#{@oext} #{file} #{@compile_arg}"
         | 
| 107 270 | 
             
            		puts(cmd)
         | 
| 108 271 | 
             
            		system(cmd)
         | 
| 272 | 
            +
            		self
         | 
| 109 273 | 
             
            	end
         | 
| 110 274 |  | 
| 111 | 
            -
            	def compile | 
| 112 | 
            -
            		 | 
| 113 | 
            -
             | 
| 114 | 
            -
             | 
| 115 | 
            -
            			 | 
| 116 | 
            -
             | 
| 275 | 
            +
            	def compile
         | 
| 276 | 
            +
            		self.clean
         | 
| 277 | 
            +
            		self.prepare
         | 
| 278 | 
            +
            		begin
         | 
| 279 | 
            +
            			Find.find(@d) { |file|
         | 
| 280 | 
            +
            				ext = File.extname(file)
         | 
| 281 | 
            +
            				base = File.basename(file)
         | 
| 282 | 
            +
            				if ext == ".c" || ext == ".asm" || ext == ".S"
         | 
| 283 | 
            +
            					if (@excludes != nil) && (@excludes.include? base)
         | 
| 284 | 
            +
            						puts "exclude: #{base}"
         | 
| 285 | 
            +
            					else
         | 
| 286 | 
            +
            						compile_file(file)
         | 
| 287 | 
            +
            					end
         | 
| 288 | 
            +
            				end
         | 
| 289 | 
            +
            			}
         | 
| 290 | 
            +
            		rescue Exception => e
         | 
| 291 | 
            +
            			puts "Error[#{@d}]: " + e.to_s
         | 
| 292 | 
            +
            		end
         | 
| 293 | 
            +
            		self
         | 
| 117 294 | 
             
            	end
         | 
| 118 295 |  | 
| 119 | 
            -
            	def archive_lib | 
| 120 | 
            -
            		cmd = "ar -r #{@d}/#{@outpath}/archive | 
| 296 | 
            +
            	def archive_lib
         | 
| 297 | 
            +
            		cmd = "ar -r #{@d}/#{@outpath}/archive/lib#{@name}#{@aext} #{@d}/#{@outpath}/*#{@oext}"
         | 
| 121 298 | 
             
            		puts(cmd)
         | 
| 122 299 | 
             
            		system(cmd)
         | 
| 300 | 
            +
            		self
         | 
| 123 301 | 
             
            	end
         | 
| 124 302 |  | 
| 125 | 
            -
            	def archive_exe | 
| 126 | 
            -
            		cmd = "cc -o #{@d}/#{@outpath}/archive/#{name} #{@d}/#{@outpath}/*#{@oext} #{@link_arg}"
         | 
| 303 | 
            +
            	def archive_exe
         | 
| 304 | 
            +
            		cmd = "cc -o #{@d}/#{@outpath}/archive/#{@name} #{@d}/#{@outpath}/*#{@oext} #{@link_arg}"
         | 
| 127 305 | 
             
            		puts(cmd)
         | 
| 128 306 | 
             
            		system(cmd)
         | 
| 307 | 
            +
            		self
         | 
| 308 | 
            +
            	end
         | 
| 309 | 
            +
             | 
| 310 | 
            +
            	def run
         | 
| 311 | 
            +
            		system("#{self.export_path}/#{name}")
         | 
| 312 | 
            +
            	end
         | 
| 313 | 
            +
             | 
| 314 | 
            +
            	def done
         | 
| 315 | 
            +
            		puts "---------- build finished ----------"
         | 
| 316 | 
            +
            		puts "#{self.export_path}/#{name}"
         | 
| 129 317 | 
             
            	end
         | 
| 130 318 | 
             
            end
         | 
| 131 319 |  | 
| 320 | 
            +
            #test area
         | 
| 321 | 
            +
            =begin
         | 
| 322 | 
            +
            runt = MCBuild.new('../../../mcruntime')
         | 
| 323 | 
            +
            	.set_name("monkc")
         | 
| 324 | 
            +
            	.set_headers(["monkc.h"])
         | 
| 325 | 
            +
            	.set_excludes(["MCNonLock.S"])
         | 
| 326 | 
            +
            	.info
         | 
| 327 | 
            +
            	.compile
         | 
| 328 | 
            +
            	.archive_lib
         | 
| 329 | 
            +
             | 
| 330 | 
            +
            lmt = MCBuild.new('../../../lemontea')
         | 
| 331 | 
            +
            	.set_name("lemontea")
         | 
| 332 | 
            +
            	.set_dependency([runt])
         | 
| 333 | 
            +
            	.info
         | 
| 334 | 
            +
            	.compile
         | 
| 335 | 
            +
            	.archive_lib
         | 
| 336 | 
            +
             | 
| 337 | 
            +
            exp = MCBuild.new('../../../example')
         | 
| 338 | 
            +
            	.set_name("exp")
         | 
| 339 | 
            +
            	.set_dependency([runt, lmt])
         | 
| 340 | 
            +
            	.info
         | 
| 341 | 
            +
            	.compile
         | 
| 342 | 
            +
            	.archive_exe
         | 
| 343 | 
            +
            	.run
         | 
| 344 | 
            +
            =end
         | 
| 345 | 
            +
             | 
| 132 346 |  | 
| 133 347 |  | 
    
        metadata
    CHANGED
    
    | @@ -1,23 +1,23 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: mcbuild
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.12
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Sun Yuli
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2016- | 
| 11 | 
            +
            date: 2016-09-10 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies: []
         | 
| 13 | 
            -
            description:  | 
| 13 | 
            +
            description: 
         | 
| 14 14 | 
             
            email: sunpaq@gmail.com
         | 
| 15 15 | 
             
            executables: []
         | 
| 16 16 | 
             
            extensions: []
         | 
| 17 17 | 
             
            extra_rdoc_files: []
         | 
| 18 18 | 
             
            files:
         | 
| 19 19 | 
             
            - lib/mcbuild.rb
         | 
| 20 | 
            -
            homepage: https://github.com/sunpaq | 
| 20 | 
            +
            homepage: https://github.com/sunpaq
         | 
| 21 21 | 
             
            licenses:
         | 
| 22 22 | 
             
            - BSD
         | 
| 23 23 | 
             
            metadata: {}
         |