scripts/diffconfig.sh: ensure config/conf is built
[openwrt/openwrt.git] / scripts / package-metadata.pl
index 2dc29ea6ff3f0baae5464b527630f02fe1a76b00..6288584d65f58890bcdfa3f5d359c42672712ee6 100755 (executable)
@@ -191,9 +191,9 @@ sub mconf_depends {
                                $depend = shift @vdeps;
 
                                if (@vdeps > 1) {
-                                       $condition = ($condition ? "$condition && " : '') . '!('.join("||", map { "PACKAGE_".$_ } @vdeps).')';
+                                       $condition = ($condition ? "$condition && " : '') . join("&&", map { "PACKAGE_$_<PACKAGE_$pkgname" } @vdeps);
                                } elsif (@vdeps > 0) {
-                                       $condition = ($condition ? "$condition && " : '') . '!PACKAGE_'.$vdeps[0];
+                                       $condition = ($condition ? "$condition && " : '') . "PACKAGE_${vdeps[0]}<PACKAGE_$pkgname";
                                }
                        }
 
@@ -209,7 +209,7 @@ sub mconf_depends {
                        $flags =~ /@/ or $depend = "PACKAGE_$depend";
                } else {
                        my $vdep = $vpackage{$depend};
-                       if ($vdep) {
+                       if ($vdep && @$vdep > 0) {
                                $depend = join("||", map { "PACKAGE_".$_->{name} } @$vdep);
                        } else {
                                $flags =~ /@/ or $depend = "PACKAGE_$depend";
@@ -337,31 +337,6 @@ sub print_package_config_category($) {
        undef $category{$cat};
 }
 
-sub print_package_features() {
-       keys %features > 0 or return;
-       print "menu \"Package features\"\n";
-       foreach my $n (keys %features) {
-               my @features = sort { $b->{priority} <=> $a->{priority} or $a->{title} cmp $b->{title} } @{$features{$n}};
-               print <<EOF;
-choice
-       prompt "$features[0]->{target_title}"
-       default FEATURE_$features[0]->{name}
-EOF
-
-               foreach my $feature (@features) {
-                       print <<EOF;
-       config FEATURE_$feature->{name}
-               bool "$feature->{title}"
-EOF
-                       $feature->{description} =~ /\w/ and do {
-                               print "\t\thelp\n".$feature->{description}."\n";
-                       };
-               }
-               print "endchoice\n"
-       }
-       print "endmenu\n\n";
-}
-
 sub print_package_overrides() {
        keys %overrides > 0 or return;
        print "\tconfig OVERRIDE_PKGS\n";
@@ -376,7 +351,6 @@ sub gen_package_config() {
        if (scalar glob "package/feeds/*/*/image-config.in") {
            print "source \"package/feeds/*/*/image-config.in\"\n";
        }
-       print_package_features();
        print_package_config_category 'Base system';
        foreach my $cat (sort {uc($a) cmp uc($b)} keys %category) {
                print_package_config_category $cat;
@@ -384,14 +358,30 @@ sub gen_package_config() {
        print_package_overrides();
 }
 
+sub and_condition($) {
+       my $condition = shift;
+       my @spl_and = split('\&\&', $condition);
+       if (@spl_and == 1) {
+               return "\$(CONFIG_$spl_and[0])";
+       }
+       return "\$(and " . join (',', map("\$(CONFIG_$_)", @spl_and)) . ")";
+}
+
+sub gen_condition ($) {
+       my $condition = shift;
+       # remove '!()', just as include/package-ipkg.mk does
+       $condition =~ s/[()!]//g;
+       return join("", map(and_condition($_), split('\|\|', $condition)));
+}
+
 sub get_conditional_dep($$) {
        my $condition = shift;
        my $depstr = shift;
        if ($condition) {
                if ($condition =~ /^!(.+)/) {
-                       return "\$(if \$(CONFIG_$1),,$depstr)";
+                       return "\$(if " . gen_condition($1) . ",,$depstr)";
                } else {
-                       return "\$(if \$(CONFIG_$condition),$depstr)";
+                       return "\$(if " . gen_condition($condition) . ",$depstr)";
                }
        } else {
                return $depstr;
@@ -430,9 +420,9 @@ sub gen_package_mk() {
                                my @vdeps = grep { $srcname ne $_->{src}{name} } @{$vpkg_dep};
 
                                foreach my $vdep (@vdeps) {
-                                       my $depstr = "\$(curdir)/$vdep->{src}{path}/compile";
+                                       my $depstr = sprintf '$(curdir)/%s/compile', $vdep->{src}{path};
                                        if (@vdeps > 1) {
-                                               $depstr = "\$(if \$(CONFIG_PACKAGE_$vdep->{name}),$depstr)";
+                                               $depstr = sprintf '$(if $(CONFIG_PACKAGE_%s),%s)', $vdep->{name}, $depstr;
                                        }
                                        my $depline = get_conditional_dep($condition, $depstr);
                                        if ($depline) {
@@ -442,32 +432,32 @@ sub gen_package_mk() {
                        }
 
                        my $config = '';
-                       $config = "\$(CONFIG_PACKAGE_$pkg->{name})" unless $pkg->{buildonly};
+                       $config = sprintf '$(CONFIG_PACKAGE_%s)', $pkg->{name} unless $pkg->{buildonly};
 
-                       $pkg->{prereq} and print "prereq-$config += $src->{path}\n";
+                       $pkg->{prereq} and printf "prereq-%s += %s\n", $config, $src->{path};
 
                        next if $pkg->{buildonly};
 
-                       print "package-$config += $src->{path}\n";
+                       printf "package-%s += %s\n", $config, $src->{path};
 
                        if ($pkg->{variant}) {
                                if (!defined($variant_default) or $pkg->{variant_default}) {
                                        $variant_default = $pkg->{variant};
                                }
-                               print "\$(curdir)/$src->{path}/variants += \$(if $config,$pkg->{variant})\n";
+                               printf "\$(curdir)/%s/variants += \$(if %s,%s)\n", $src->{path}, $config, $pkg->{variant};
                        }
                }
 
                if (defined($variant_default)) {
-                       print "\$(curdir)/$src->{path}/default-variant := $variant_default\n";
+                       printf "\$(curdir)/%s/default-variant := %s\n", $src->{path}, $variant_default;
                }
 
                unless (grep {!$_->{buildonly}} @{$src->{packages}}) {
-                       print "package- += $src->{path}\n";
+                       printf "package- += %s\n", $src->{path};
                }
 
                if (@{$src->{buildtypes}} > 0) {
-                       print "buildtypes-$src->{path} = ".join(' ', @{$src->{buildtypes}})."\n";
+                       printf "buildtypes-%s = %s\n", $src->{path}, join(' ', @{$src->{buildtypes}});
                }
 
                foreach my $type ('', @{$src->{buildtypes}}) {
@@ -498,12 +488,12 @@ sub gen_package_mk() {
 
                                my $src_dep = $srcpackage{$dep};
                                unless (defined($src_dep) && (!$deptype || grep { $_ eq $deptype } @{$src_dep->{buildtypes}})) {
-                                       warn sprintf "WARNING: Makefile '%s' has a build dependency on '%s%s', which does not exist\n",
-                                               $src->{makefile}, $dep$depsuffix;
+                                       warn sprintf "WARNING: Makefile '%s' has a build dependency on '%s', which does not exist\n",
+                                               $src->{makefile}, $dep.$depsuffix;
                                        next;
                                }
 
-                               my $depstr = "\$(curdir)/$src_dep->{path}$depsuffix/compile";
+                               my $depstr = sprintf '$(curdir)/%s/compile', $src_dep->{path}.$depsuffix;
                                my $depline = get_conditional_dep($condition, $depstr);
                                if ($depline) {
                                        $deplines{$suffix}{$depline}++;
@@ -514,7 +504,7 @@ sub gen_package_mk() {
                foreach my $suffix (sort keys %deplines) {
                        my $depline = join(" ", sort keys %{$deplines{$suffix}});
                        if ($depline) {
-                               $line .= "\$(curdir)/$src->{path}$suffix/compile += $depline\n";
+                               $line .= sprintf "\$(curdir)/%s/compile += %s\n", $src->{path}.$suffix, $depline;
                        }
                }
        }
@@ -535,13 +525,25 @@ sub gen_package_source() {
        }
 }
 
-sub gen_package_subdirs() {
+sub gen_package_auxiliary() {
        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->{repository}) {
                        print "Package/$name/subdir = $pkg->{repository}\n";
                }
+               my %depends;
+               foreach my $dep (@{$pkg->{depends} || []}) {
+                       if ($dep =~ m!^\+?(?:[^:]+:)?([^@]+)$!) {
+                               $depends{$1}++;
+                       }
+               }
+               my @depends = sort keys %depends;
+               if (@depends > 0) {
+                       foreach my $n (@{$pkg->{provides}}) {
+                               print "Package/$n/depends = @depends\n";
+                       }
+               }
        }
 }
 
@@ -583,6 +585,40 @@ sub gen_usergroup_list() {
        }
 }
 
+sub gen_package_manifest_json() {
+       my $json;
+       parse_package_metadata($ARGV[0]) or exit 1;
+       foreach my $name (sort {uc($a) cmp uc($b)} keys %package) {
+               my %depends;
+               my $pkg = $package{$name};
+               foreach my $dep (@{$pkg->{depends} || []}) {
+                       if ($dep =~ m!^\+?(?:[^:]+:)?([^@]+)$!) {
+                               $depends{$1}++;
+                       }
+               }
+               my @depends = sort keys %depends;
+               my $pkg_deps = join ' ', map { qq/"$_",/ } @depends;
+               $pkg_deps =~ s/\,$//;
+
+               my $pkg_maintainer = join ' ', map { qq/"$_",/ } @{$pkg->{maintainer} || []};
+               $pkg_maintainer =~ s/\,$//;
+
+               $json = <<"END_JSON";
+${json}{
+"name":"$name",
+"version":"$pkg->{version}",
+"category":"$pkg->{category}",
+"license":"$pkg->{license}",
+"maintainer": [$pkg_maintainer],
+"depends":[$pkg_deps]},
+END_JSON
+       }
+
+       $json =~ s/[\n\r]//g;
+       $json =~ s/\,$//;
+       print "[$json]";
+}
+
 sub parse_command() {
        GetOptions("ignore=s", \@ignore);
        my $cmd = shift @ARGV;
@@ -591,7 +627,8 @@ sub parse_command() {
                /^config$/ and return gen_package_config();
                /^kconfig/ and return gen_kconfig_overrides();
                /^source$/ and return gen_package_source();
-               /^subdirs$/ and return gen_package_subdirs();
+               /^pkgaux$/ and return gen_package_auxiliary();
+               /^pkgmanifestjson$/ and return gen_package_manifest_json();
                /^license$/ and return gen_package_license(0);
                /^licensefull$/ and return gen_package_license(1);
                /^usergroup$/ and return gen_usergroup_list();
@@ -603,7 +640,8 @@ Available Commands:
        $0 config [file]                        Package metadata in Kconfig format
        $0 kconfig [file] [config] [patchver]   Kernel config overrides
        $0 source [file]                        Package source file information
-       $0 subdirs [file]                       Package subdir information in makefile format
+       $0 pkgaux [file]                        Package auxiliary variables in makefile format
+       $0 pkgmanifestjson [file]               Package manifests in JSON format
        $0 license [file]                       Package license information
        $0 licensefull [file]                   Package license information (full list)
        $0 usergroup [file]                     Package usergroup allocation list