2020-03-27 05:12:34 +03:00
|
|
|
|
#!/usr/bin/env nix-shell
|
|
|
|
|
#!nix-shell -p ruby -i ruby
|
|
|
|
|
|
|
|
|
|
require "shellwords"
|
|
|
|
|
ROOT = File.join(__dir__, "..")
|
|
|
|
|
|
|
|
|
|
def usage()
|
2020-10-10 03:26:03 +03:00
|
|
|
|
puts "Usage: bin/menuconfig [--only-save] <device_name>"
|
2020-03-27 05:12:34 +03:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Poor approximation to arguments parsing.
|
|
|
|
|
params, other_args = ARGV.partition { |s| s.match(/^--/) }
|
|
|
|
|
|
|
|
|
|
if other_args.empty?
|
|
|
|
|
$stderr.puts "Device name required."
|
|
|
|
|
usage
|
|
|
|
|
exit 1
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
DEVICE = other_args.shift
|
2020-06-08 10:33:25 +03:00
|
|
|
|
|
|
|
|
|
FILE =
|
|
|
|
|
# Is the device a path?
|
|
|
|
|
if DEVICE.match(%r{/})
|
|
|
|
|
Dir.glob(File.join(DEVICE, "kernel", "config.*")).sort.first
|
|
|
|
|
else
|
|
|
|
|
Dir.glob(File.join(Dir.pwd, "devices", DEVICE, "kernel", "config.*")).sort.first
|
|
|
|
|
end
|
2020-03-27 05:12:34 +03:00
|
|
|
|
|
|
|
|
|
ONLY_SAVE = !!params.delete("--only-save")
|
|
|
|
|
|
|
|
|
|
unless params.empty?
|
|
|
|
|
$stderr.puts "Unknown parameters #{params.join(", ")}."
|
|
|
|
|
usage
|
|
|
|
|
exit 1
|
|
|
|
|
end
|
2020-06-08 10:33:25 +03:00
|
|
|
|
|
2020-03-27 05:12:34 +03:00
|
|
|
|
unless other_args.empty?
|
|
|
|
|
$stderr.puts "Unexpected arguments #{other_args.join(", ")}."
|
|
|
|
|
usage
|
|
|
|
|
exit 1
|
|
|
|
|
end
|
2020-06-08 10:33:25 +03:00
|
|
|
|
|
|
|
|
|
unless FILE
|
2020-03-27 05:12:34 +03:00
|
|
|
|
$stderr.puts "Could not find kernel configuration file for #{DEVICE}."
|
|
|
|
|
usage
|
|
|
|
|
exit 1
|
|
|
|
|
end
|
|
|
|
|
|
2020-06-08 10:33:25 +03:00
|
|
|
|
arg =
|
|
|
|
|
# Is the device a path?
|
|
|
|
|
if DEVICE.match(%r{/})
|
|
|
|
|
["--arg", "device", DEVICE]
|
|
|
|
|
else
|
|
|
|
|
["--argstr", "device", DEVICE]
|
|
|
|
|
end
|
|
|
|
|
|
2020-03-27 05:12:34 +03:00
|
|
|
|
Dir.chdir(ROOT) do
|
|
|
|
|
tool = File.join(`#{[
|
|
|
|
|
"nix-build",
|
|
|
|
|
"--no-out-link",
|
2020-06-08 10:33:25 +03:00
|
|
|
|
*arg,
|
2020-05-26 18:51:43 +03:00
|
|
|
|
"-A", "config.mobile.boot.stage-1.kernel.package.menuconfig"
|
2020-03-27 05:12:34 +03:00
|
|
|
|
].shelljoin}`.strip, "bin/nconf")
|
|
|
|
|
|
|
|
|
|
if ONLY_SAVE
|
|
|
|
|
# Equivalent to F9,Enter
|
|
|
|
|
`echo -e "[20~\n" | #{[tool, FILE].shelljoin}`
|
|
|
|
|
else
|
|
|
|
|
system(tool, FILE)
|
|
|
|
|
end
|
2020-09-30 05:17:50 +03:00
|
|
|
|
|
|
|
|
|
# Force normalize at the end. Otherwise recent kernels (5.8+) will have the wrong compiler data.
|
|
|
|
|
exec(File.join(ROOT, "bin", "kernel-normalize-config"), *ARGV)
|
2020-03-27 05:12:34 +03:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# vim: ft=ruby
|