Move kernel sources to platform specific subdirs
diff --git a/share/jmk/jmk.tcl b/share/jmk/jmk.tcl
index b3b860c..64b9afd 100644
--- a/share/jmk/jmk.tcl
+++ b/share/jmk/jmk.tcl
@@ -7,6 +7,8 @@
 variable jmk_lib_paths
 variable jmk_lib_targets
 
+variable jmk_sourced
+
 variable cflags {}
 variable asmflags {}
 variable ldflags {}
@@ -98,6 +100,15 @@
 	puts "\t@printf ' \\e\[1;34m%8s\\e\[m  %s\\n' '$category' '$message' > /dev/stderr"
 }
 
+proc jmk_log {message} {
+	puts stderr $message
+}
+
+proc jmk_error {message} {
+	puts stderr "\e[31mError\e[0m $message"
+	exit 1
+}
+
 proc cc {command} {
 	puts "\t@$::cc $command $::cflags"
 }
@@ -132,9 +143,9 @@
 
 proc srcs {args} {
 	puts ""
-	variable objs ""
 
 	foreach src $args {
+		set src [file join [pwd] $src]
 		variable obj [regsub -- {(.+)\.\w+} $src {\1.o}]
 		set ::objs "$::objs $obj"
 	}
@@ -233,3 +244,21 @@
 		set asm nasm
 	}
 }
+
+proc jmk_source {path} {
+	variable dir [pwd]
+
+	if {![file exists $path]} {
+		jmk_error "jmk_source: $dir/$path doesn't exist"
+	}
+
+	lappend ::jmk_sourced "$dir/$path"
+
+	cd [file dirname $path]
+	uplevel 1 source [file tail $path]
+	cd $dir
+}
+
+proc jmk_finalize {} {
+	puts "Jmk2: $::jmk_sourced"
+}
diff --git a/share/jmk/multiplat.jmk b/share/jmk/multiplat.jmk
new file mode 100644
index 0000000..0638d8d
--- /dev/null
+++ b/share/jmk/multiplat.jmk
@@ -0,0 +1,53 @@
+# -*- tcl -*-
+
+variable isas
+variable devices
+
+variable isa_features
+
+proc isa {name} {
+	lappend ::isas $name
+}
+
+proc device {name isa} {
+	lappend ::devices($isa) $name
+}
+
+proc target_feature {feature} {
+	lappend ::isa_features $feature
+}
+
+proc target_features {args} {
+	lappend ::isa_features {*}$args
+}
+
+proc feature_supported {feature} {
+	return [expr {[lsearch -exact $::isa_features $feature] != -1}]
+}
+
+option ISA x86_32
+option DEVICE pc-generic
+
+proc source_if_exists {path} {
+	if {[file exists $path]} {
+		uplevel 1 jmk_source $path
+	}
+}
+
+proc enable_multiplat {} {
+	uplevel 1 source_if_exists "$::root/etc/platforms/platforms.jmk"
+
+	if {[lsearch -exact $::isas $::options(ISA)] == -1} {
+		jmk_error "Specified ISA $::options(ISA) is invalid, choose one of $::isas"
+	}
+
+	if {[lsearch -exact $::devices($::options(ISA)) $::options(DEVICE)] == -1} {
+		jmk_error "Specified DEVICE $::options(DEVICE) is invalid, choose one of $::devices($::options(ISA))"
+	}
+
+	uplevel 1 source_if_exists "$::root/etc/platforms/$::options(ISA)/$::options(DEVICE).jmk"
+	uplevel 1 source_if_exists "$::root/etc/platforms/$::options(ISA)/$::options(ISA).jmk"
+
+	uplevel 1 source_if_exists "$::options(ISA)/$::options(DEVICE).jmk"
+	uplevel 1 source_if_exists "$::options(ISA)/$::options(ISA).jmk"
+}