use parent-dependencies for all dependencies of a package, not only those which are...
[openwrt/openwrt.git] / scripts / metadata.pl
index 7496f33a7d6723e1ca3080a7ec7ec7c3fd426f1f..1971607ebb6f0576a3e323079b63e76090d563ba 100755 (executable)
@@ -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-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;
@@ -162,6 +163,7 @@ sub target_config_features(@) {
                /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;
 }
@@ -325,6 +327,16 @@ EOF
        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) {
@@ -332,8 +344,10 @@ EOF
                next if $kver{$v};
                $kver{$v} = 1;
                print <<EOF;
+
 config LINUX_$v
        bool
+
 EOF
        }
        foreach my $def (sort keys %defaults) {
@@ -401,12 +415,12 @@ sub mconf_depends {
                $depend =~ s/^([@\+]+)//;
                my $flags = $1;
                my $vdep;
-               my $condition;
+               my $condition = $parent_condition;
 
                if ($depend =~ /^(.+):(.+)$/) {
                        if ($1 ne "PACKAGE_$pkgname") {
-                               if ($parent_condition) {
-                                       $condition = "$parent_condition && $1";
+                               if ($condition) {
+                                       $condition = "$condition && $1";
                                } else {
                                        $condition = $1;
                                }
@@ -538,6 +552,20 @@ 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;
@@ -569,6 +597,10 @@ sub gen_package_mk() {
                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 {
@@ -577,17 +609,60 @@ sub gen_package_mk() {
                                };
                        }
                }
+               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 %deplines;
                foreach my $deps (@srcdeps) {
                        my $idx;
                        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;
@@ -601,14 +676,15 @@ sub gen_package_mk() {
                        foreach my $dep (@deps) {
                                $pkg_dep = $package{$deps};
                                if (defined $pkg_dep->{src}) {
-                                       ($pkg->{src} ne $pkg_dep->{src}) and $idx = $pkg_dep->{subdir}.$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};
+                                       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;
@@ -620,15 +696,7 @@ sub gen_package_mk() {
                                                $depstr = "\$(curdir)/$idx/compile";
                                                $dep{$pkg->{src}."->".$idx} = 1;
                                        }
-                                       if ($condition) {
-                                               if ($condition =~ /^!(.+)/) {
-                                                       $depline = "\$(if \$(CONFIG_$1),,$depstr)";
-                                               } else {
-                                                       $depline = "\$(if \$(CONFIG_$condition),$depstr)";
-                                               }
-                                       } else {
-                                               $depline = $depstr;
-                                       }
+                                       $depline = get_conditional_dep($condition, $depstr);
                                        if ($depline) {
                                                $deplines{$idx.$dep} = $depline;
                                        }