X-Git-Url: https://git.rohieb.name/openwrt.git/blobdiff_plain/f08be3e501d20838b7467f26a86dfc40ee9efcae..1d9a77e99ff3a8af45a328309b9bccbb408ea8c4:/scripts/metadata.pl diff --git a/scripts/metadata.pl b/scripts/metadata.pl index 03041f97c..41e6e9cd5 100755 --- a/scripts/metadata.pl +++ b/scripts/metadata.pl @@ -1,23 +1,10 @@ -#!/usr/bin/perl +#!/usr/bin/env perl +use FindBin; +use lib "$FindBin::Bin"; use strict; -my %preconfig; -my %package; -my %srcpackage; -my %category; -my %subdir; -my %board; - -sub get_multiline { - my $prefix = shift; - my $str; - while (<>) { - last if /^@@/; - s/^\s*//g; - $str .= (($_ and $prefix) ? $prefix . $_ : $_); - } +use metadata; - return $str; -} +my %board; sub confstr($) { my $conf = shift; @@ -26,30 +13,50 @@ sub confstr($) { } sub parse_target_metadata() { - my ($target, @target, $profile); - while (<>) { + my $file = shift @ARGV; + my ($target, @target, $profile); + my %target; + + open FILE, "<$file" or do { + warn "Can't open file '$file': $!\n"; + return; + }; + while () { chomp; /^Target:\s*(.+)\s*$/ and do { + my $name = $1; $target = { - id => $1, - conf => confstr($1), - profiles => [] + id => $name, + board => $name, + boardconf => confstr($name), + conf => confstr($name), + profiles => [], + features => [], + depends => [], + subtargets => [] }; push @target, $target; + $target{$name} = $target; + if ($name =~ /([^\/]+)\/([^\/]+)/) { + push @{$target{$1}->{subtargets}}, $2; + $target->{board} = $1; + $target->{boardconf} = confstr($1); + $target->{subtarget} = 1; + $target->{parent} = $target{$1}; + } }; - /^Target-Board:\s*(.+)\s*$/ and do { - $target->{board} = $1; - $target->{boardconf} = confstr($1); - }; - /^Target-Kernel:\s*(\d+\.\d+)\s*$/ and $target->{kernel} = $1; /^Target-Name:\s*(.+)\s*$/ and $target->{name} = $1; /^Target-Path:\s*(.+)\s*$/ and $target->{path} = $1; /^Target-Arch:\s*(.+)\s*$/ and $target->{arch} = $1; + /^Target-Arch-Packages:\s*(.+)\s*$/ and $target->{arch_packages} = $1; /^Target-Features:\s*(.+)\s*$/ and $target->{features} = [ split(/\s+/, $1) ]; - /^Target-Description:/ and $target->{desc} = get_multiline(); + /^Target-Depends:\s*(.+)\s*$/ and $target->{depends} = [ split(/\s+/, $1) ]; + /^Target-Description:/ and $target->{desc} = get_multiline(*FILE); + /^Target-Optimization:\s*(.+)\s*$/ and $target->{cflags} = $1; /^Linux-Version:\s*(.+)\s*$/ and $target->{version} = $1; /^Linux-Release:\s*(.+)\s*$/ and $target->{release} = $1; /^Linux-Kernel-Arch:\s*(.+)\s*$/ and $target->{karch} = $1; + /^Default-Subtarget:\s*(.+)\s*$/ and $target->{def_subtarget} = $1; /^Default-Packages:\s*(.+)\s*$/ and $target->{packages} = [ split(/\s+/, $1) ]; /^Target-Profile:\s*(.+)\s*$/ and do { $profile = { @@ -61,11 +68,13 @@ sub parse_target_metadata() { }; /^Target-Profile-Name:\s*(.+)\s*$/ and $profile->{name} = $1; /^Target-Profile-Packages:\s*(.*)\s*$/ and $profile->{packages} = [ split(/\s+/, $1) ]; - /^Target-Profile-Description:\s*(.*)\s*/ and $profile->{desc} = get_multiline(); - /^Target-Profile-Config:/ and $profile->{config} = get_multiline("\t"); + /^Target-Profile-Description:\s*(.*)\s*/ and $profile->{desc} = get_multiline(*FILE); + /^Target-Profile-Config:/ and $profile->{config} = get_multiline(*FILE, "\t"); /^Target-Profile-Kconfig:/ and $profile->{kconfig} = 1; } + close FILE; foreach my $target (@target) { + next if @{$target->{subtargets}} > 0; @{$target->{profiles}} > 0 or $target->{profiles} = [ { id => 'Default', @@ -77,78 +86,6 @@ sub parse_target_metadata() { return @target; } -sub parse_package_metadata() { - my $pkg; - my $makefile; - my $preconfig; - my $subdir; - my $src; - while (<>) { - chomp; - /^Source-Makefile: \s*((.+\/)([^\/]+)\/Makefile)\s*$/ and do { - $makefile = $1; - $subdir = $2; - $src = $3; - $subdir =~ s/^package\///; - $subdir{$src} = $subdir; - $srcpackage{$src} = []; - undef $pkg; - }; - /^Package:\s*(.+?)\s*$/ and do { - $pkg = {}; - $pkg->{src} = $src; - $pkg->{makefile} = $makefile; - $pkg->{name} = $1; - $pkg->{default} = "m if ALL"; - $pkg->{depends} = []; - $pkg->{builddepends} = []; - $pkg->{subdir} = $subdir; - $package{$1} = $pkg; - push @{$srcpackage{$src}}, $pkg; - }; - /^Version: \s*(.+)\s*$/ and $pkg->{version} = $1; - /^Title: \s*(.+)\s*$/ and $pkg->{title} = $1; - /^Menu: \s*(.+)\s*$/ and $pkg->{menu} = $1; - /^Submenu: \s*(.+)\s*$/ and $pkg->{submenu} = $1; - /^Submenu-Depends: \s*(.+)\s*$/ and $pkg->{submenudep} = $1; - /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1; - /^Provides: \s*(.+)\s*$/ and do { - my @vpkg = split /\s+/, $1; - foreach my $vpkg (@vpkg) { - $package{$vpkg} or $package{$vpkg} = { vdepends => [] }; - push @{$package{$vpkg}->{vdepends}}, $pkg->{name}; - } - }; - /^Depends: \s*(.+)\s*$/ and $pkg->{depends} = [ split /\s+/, $1 ]; - /^Build-Depends: \s*(.+)\s*$/ and $pkg->{builddepends} = [ split /\s+/, $1 ]; - /^Category: \s*(.+)\s*$/ and do { - $pkg->{category} = $1; - defined $category{$1} or $category{$1} = {}; - defined $category{$1}->{$src} or $category{$1}->{$src} = []; - push @{$category{$1}->{$src}}, $pkg; - }; - /^Description: \s*(.*)\s*$/ and $pkg->{description} = "\t\t $1\n". get_multiline("\t\t "); - /^Config: \s*(.*)\s*$/ and $pkg->{config} = "$1\n".get_multiline(); - /^Prereq-Check:/ and $pkg->{prereq} = 1; - /^Preconfig:\s*(.+)\s*$/ and do { - my $pkgname = $pkg->{name}; - $preconfig{$pkgname} or $preconfig{$pkgname} = {}; - if (exists $preconfig{$pkgname}->{$1}) { - $preconfig = $preconfig{$pkgname}->{$1}; - } else { - $preconfig = { - id => $1 - }; - $preconfig{$pkgname}->{$1} = $preconfig; - } - }; - /^Preconfig-Type:\s*(.*?)\s*$/ and $preconfig->{type} = $1; - /^Preconfig-Label:\s*(.*?)\s*$/ and $preconfig->{label} = $1; - /^Preconfig-Default:\s*(.*?)\s*$/ and $preconfig->{default} = $1; - } - return %category; -} - sub gen_kconfig_overrides() { my %config; my %kconfig; @@ -216,89 +153,162 @@ sub target_config_features(@) { while ($_ = shift @_) { /broken/ and $ret .= "\tdepends BROKEN\n"; + /audio/ and $ret .= "\tselect AUDIO_SUPPORT\n"; + /display/ and $ret .= "\tselect DISPLAY_SUPPORT\n"; + /gpio/ and $ret .= "\tselect GPIO_SUPPORT\n"; /pci/ and $ret .= "\tselect PCI_SUPPORT\n"; + /pcie/ and $ret .= "\tselect PCIE_SUPPORT\n"; /usb/ and $ret .= "\tselect USB_SUPPORT\n"; + /usbgadget/ and $ret .= "\tselect USB_GADGET_SUPPORT\n"; /pcmcia/ and $ret .= "\tselect PCMCIA_SUPPORT\n"; /squashfs/ and $ret .= "\tselect USES_SQUASHFS\n"; /jffs2/ and $ret .= "\tselect USES_JFFS2\n"; - /ext2/ and $ret .= "\tselect USES_EXT2\n"; - /tgz/ and $ret .= "\tselect USES_TGZ\n"; + /ext4/ and $ret .= "\tselect USES_EXT4\n"; + /targz/ and $ret .= "\tselect USES_TARGZ\n"; + /cpiogz/ and $ret .= "\tselect USES_CPIOGZ\n"; + /ubifs/ and $ret .= "\tselect USES_UBIFS\n"; + /fpu/ and $ret .= "\tselect HAS_FPU\n"; + /spe_fpu/ and $ret .= "\tselect HAS_SPE_FPU\n"; + /ramdisk/ and $ret .= "\tselect USES_INITRAMFS\n"; + /powerpc64/ and $ret .= "\tselect powerpc64\n"; + /nommu/ and $ret .= "\tselect NOMMU\n"; } return $ret; } +sub target_name($) { + my $target = shift; + my $parent = $target->{parent}; + if ($parent) { + return $target->{parent}->{name}." - ".$target->{name}; + } else { + return $target->{name}; + } +} + +sub kver($) { + my $v = shift; + $v =~ tr/\./_/; + if (substr($v,0,2) eq "2_") { + $v =~ /(\d+_\d+_\d+)(_\d+)?/ and $v = $1; + } else { + $v =~ /(\d+_\d+)(_\d+)?/ and $v = $1; + } + return $v; +} + +sub print_target($) { + my $target = shift; + my $features = target_config_features(@{$target->{features}}); + my $help = $target->{desc}; + my $confstr; + + chomp $features; + $features .= "\n"; + if ($help =~ /\w+/) { + $help =~ s/^\s*/\t /mg; + $help = "\thelp\n$help"; + } else { + undef $help; + } + + my $v = kver($target->{version}); + if (@{$target->{subtargets}} == 0) { + $confstr = <{conf} + bool "$target->{name}" + select LINUX_$v +EOF + } + else { + $confstr = <{conf} + bool "$target->{name}" +EOF + } + if ($target->{subtarget}) { + $confstr .= "\tdepends TARGET_$target->{boardconf}\n"; + } + if (@{$target->{subtargets}} > 0) { + $confstr .= "\tselect HAS_SUBTARGETS\n"; + } else { + $confstr .= $features; + } + + if ($target->{arch} =~ /\w/) { + $confstr .= "\tselect $target->{arch}\n"; + } + foreach my $dep (@{$target->{depends}}) { + my $mode = "depends"; + my $flags; + my $name; + + $dep =~ /^([@\+\-]+)(.+)$/; + $flags = $1; + $name = $2; + + next if $name =~ /:/; + $flags =~ /-/ and $mode = "deselect"; + $flags =~ /\+/ and $mode = "select"; + $flags =~ /@/ and $confstr .= "\t$mode $name\n"; + } + $confstr .= "$help\n\n"; + print $confstr; +} sub gen_target_config() { my @target = parse_target_metadata(); + my %defaults; - @target = sort { - $a->{name} cmp $b->{name} + my @target_sort = sort { + target_name($a) cmp target_name($b); } @target; - - + + print <{features}}); - my $help = $target->{desc}; - my $kernel = $target->{kernel}; - $kernel =~ tr/./_/; - - chomp $features; - $features .= "\n"; - if ($help =~ /\w+/) { - $help =~ s/^\s*/\t /mg; - $help = "\thelp\n$help"; - } else { - undef $help; - } - - print <{conf} - bool "$target->{name}" - select $target->{arch} - select LINUX_$kernel -EOF - if ($target->{id} ne $target->{board}) { - print "\tselect TARGET_".$target->{boardconf}."\n"; - } - print "$features$help\n\n" + foreach my $target (@target_sort) { + next if $target->{subtarget}; + print_target($target); } print <{board}."\" if TARGET_".$target->{conf}."\n"; + next unless $target->{def_subtarget}; + print <{conf}_$target->{def_subtarget} if TARGET_$target->{conf} +EOF } + print <