mips: fix another bug in the module relocation change: the wrong base address for...
[openwrt.git] / scripts / metadata.pl
index 6d75345..e8850c9 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
 use FindBin;
 use lib "$FindBin::Bin";
 use strict;
 use FindBin;
 use lib "$FindBin::Bin";
 use strict;
@@ -52,6 +52,7 @@ sub parse_target_metadata() {
                /^Target-Features:\s*(.+)\s*$/ and $target->{features} = [ split(/\s+/, $1) ];
                /^Target-Depends:\s*(.+)\s*$/ and $target->{depends} = [ split(/\s+/, $1) ];
                /^Target-Description:/ and $target->{desc} = get_multiline(*FILE);
                /^Target-Features:\s*(.+)\s*$/ and $target->{features} = [ split(/\s+/, $1) ];
                /^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;
                /^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;
@@ -152,7 +153,9 @@ sub target_config_features(@) {
        while ($_ = shift @_) {
                /broken/ and $ret .= "\tdepends BROKEN\n";
                /display/ and $ret .= "\tselect DISPLAY_SUPPORT\n";
        while ($_ = shift @_) {
                /broken/ and $ret .= "\tdepends BROKEN\n";
                /display/ and $ret .= "\tselect DISPLAY_SUPPORT\n";
+               /gpio/ and $ret .= "\tselect GPIO_SUPPORT\n";
                /pci/ and $ret .= "\tselect PCI_SUPPORT\n";
                /pci/ and $ret .= "\tselect PCI_SUPPORT\n";
+               /pcie/ and $ret .= "\tselect PCIE_SUPPORT\n";
                /usb/ and $ret .= "\tselect USB_SUPPORT\n";
                /pcmcia/ and $ret .= "\tselect PCMCIA_SUPPORT\n";
                /squashfs/ and $ret .= "\tselect USES_SQUASHFS\n";
                /usb/ and $ret .= "\tselect USB_SUPPORT\n";
                /pcmcia/ and $ret .= "\tselect PCMCIA_SUPPORT\n";
                /squashfs/ and $ret .= "\tselect USES_SQUASHFS\n";
@@ -160,6 +163,8 @@ sub target_config_features(@) {
                /ext2/ and $ret .= "\tselect USES_EXT2\n";
                /tgz/ and $ret .= "\tselect USES_TGZ\n";
                /cpiogz/ and $ret .= "\tselect USES_CPIOGZ\n";
                /ext2/ and $ret .= "\tselect USES_EXT2\n";
                /tgz/ and $ret .= "\tselect USES_TGZ\n";
                /cpiogz/ and $ret .= "\tselect USES_CPIOGZ\n";
+               /fpu/ and $ret .= "\tselect HAS_FPU\n";
+               /ramdisk/ and $ret .= "\tselect USES_INITRAMFS\n";
        }
        return $ret;
 }
        }
        return $ret;
 }
@@ -199,12 +204,20 @@ sub print_target($) {
        }
 
        my $v = kver($target->{version});
        }
 
        my $v = kver($target->{version});
+       if (@{$target->{subtargets}} == 0) {
        $confstr = <<EOF;
 config TARGET_$target->{conf}
        bool "$target->{name}"
        select LINUX_$kernel
        select LINUX_$v
 EOF
        $confstr = <<EOF;
 config TARGET_$target->{conf}
        bool "$target->{name}"
        select LINUX_$kernel
        select LINUX_$v
 EOF
+       }
+       else {
+               $confstr = <<EOF;
+config TARGET_$target->{conf}
+       bool "$target->{name}"
+EOF
+       }
        if ($target->{subtarget}) {
                $confstr .= "\tdepends TARGET_$target->{boardconf}\n";
        }
        if ($target->{subtarget}) {
                $confstr .= "\tdepends TARGET_$target->{boardconf}\n";
        }
@@ -221,6 +234,7 @@ EOF
                        $flags = $1;
                        $name = $2;
 
                        $flags = $1;
                        $name = $2;
 
+                       next if $name =~ /:/;
                        $flags =~ /-/ and $mode = "deselect";
                        $flags =~ /\+/ and $mode = "select";
                        $flags =~ /@/ and $confstr .= "\t$mode $name\n";
                        $flags =~ /-/ and $mode = "deselect";
                        $flags =~ /\+/ and $mode = "select";
                        $flags =~ /@/ and $confstr .= "\t$mode $name\n";
@@ -234,6 +248,7 @@ EOF
 
 sub gen_target_config() {
        my @target = parse_target_metadata();
 
 sub gen_target_config() {
        my @target = parse_target_metadata();
+       my %defaults;
 
        my @target_sort = sort {
                target_name($a) cmp target_name($b);
 
        my @target_sort = sort {
                target_name($a) cmp target_name($b);
@@ -287,8 +302,16 @@ EOF
                        my @pkglist = merge_package_lists($target->{packages}, $profile->{packages});
                        foreach my $pkg (@pkglist) {
                                print "\tselect DEFAULT_$pkg\n";
                        my @pkglist = merge_package_lists($target->{packages}, $profile->{packages});
                        foreach my $pkg (@pkglist) {
                                print "\tselect DEFAULT_$pkg\n";
+                               $defaults{$pkg} = 1;
                        }
                        }
-                       print "\n";
+                       my $help = $profile->{desc};
+                       if ($help =~ /\w+/) {
+                               $help =~ s/^\s*/\t  /mg;
+                               $help = "\thelp\n$help";
+                       } else {
+                               undef $help;
+                       }
+                       print "$help\n";
                }
        }
 
                }
        }
 
@@ -305,6 +328,16 @@ EOF
        foreach my $target (@target) {
                $target->{subtarget} or print "\t\tdefault \"".$target->{board}."\" if TARGET_".$target->{conf}."\n";
        }
        foreach my $target (@target) {
                $target->{subtarget} or print "\t\tdefault \"".$target->{board}."\" if TARGET_".$target->{conf}."\n";
        }
+       print <<EOF;
+
+config DEFAULT_TARGET_OPTIMIZATION
+       string
+EOF
+       foreach my $target (@target) {
+               next if @{$target->{subtargets}} > 0;
+               print "\tdefault \"".$target->{cflags}."\" if TARGET_".$target->{conf}."\n";
+       }
+       print "\tdefault \"-Os -pipe -funit-at-a-time\"\n";
 
        my %kver;
        foreach my $target (@target) {
 
        my %kver;
        foreach my $target (@target) {
@@ -312,10 +345,16 @@ EOF
                next if $kver{$v};
                $kver{$v} = 1;
                print <<EOF;
                next if $kver{$v};
                $kver{$v} = 1;
                print <<EOF;
+
 config LINUX_$v
        bool
 config LINUX_$v
        bool
+
 EOF
        }
 EOF
        }
+       foreach my $def (sort keys %defaults) {
+               print "\tconfig DEFAULT_".$def."\n";
+               print "\t\tbool\n\n";
+       }
 }
 
 my %dep_check;
 }
 
 my %dep_check;
@@ -359,12 +398,16 @@ sub package_depends($$) {
        return $ret;
 }
 
        return $ret;
 }
 
-sub mconf_depends($$) {
+sub mconf_depends {
+       my $pkgname = shift;
        my $depends = shift;
        my $only_dep = shift;
        my $res;
        my $dep = shift;
        my $depends = shift;
        my $only_dep = shift;
        my $res;
        my $dep = shift;
+       my $seen = shift;
+       my $parent_condition = shift;
        $dep or $dep = {};
        $dep or $dep = {};
+       $seen or $seen = {};
 
        $depends or return;
        my @depends = @$depends;
 
        $depends or return;
        my @depends = @$depends;
@@ -373,21 +416,42 @@ sub mconf_depends($$) {
                $depend =~ s/^([@\+]+)//;
                my $flags = $1;
                my $vdep;
                $depend =~ s/^([@\+]+)//;
                my $flags = $1;
                my $vdep;
-
+               my $condition = $parent_condition;
+
+               if ($depend =~ /^(.+):(.+)$/) {
+                       if ($1 ne "PACKAGE_$pkgname") {
+                               if ($condition) {
+                                       $condition = "$condition && $1";
+                               } else {
+                                       $condition = $1;
+                               }
+                       }
+                       $depend = $2;
+               }
+               next if $seen->{$depend};
+               next if $package{$depend} and $package{$depend}->{buildonly};
+               $seen->{$depend} = 1;
                if ($vdep = $package{$depend}->{vdepends}) {
                        $depend = join("||", map { "PACKAGE_".$_ } @$vdep);
                } else {
                        $flags =~ /\+/ and do {
                if ($vdep = $package{$depend}->{vdepends}) {
                        $depend = join("||", map { "PACKAGE_".$_ } @$vdep);
                } else {
                        $flags =~ /\+/ and do {
-                               next if $only_dep;
-                               $m = "select";
-
                                # Menuconfig will not treat 'select FOO' as a real dependency
                                # thus if FOO depends on other config options, these dependencies
                                # will not be checked. To fix this, we simply emit all of FOO's
                                # depends here as well.
                                # Menuconfig will not treat 'select FOO' as a real dependency
                                # thus if FOO depends on other config options, these dependencies
                                # will not be checked. To fix this, we simply emit all of FOO's
                                # depends here as well.
-                               $package{$depend} and mconf_depends($package{$depend}->{depends}, 1, $dep);
+                               $package{$depend} and mconf_depends($pkgname, $package{$depend}->{depends}, 1, $dep, $seen, $condition);
+
+                               $m = "select";
+                               next if $only_dep;
                        };
                        $flags =~ /@/ or $depend = "PACKAGE_$depend";
                        };
                        $flags =~ /@/ or $depend = "PACKAGE_$depend";
+                       if ($condition) {
+                               if ($m =~ /select/) {
+                                       $depend = "$depend if $condition";
+                               } else {
+                                       $depend = "!($condition) || $depend";
+                               }
+                       }
                }
                $dep->{$depend} =~ /select/ or $dep->{$depend} = $m;
        }
                }
                $dep->{$depend} =~ /select/ or $dep->{$depend} = $m;
        }
@@ -410,6 +474,7 @@ sub print_package_config_category($) {
 
        foreach my $spkg (sort {uc($a) cmp uc($b)} keys %spkg) {
                foreach my $pkg (@{$spkg{$spkg}}) {
 
        foreach my $spkg (sort {uc($a) cmp uc($b)} keys %spkg) {
                foreach my $pkg (@{$spkg{$spkg}}) {
+                       next if $pkg->{buildonly};
                        my $menu = $pkg->{submenu};
                        if ($menu) {
                                $menu_dep{$menu} or $menu_dep{$menu} = $pkg->{submenudep};
                        my $menu = $pkg->{submenu};
                        if ($menu) {
                                $menu_dep{$menu} or $menu_dep{$menu} = $pkg->{submenudep};
@@ -418,8 +483,6 @@ sub print_package_config_category($) {
                        }
                        $menus{$menu} or $menus{$menu} = [];
                        push @{$menus{$menu}}, $pkg;
                        }
                        $menus{$menu} or $menus{$menu} = [];
                        push @{$menus{$menu}}, $pkg;
-                       print "\tconfig DEFAULT_".$pkg->{name}."\n";
-                       print "\t\tbool\n\n";
                }
        }
        my @menus = sort {
                }
        }
        my @menus = sort {
@@ -451,7 +514,7 @@ sub print_package_config_category($) {
                        foreach my $default (split /\s*,\s*/, $pkg->{default}) {
                                print "\t\tdefault $default\n";
                        }
                        foreach my $default (split /\s*,\s*/, $pkg->{default}) {
                                print "\t\tdefault $default\n";
                        }
-                       print mconf_depends($pkg->{depends}, 0);
+                       print mconf_depends($pkg->{name}, $pkg->{depends}, 0);
                        print "\t\thelp\n";
                        print $pkg->{description};
                        print "\n";
                        print "\t\thelp\n";
                        print $pkg->{description};
                        print "\n";
@@ -470,7 +533,7 @@ sub print_package_config_category($) {
 
 sub gen_package_config() {
        parse_package_metadata($ARGV[0]) or exit 1;
 
 sub gen_package_config() {
        parse_package_metadata($ARGV[0]) or exit 1;
-       print "menuconfig UCI_PRECONFIG\n\tbool \"Image configuration\"\n";
+       print "menuconfig UCI_PRECONFIG\n\tbool \"Image configuration\"\n" if %preconfig;
        foreach my $preconfig (keys %preconfig) {
                foreach my $cfg (keys %{$preconfig{$preconfig}}) {
                        my $conf = $preconfig{$preconfig}->{$cfg}->{id};
        foreach my $preconfig (keys %preconfig) {
                foreach my $cfg (keys %{$preconfig{$preconfig}}) {
                        my $conf = $preconfig{$preconfig}->{$cfg}->{id};
@@ -490,17 +553,34 @@ EOF
        }
 }
 
        }
 }
 
+sub get_conditional_dep($$) {
+       my $condition = shift;
+       my $depstr = shift;
+       if ($condition) {
+               if ($condition =~ /^!(.+)/) {
+                       return "\$(if \$(CONFIG_$1),,$depstr)";
+               } else {
+                       return "\$(if \$(CONFIG_$condition),$depstr)";
+               }
+       } else {
+               return $depstr;
+       }
+}
+
 sub gen_package_mk() {
        my %conf;
        my %dep;
 sub gen_package_mk() {
        my %conf;
        my %dep;
+       my %done;
        my $line;
 
        parse_package_metadata($ARGV[0]) or exit 1;
        foreach my $name (sort {uc($a) cmp uc($b)} keys %package) {
                my $config;
                my $pkg = $package{$name};
        my $line;
 
        parse_package_metadata($ARGV[0]) or exit 1;
        foreach my $name (sort {uc($a) cmp uc($b)} keys %package) {
                my $config;
                my $pkg = $package{$name};
+               my @srcdeps;
 
                next if defined $pkg->{vdepends};
 
                next if defined $pkg->{vdepends};
+
                if ($ENV{SDK}) {
                        $conf{$pkg->{src}} or do {
                                $config = 'm';
                if ($ENV{SDK}) {
                        $conf{$pkg->{src}} or do {
                                $config = 'm';
@@ -510,31 +590,121 @@ sub gen_package_mk() {
                        $config = "\$(CONFIG_PACKAGE_$name)"
                }
                if ($config) {
                        $config = "\$(CONFIG_PACKAGE_$name)"
                }
                if ($config) {
+                       $pkg->{buildonly} and $config = "";
                        print "package-$config += $pkg->{subdir}$pkg->{src}\n";
                        $pkg->{prereq} and print "prereq-$config += $pkg->{subdir}$pkg->{src}\n";
                }
 
                        print "package-$config += $pkg->{subdir}$pkg->{src}\n";
                        $pkg->{prereq} and print "prereq-$config += $pkg->{subdir}$pkg->{src}\n";
                }
 
+               next if $done{$pkg->{src}};
+               $done{$pkg->{src}} = 1;
+
+               if (@{$pkg->{buildtypes}} > 0) {
+                       print "buildtypes-$pkg->{subdir}$pkg->{src} = ".join(' ', @{$pkg->{buildtypes}})."\n";
+               }
+
+               foreach my $spkg (@{$srcpackage{$pkg->{src}}}) {
+                       foreach my $dep (@{$spkg->{depends}}, @{$spkg->{builddepends}}) {
+                               $dep =~ /@/ or do {
+                                       $dep =~ s/\+//g;
+                                       push @srcdeps, $dep;
+                               };
+                       }
+               }
+               foreach my $type (@{$pkg->{buildtypes}}) {
+                       my @extra_deps;
+                       my %deplines;
+
+                       next unless $pkg->{"builddepends/$type"};
+                       foreach my $dep (@{$pkg->{"builddepends/$type"}}) {
+                               my $suffix = "";
+                               my $condition;
+
+                               if ($dep =~ /^(.+):(.+)/) {
+                                       $condition = $1;
+                                       $dep = $2;
+                               }
+                               if ($dep =~ /^(.+)(\/.+)/) {
+                                       $dep = $1;
+                                       $suffix = $2;
+                               }
+                               my $pkg_dep = $package{$dep};
+                               next unless $pkg_dep;
+
+                               my $idx = "";
+                               if (defined $pkg_dep->{src}) {
+                                       $idx = $pkg_dep->{subdir}.$pkg_dep->{src};
+                               } elsif (defined($srcpackage{$dep})) {
+                                       $idx = $subdir{$dep}.$dep;
+                               }
+                               my $depstr = "\$(curdir)/$idx$suffix/compile";
+                               my $depline = get_conditional_dep($condition, $depstr);
+                               if ($depline) {
+                                       $deplines{$dep} = $depline;
+                               }
+                       }
+                       my $depline = join(" ", values %deplines);
+                       if ($depline) {
+                               $line .= "\$(curdir)/".$pkg->{subdir}."$pkg->{src}/$type/compile += $depline\n";
+                       }
+               }
+
                my $hasdeps = 0;
                my $hasdeps = 0;
-               my $depline = "";
-               foreach my $dep (@{$pkg->{depends}}, @{$pkg->{builddepends}}) {
-                       next if $dep =~ /@/;
-                       $dep =~ s/\+//;
+               my %deplines;
+               foreach my $deps (@srcdeps) {
                        my $idx;
                        my $idx;
-                       my $pkg_dep = $package{$dep};
-                       next if defined $pkg_dep->{vdepends};
+                       my $condition;
+                       my $prefix = "";
+                       my $suffix = "";
+
+                       if ($deps =~ /^(.+):(.+)/) {
+                               $condition = $1;
+                               $deps = $2;
+                       }
+                       if ($deps =~ /^(.+)(\/.+)/) {
+                               $deps = $1;
+                               $suffix = $2;
+                       }
+
+                       my $pkg_dep = $package{$deps};
+                       my @deps;
 
 
-                       if (defined $pkg_dep->{src}) {
-                               ($pkg->{src} ne $pkg_dep->{src}) and $idx = $pkg_dep->{subdir}.$pkg_dep->{src};
-                       } elsif (defined($srcpackage{$dep})) {
-                               $idx = $subdir{$dep}.$dep;
+                       if ($pkg_dep->{vdepends}) {
+                               @deps = @{$pkg_dep->{vdepends}};
+                       } else {
+                               @deps = ($deps);
                        }
                        }
-                       undef $idx if $idx =~ /^(kernel)|(base-files)$/;
-                       if ($idx) {
-                               next if $dep{$pkg->{src}."->".$idx};
-                               $depline .= " \$(curdir)/$idx/compile";
-                               $dep{$pkg->{src}."->".$idx} = 1;
+
+                       foreach my $dep (@deps) {
+                               $pkg_dep = $package{$deps};
+                               if (defined $pkg_dep->{src}) {
+                                       ($pkg->{src} ne $pkg_dep->{src}.$suffix) and $idx = $pkg_dep->{subdir}.$pkg_dep->{src};
+                               } elsif (defined($srcpackage{$dep})) {
+                                       $idx = $subdir{$dep}.$dep;
+                               }
+                               $idx .= $suffix;
+                               undef $idx if $idx =~ /^(kernel)|(base-files)$/;
+                               if ($idx) {
+                                       my $depline;
+                                       next if $pkg->{src} eq $pkg_dep->{src}.$suffix;
+                                       next if $dep{$pkg->{src}."->".$idx};
+                                       next if $dep{$pkg->{src}."->($dep)".$idx} and $pkg_dep->{vdepends};
+                                       my $depstr;
+
+                                       if ($pkg_dep->{vdepends}) {
+                                               $depstr = "\$(if \$(CONFIG_PACKAGE_$dep),\$(curdir)/$idx/compile)";
+                                               $dep{$pkg->{src}."->($dep)".$idx} = 1;
+                                       } else {
+                                               $depstr = "\$(curdir)/$idx/compile";
+                                               $dep{$pkg->{src}."->".$idx} = 1;
+                                       }
+                                       $depline = get_conditional_dep($condition, $depstr);
+                                       if ($depline) {
+                                               $deplines{$idx.$dep} = $depline;
+                                       }
+                               }
                        }
                }
                        }
                }
+               my $depline = join(" ", values %deplines);
                if ($depline) {
                        $line .= "\$(curdir)/".$pkg->{subdir}."$pkg->{src}/compile += $depline\n";
                }
                if ($depline) {
                        $line .= "\$(curdir)/".$pkg->{subdir}."$pkg->{src}/compile += $depline\n";
                }
@@ -565,6 +735,16 @@ EOF
        }
 }
 
        }
 }
 
+sub gen_package_source() {
+       parse_package_metadata($ARGV[0]) or exit 1;
+       foreach my $name (sort {uc($a) cmp uc($b)} keys %package) {
+               my $pkg = $package{$name};
+               if ($pkg->{name} && $pkg->{source}) {
+                       print "$pkg->{name}: ";
+                       print "$pkg->{source}\n";
+               }
+       }
+}
 
 sub parse_command() {
        my $cmd = shift @ARGV;
 
 sub parse_command() {
        my $cmd = shift @ARGV;
@@ -573,13 +753,15 @@ sub parse_command() {
                /^package_mk$/ and return gen_package_mk();
                /^package_config$/ and return gen_package_config();
                /^kconfig/ and return gen_kconfig_overrides();
                /^package_mk$/ and return gen_package_mk();
                /^package_config$/ and return gen_package_config();
                /^kconfig/ and return gen_kconfig_overrides();
+               /^package_source$/ and return gen_package_source();
        }
        print <<EOF
 Available Commands:
        $0 target_config [file]         Target metadata in Kconfig format
        }
        print <<EOF
 Available Commands:
        $0 target_config [file]         Target metadata in Kconfig format
-       $0 package_mk [file]            Package metadata in makefile format
+       $0 package_mk [file]            Package metadata in makefile format
        $0 package_config [file]        Package metadata in Kconfig format
        $0 kconfig [file] [config]      Kernel config overrides
        $0 package_config [file]        Package metadata in Kconfig format
        $0 kconfig [file] [config]      Kernel config overrides
+       $0 package_source [file]        Package source file information
 
 EOF
 }
 
 EOF
 }
This page took 0.038677 seconds and 4 git commands to generate.