shithub: mc

Download patch

ref: 49c320b86e245a553ed87e679bcfc695e9315839
parent: a71988c710b2aaa5cf23fe1fedc52d3d7fc4b55d
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Dec 20 09:19:39 EST 2014

Remove code duplication.

    We were doing the same thing for binname and libname. Just
    use one codepath with a bool for the final target type.

--- a/main.myr
+++ b/main.myr
@@ -13,6 +13,8 @@
 const main = {args : byte[:][:]
 	var p : bld.parser#
 	var mt : bld.myrtarg
+	var targname
+	var bintarg
 	var optctx
 
 	optctx = std.optinit("hb:l:s:Sr:I:C:A:M:L:R:d", args)
@@ -20,12 +22,17 @@
 	while !std.optdone(optctx)
 		match std.optnext(optctx)
 		| ('h', arg): usage(args[0])
-		| ('b', arg): bld.opt_binname = arg
-		| ('l', arg): bld.opt_libname = arg
 		| ('s', arg): bld.opt_ldscript = arg
 		| ('f', arg): bld.opt_bldfile = arg
 		| ('I', arg): bld.opt_incpaths = std.slpush(bld.opt_incpaths, arg)
 		| ('S', _): bld.opt_genasm = true
+		| ('R', arg): bld.opt_instroot = arg
+		| ('b', arg):
+			targname = arg
+			bintarg = true
+		| ('l', arg):
+			targname = arg
+			bintarg = false
 		| ('r', arg):
 			if std.sleq(arg, "none")
 				bld.opt_runtime = ""
@@ -32,12 +39,11 @@
 			else
 				bld.opt_runtime = arg
 			;;
-		| ('R', arg): bld.opt_instroot = arg
-		| ('d', arg): bld.opt_debug = true
 		/*
 		internal undocumented args; used by compiler suite for
 		building with an uninstalled compiler.
 		*/
+		| ('d', arg): bld.opt_debug = true
 		| ('C', arg): bld.opt_mc = arg
 		| ('A', arg): bld.opt_as = arg
 		| ('M', arg): bld.opt_muse = arg
@@ -52,9 +58,9 @@
 	| `std.Fail f:	std.fatal(1, "Failed to compile use pattern regex\n")
 	;;
 
-	if bld.opt_binname.len != 0
+	if targname.len != 0
 		mt = [
-			.name=bld.opt_binname,
+			.name=targname,
 			.inputs=optctx.args,
 			.runtime=bld.opt_runtime,
 			.incpath=bld.opt_incpaths,
@@ -62,17 +68,11 @@
 			.libdeps=[][:]
 		]
 		p = std.zalloc()
-		bld.buildbin(p, &mt)
-		std.free(p)
-	elif bld.opt_libname.len != 0
-		mt = [
-			.name=bld.opt_libname,
-			.inputs=optctx.args,
-			.incpath=bld.opt_incpaths,
-			.libdeps=[][:]
-		]
-		p = std.zalloc()
-		bld.buildbin(p, &mt)
+		if bintarg
+			bld.buildbin(p, &mt)
+		else
+			bld.buildlib(p, &mt)
+		;;
 		std.free(p)
 	else
 		p = loadbuild(bld.opt_bldfile)
--- a/opts.myr
+++ b/opts.myr
@@ -6,8 +6,6 @@
 pkg bld =
 	var opt_arch 	: byte[:]
 	var opt_sys	: byte[:]
-	var opt_binname	: byte[:]
-	var opt_libname	: byte[:]
 	var opt_runtime	: byte[:]
 	var opt_genasm	: bool
 	var opt_ldscript	: byte[:]