--- build-20150115.orig/.gbp.conf
+++ build-20150115/.gbp.conf
@@ -0,0 +1,15 @@
+[DEFAULT]
+upstream-tag = upstream/%(version)s
+patch-export = True
+patch-export-ignore-path = (.gbp.conf|.gbs.conf|packaging/.*|debian/.*|.gitignore)
+packaging-dir = packaging
+#packaging-tag = tizen/%(upstreamversion)s-%(nowtime)s
+
+[git-buildpackage]
+upstream-tag = upstream/%(version)s
+
+[git-dch]
+upstream-tag = upstream/%(version)s
+
+[gbp-pq-rpm]
+pq-branch = patch-queue/%(branch)s
--- build-20150115.orig/createrepomddeps
+++ build-20150115/createrepomddeps
@@ -33,6 +33,8 @@
 use Digest::MD5 ();
 use File::Path qw(mkpath rmtree);
 use File::Basename;
+use IPC::SysV qw(IPC_PRIVATE S_IRUSR S_IWUSR IPC_CREAT IPC_EXCL SEM_UNDO);
+use IPC::Semaphore;
 
 Getopt::Long::Configure("no_ignore_case");
 
@@ -87,7 +89,20 @@
     $dir = "$cachedir/$repoid/";
     $baseurl .= '/' unless $baseurl =~ /\/$/;
     mkpath("${dir}repodata");
-    system($INC[0].'/download', "${dir}repodata", "${baseurl}repodata/repomd.xml");
+    my $sem;
+    my $key = IPC::SysV::ftok($dir, '1');
+    if ($sem = IPC::Semaphore->new($key, 1, S_IRUSR | S_IWUSR | IPC_CREAT | IPC_EXCL)) {
+      $sem->setval(0, 1);
+    } else {
+      $sem = IPC::Semaphore->new($key, 1, S_IRUSR | S_IWUSR | IPC_CREAT);
+    }
+
+    $sem->op(0, -1, SEM_UNDO);
+    if (!-f "${dir}repodata/repomd.xml") {
+      system($INC[0].'/download', "${dir}repodata", "${baseurl}repodata/repomd.xml");
+    }
+    $sem->op(0, 1, SEM_UNDO);
+    $sem->remove();
   } else {
     $dir = $url;
   }
@@ -111,6 +126,14 @@
       utf8::downgrade($u);
     }
     my $cached;
+    my $sem;
+    my $key = IPC::SysV::ftok("${dir}repodata/", '1');
+    if ($sem = IPC::Semaphore->new($key, 1, S_IRUSR | S_IWUSR | IPC_CREAT | IPC_EXCL)) {
+      $sem->setval(0, 1);
+    } else {
+      $sem = IPC::Semaphore->new($key, 1, S_IRUSR | S_IWUSR | IPC_CREAT);
+    }
+    $sem->op(0, -1, SEM_UNDO);
     if (-e $u) {
       $cached = 1;
       $cached = 0 if exists($f->{'size'}) && $f->{'size'} != (-s _);
@@ -126,6 +149,9 @@
 	die("inconsistent repodata in $url\n");
       }
     }
+    $sem->op(0, 1, SEM_UNDO);
+    $sem->remove();
+
     my $fh;
     open($fh, '<', $u) or die "Error opening $u: $!\n";
     if ($u =~ /\.gz$/) {
--- build-20150115.orig/qemu-reg
+++ build-20150115/qemu-reg
@@ -4,7 +4,7 @@
 
 # NOTE: this requires a qemu with the binfmt misc handler binary
 
-:aarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-aarch64-binfmt:P
+#:aarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-aarch64-binfmt:P
 :aarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-arm64-binfmt:P
 :arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfa\xff\xff\xff:/usr/bin/qemu-arm-static:
 :armeb:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-armeb-binfmt:P
--- build-20150115.orig/expanddeps
+++ build-20150115/expanddeps
@@ -29,7 +29,7 @@
 use Build;
 use File::Basename;
 
-my ($dist, $rpmdeps, $archs, $configdir, $useusedforbuild, $installonly, $noinstall);
+my ($dist, $rpmdeps, $archs, $configdir, $useusedforbuild, $installonly, $noinstall, $usehigherdeps, $isvm);
 
 $configdir = ($::ENV{'BUILD_DIR'} || '/usr/lib/build') . '/configs';
 
@@ -77,6 +77,16 @@
     Build::define("_without_$def --without-$def");
     next;
   }
+  if ($ARGV[0] eq '--usehigherdeps') {
+    shift @ARGV;
+    $usehigherdeps = 1;
+    next;
+  }
+  if ($ARGV[0] eq '--vm') {
+    shift @ARGV;
+    $isvm = 1;
+    next;
+  }
   last;
 }
 
@@ -116,7 +126,7 @@
   $binarytype = $cf->{'binarytype'} if $cf->{'binarytype'} && $cf->{'binarytype'} ne 'UNDEFINED';
 }
 
-my (%fn, %prov, %req, %con, %obs);
+my (%fn, %prov, %req, %con, %obs, %rec, %sup);
 
 my %packs;
 my %repo;
@@ -160,7 +170,7 @@
 
 open(F, '<', $rpmdeps) || die("$rpmdeps: $!\n");
 # WARNING: the following code assumes that the 'I' tag comes last
-my ($pkgF, $pkgP, $pkgR, $pkgC, $pkgO);
+my ($pkgF, $pkgP, $pkgR, $pkgC, $pkgO, $pkgr, $pkgs);
 
 my $verscmp = \&Build::Rpm::verscmp;
 
@@ -194,16 +204,42 @@
     }
   } elsif (/^P:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
     $pkgP = $2;
+    next if $prov{$1};
+    $prov{$1} = $2;
   } elsif (/^R:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
     $pkgR = $2;
+    next if $req{$1};
+    $req{$1} = $2;
+  } elsif (/^r:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
+    $pkgr = $2;
   } elsif (/^C:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
     $pkgC = $2;
+    next if $con{$1};
+    $con{$1} = $2;
   } elsif (/^O:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
     $pkgO = $2;
+    next if $obs{$1};
+    $obs{$1} = $2;
+  } elsif (/^r:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
+    $pkgr = $2;
+  } elsif (/^s:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
+    $pkgs = $2;
   } elsif (/^I:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
+    my $r = 0;
+    if ($usehigherdeps) {
+      $r = 1;
+    } else {
+      if ($packs_done{$1}) {
+        $r = 0;
+      } else {
+        $r = 1;
+      }
+    }
+
+    next unless ($r);
     my ($i, $newid) = ($1, $2);
     undef $i unless !$ids{$i} || $verscmp->($ids{$i}, $newid) < 0;
-    undef $i unless defined($pkgF) && defined($pkgP);
+    undef $i unless defined($pkgF) && defined($pkgP) && defined($pkgR);
     if (defined $i) {
       $i =~ /^(.*)\.([^\.]+)$/ or die;
       push @{$packs_arch{$2}}, $1;
@@ -211,17 +247,27 @@
       $fn{$i}   = $pkgF;
       $prov{$i} = $pkgP;
       delete $req{$i};
+      delete $rec{$i};
       delete $con{$i};
       delete $obs{$i};
+      delete $rec{$i};
+      delete $sup{$i};
       $req{$i}  = $pkgR;
       $con{$i}  = $pkgC if defined $pkgC;
       $obs{$i}  = $pkgO if defined $pkgO;
+      $rec{$i}  = $pkgr if defined $pkgr;
+      $sup{$i}  = $pkgs if defined $pkgs;
+    } else {
+      next if $ids{$1};
+      $ids{$1} = $2;
     }
     undef $pkgF;
     undef $pkgP;
     undef $pkgR;
     undef $pkgC;
     undef $pkgO;
+    undef $pkgr;
+    undef $pkgs;
   } elsif ($_ eq 'D:') {
     %packs_done = %ids;
   }
@@ -234,7 +280,7 @@
 
 for my $pack (keys %packs) {
   my $r = {};
-  my (@s, $s, @pr, @re, @co, @ob);
+  my (@s, $s, @pr, @re, @co, @ob, @rc, @su);
   @s = split(' ', $prov{$packs{$pack}} || '');
   while (@s) {
     $s = shift @s;
@@ -291,10 +337,44 @@
       splice(@s, 0, 2);
     }
   }
+  @s = split(' ', $rec{$packs{$pack}} || '');
+  while (@s) {
+    $s = shift @s;
+    next if !$dofileprovides && $s =~ /^\//;
+    if ($s =~ /^rpmlib\(/) {
+      splice(@s, 0, 2);
+      next;
+    }
+    push @rc, $s;
+    while (@s && $s[0] =~ /^[\(<=>|]/) {
+      $rc[-1] .= " $s[0] $s[1]";
+      $rc[-1] =~ s/ \((.*)\)/ $1/;
+      $rc[-1] =~ s/(<|>){2}/$1/;
+      splice(@s, 0, 2);
+    }
+  }
+  @s = split(' ', $sup{$packs{$pack}} || '');
+  while (@s) {
+    $s = shift @s;
+    next if !$dofileprovides && $s =~ /^\//;
+    if ($s =~ /^rpmlib\(/) {
+      splice(@s, 0, 2);
+      next;
+    }
+    push @su, $s;
+    while (@s && $s[0] =~ /^[\(<=>|]/) {
+      $su[-1] .= " $s[0] $s[1]";
+      $su[-1] =~ s/ \((.*)\)/ $1/;
+      $su[-1] =~ s/(<|>){2}/$1/;
+      splice(@s, 0, 2);
+    }
+  }
   $r->{'provides'} = \@pr;
   $r->{'requires'} = \@re;
   $r->{'conflicts'} = \@co;
   $r->{'obsoletes'} = \@ob;
+  $r->{'recommends'} = \@rc;
+  $r->{'supplements'} = \@su;
   $repo{$pack} = $r;
 }
 
@@ -382,6 +462,9 @@
 
 #######################################################################
 
+if ($isvm) {
+  push @packdeps, @{$cf->{'vminstall'}};
+}
 my @bdeps = Build::get_build($cf, $subpacks, @packdeps, @extradeps);
 
 if (!shift @bdeps) {
@@ -407,5 +490,8 @@
 # make sure all preinstalls are in bdeps;
 # XXX: also add vmdeps?
 @bdeps = Build::unify(@bdeps, Build::get_preinstalls($cf));
+if ($isvm) {
+  @bdeps = Build::unify(@bdeps, Build::get_vminstalls($cf));
+}
 
 print_rpmlist(@bdeps);
--- build-20150115.orig/build-vm
+++ build-20150115/build-vm
@@ -686,6 +686,14 @@
     echo "BUILDENGINE='$BUILDENGINE'" >> $BUILD_ROOT/.build/build.data
     echo "CCACHE='$CCACHE'" >> $BUILD_ROOT/.build/build.data
     echo "ABUILD_TARGET='$ABUILD_TARGET'" >> $BUILD_ROOT/.build/build.data
+    # use the rpmbuild --stage option
+    if [ ! -z $BUILD_RPM_BUILD_STAGE ]; then
+        if [[ "$BUILD_RPM_BUILD_STAGE" =~ ^- ]]; then
+            echo "BUILD_RPM_BUILD_STAGE='$BUILD_RPM_BUILD_STAGE'" >> $BUILD_ROOT/.build/build.data
+        else
+            echo "BUILD_RPM_BUILD_STAGE='-$BUILD_RPM_BUILD_STAGE'" >> $BUILD_ROOT/.build/build.data
+        fi
+    fi
     # fallback time for broken hosts
     date '+@%s' > $BUILD_ROOT/.build/.date
     # we're done with the root file system, unmount
--- build-20150115.orig/init_buildsystem
+++ build-20150115/init_buildsystem
@@ -47,6 +47,9 @@
 
 BUILD_IS_RUNNING=$BUILD_ROOT/not-ready
 TMPFILE=$BUILD_ROOT/tmpfile
+RPMIDFMT="%{NAME}-%{VERSION}-%{RELEASE} %{BUILDTIME}-%{ARCH}\n"
+RPMCHECKOPTS_HOST=
+test -x /usr/bin/rpmquery && RPMCHECKOPTS_HOST="--nodigest --nosignature"
 
 # should RPMs be installed with --force ?
 USE_FORCE=false
@@ -59,6 +62,7 @@
 CREATE_BUILD_BINARIES=
 DLNOSIGNATURE=
 CACHE_DIR=/var/cache/build
+USEHIGHERDEPS=
 
 while test -n "$1" ; do
     case "$1" in
@@ -112,6 +116,10 @@
 	    shift
 	    DLNOSIGNATURE="--nosignature"
 	    ;;
+	--use-higher-deps)
+	    shift
+	    USEHIGHERDEPS="--usehigherdeps"
+	    ;;
 	*)
 	    break
 	    ;;
@@ -208,6 +216,7 @@
     else
 	unsafe_preinstall_check
 	CPIO="cpio --extract --unconditional --preserve-modification-time --make-directories --no-absolute-filenames --quiet"
+	cpio --help 2>/dev/null | grep -q -e --extract-over-symlinks && CPIO="$CPIO --extract-over-symlinks"
 	TAR="tar -x"
     fi
     pkg_preinstall
@@ -418,7 +427,7 @@
     local cachepkgid pkgid
     test -s "$1" || return 1
     if test -s "$BUILD_ROOT/.init_b_cache/rpms/$PKG.id" ; then
-        pkgid=$(perl -I$BUILD_DIR -MBuild -e Build::showquery "$1" buildid)
+        pkgid=$(rpm -qp --qf "${RPMIDFMT}" $RPMCHECKOPTS_HOST "${1}")
 	read cachepkgid < $BUILD_ROOT/.init_b_cache/rpms/$PKG.id
 	test "$cachepkgid" = "$pkgid" || return 1
     fi
@@ -573,7 +582,9 @@
 	#
 	RPMLIST=$BUILD_ROOT/.init_b_cache/rpmlist
 	test -z "$LIST_STATE" && echo "expanding package dependencies..."
-	if ! $BUILD_DIR/expanddeps $USEUSEDFORBUILD "${definesnstuff[@]}" --dist "$BUILD_DIST" --depfile "$CACHE_FILE" --archpath "$BUILD_ARCH" --configdir $CONFIG_DIR "${PKGS[@]}" > $RPMLIST ; then
+        VMOPT=
+        test -z "$PREPARE_VM" || VMOPT=--vm
+	if ! $BUILD_DIR/expanddeps $USEUSEDFORBUILD $VMOPT $USEHIGHERDEPS "${definesnstuff[@]}" --dist "$BUILD_DIST" --depfile "$CACHE_FILE" --archpath "$BUILD_ARCH" --configdir $CONFIG_DIR "${PKGS[@]}" > $RPMLIST ; then
 	    rm -f $BUILD_IS_RUNNING
 	    cleanup_and_exit 1
 	fi
@@ -598,9 +609,9 @@
     # register the QEMU emulator if needed
     # (we do not need this for the prepare step, as we do not run scripts in this case)
     #
+    copy_qemu
     if test -z "$PREPARE_VM" ; then
 	if check_use_emulator ; then
-	    copy_qemu
 	    echo "registering binfmt handlers for cross build"
 	    "$BUILD_DIR/$INITVM_NAME"
 	    echo 0 > /proc/sys/vm/mmap_min_addr
@@ -967,8 +978,13 @@
 	    continue
 	fi
     fi
-
-    PKGID=$(perl -I$BUILD_DIR -MBuild -e Build::showquery "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF" buildid)
+    
+    # revert use rpm to query pkgid if building rpm package 
+    if test "$PSUF" != "rpm" ; then
+        PKGID=$(perl -I$BUILD_DIR -MBuild -e Build::showquery "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF" buildid)
+    else
+        PKGID=`rpm -qp --qf "$RPMIDFMT" $RPMCHECKOPTS_HOST $BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm`
+    fi
 
     if test -f $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG ; then
 	read OLDPKGID < $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG
--- build-20150115.orig/createdirdeps
+++ build-20150115/createdirdeps
@@ -51,7 +51,7 @@
 if (defined($oldfile) && open(F, '<', $oldfile)) {
   while (<F>) {
     chomp;
-    $old{$1} = $_ if /^([PRCOI]:[^ ]+): /;
+    $old{$1} = $_ if /^([PRrsCOI]:[^ ]+): /;
   }
   close F;
 }
@@ -78,14 +78,14 @@
 	  next if $seen{$idx};
 	  $seen{$idx} = 1;
 	  print "F:$idx: $path\n";
-	  for (qw{P R C O I}) {
+	  for (qw{P R r s C O I}) {
 	    print $old{"$_:$idx"}."\n" if $old{"$_:$idx"};
 	  }
 	  next;
 	}
       }
     }
-    my $q = Build::query($path, 'addselfprovides' => 1, 'conflicts' => 1, 'evra' => 1, 'buildtime' => 1);
+    my $q = Build::query($path, 'addselfprovides' => 1, 'conflicts' => 1, 'evra' => 1, 'buildtime' => 1, 'weakdeps' => 1);
     next unless $q && defined($q->{'name'}) && defined($q->{'arch'}) && defined($q->{'version'});
     my $idx = "$q->{'name'}.$q->{'arch'}-$id";
     next if $seen{$idx};
--- build-20150115.orig/build
+++ build-20150115/build
@@ -97,6 +97,7 @@
 CCACHE=
 DLNOSIGNATURE=
 CACHE_DIR=/var/cache/build
+USEHIGHERDEPS=
 
 
 # This is for insserv
@@ -366,7 +367,14 @@
     else
 	umount -n $BUILD_ROOT/proc/sys/fs/binfmt_misc 2> /dev/null || true
 	umount -n $BUILD_ROOT/proc 2>/dev/null || true
-	umount -n $BUILD_ROOT/dev/pts 2>/dev/null || true
+	while true
+	do
+		umount -n $BUILD_ROOT/dev/pts 2>/dev/null
+		if test $? -ne 0; then
+			break
+		fi
+	done
+
 	umount -n $BUILD_ROOT/dev/shm 2>/dev/null || true
 	umount -n $BUILD_ROOT/sys 2>/dev/null || true
 	test -n "$VM_IMAGE" -a "$VM_IMAGE" != 1 && umount $BUILD_ROOT 2>/dev/null || true
@@ -422,9 +430,14 @@
     fi
 }
 
-setupicecream() {
-    if test "$icecream" -eq 0 ; then
-	rm -rf "$BUILD_ROOT/var/run/icecream"
+setupicecream()
+{
+    local icecreamdir="/var/run/icecream"
+    if test `readlink "$BUILD_ROOT/var/run"` = '/run' ; then
+        icecreamdir="/run/icecream"
+    fi
+    if [ "$icecream" -eq 0 ]; then
+	rm -rf "$BUILD_ROOT$icecreamdir"
 	rm -f "$BUILD_ROOT/etc/profile.d/build_icecream.sh"
 	return 0
     fi
@@ -442,7 +455,7 @@
 	echo 'export CCACHE_PATH=/usr/lib/icecc/bin:/opt/icecream/bin' > "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
     fi
 
-    local icecc_vers=(`shopt -s nullglob; echo $BUILD_ROOT/var/run/icecream/*.tar.{bz2,gz}`)
+    local icecc_vers=(`shopt -s nullglob; echo $BUILD_ROOT$icecreamdir/*.tar.{bz2,gz}`)
     icecc_vers=${icecc_vers//$BUILD_ROOT/}
 
     # XXX use changelog like autobuild does instead?
@@ -454,21 +467,23 @@
 	-o "$BUILD_ROOT/usr/bin/as" -nt "$BUILD_ROOT/$icecc_vers" \
 	-o "$BUILD_ROOT/lib/libc.so.6" -nt "$BUILD_ROOT/$icecc_vers"
     then
-	rm -rf "$BUILD_ROOT/var/run/icecream"
-	mkdir -p "$BUILD_ROOT/var/run/icecream"
-	if test -e "$BUILD_ROOT"/usr/bin/create-env ; then
-	    createenv=/usr/bin/create-env
-	elif test -e "$BUILD_ROOT"/usr/lib/icecc/icecc-create-env ; then
-	    createenv="/usr/lib/icecc/icecc-create-env /usr/bin/gcc /usr/bin/g++" # XXX
-	elif test -e "$BUILD_ROOT"/usr/lib64/icecc/icecc-create-env ; then
-	    createenv="/usr/lib64/icecc/icecc-create-env /usr/bin/gcc /usr/bin/g++" # XXX
+	rm -rf "$BUILD_ROOT$icecreamdir"
+	mkdir -p "$BUILD_ROOT$icecreamdir"
+	if [ -e "$BUILD_ROOT"/usr/bin/create-env ]; then
+	  createenv=/usr/bin/create-env
+	elif [ -e "$BUILD_ROOT"/usr/lib/icecc/icecc-create-env ]; then
+	  createenv="/usr/lib/icecc/icecc-create-env /usr/bin/gcc /usr/bin/g++" # XXX
+	elif [ -e "$BUILD_ROOT"/usr/lib64/icecc/icecc-create-env ]; then
+	  createenv="/usr/lib64/icecc/icecc-create-env /usr/bin/gcc /usr/bin/g++" # XXX
 	else
 	    echo "create-env not found"
 	    return 1
 	fi
-	chroot $BUILD_ROOT bash -c "cd /var/run/icecream; $createenv" || cleanup_and_exit 1
-	icecc_vers=(`shopt -s nullglob; echo $BUILD_ROOT/var/run/icecream/*.tar.{bz2,gz}`)
+        echo "creating new env in '$icecreamdir'"
+	chroot $BUILD_ROOT bash -c "cd $icecreamdir; $createenv" || cleanup_and_exit 1
+	icecc_vers=(`shopt -s nullglob; echo $BUILD_ROOT/$icecreamdir/*.tar.{bz2,gz}`)
 	icecc_vers=${icecc_vers//$BUILD_ROOT/}
+	echo "created icecream environment $icecc_vers"
     else
 	echo "reusing existing icecream environment $icecc_vers"
     fi
@@ -923,6 +938,9 @@
 	echo "$ARG does not take an argument"
 	cleanup_and_exit
       ;;
+      -use-higher-deps)
+        USEHIGHERDEPS="--use-higher-deps"
+      ;;
       -*)
 	if vm_parse_options "$@" ; then
 	    set -- "${nextargs[@]}"
@@ -993,7 +1011,7 @@
 	recipe_unpack_srcrpm
 	RECIPEFILE="$MYSRCDIR/$RECIPEFILE"
     fi
-    init_buildsystem --configdir "$CONFIG_DIR" --cachedir "$CACHE_DIR" --list-state "${definesnstuff[@]}" "${repos[@]}" $DLNOSIGNATURE $KEEP_PACKS $USEUSEDFORBUILD $RECIPEFILE $BUILD_EXTRA_PACKS
+    init_buildsystem --configdir "$CONFIG_DIR" --cachedir "$CACHE_DIR" --list-state "${definesnstuff[@]}" "${repos[@]}" $DLNOSIGNATURE $KEEP_PACKS $USEHIGHERDEPS $USEUSEDFORBUILD $RECIPEFILE $BUILD_EXTRA_PACKS
     ERR=$?
     rm -rf "$BUILD_ROOT"
     cleanup_and_exit $ERR
@@ -1133,7 +1151,7 @@
 	test "$BUILDTYPE" = mock && CREATE_BUILD_BINARIES=--create-build-binaries
 	test "$BUILDTYPE" = debootstrap && CREATE_BUILD_BINARIES=--create-build-binaries
 	test "$BUILDTYPE" = livebuild && CREATE_BUILD_BINARIES=--create-build-binaries
-	set -- init_buildsystem --configdir "$CONFIG_DIR" --cachedir "$CACHE_DIR" "${definesnstuff[@]}" "${repos[@]}" $CLEAN_BUILD $DLNOSIGNATURE $KEEP_PACKS $USEUSEDFORBUILD $CREATE_BUILD_BINARIES $RPMLIST "$MYSRCDIR/$RECIPEFILE" $ADDITIONAL_PACKS
+	set -- init_buildsystem --configdir "$CONFIG_DIR" --cachedir "$CACHE_DIR" "${definesnstuff[@]}" "${repos[@]}" $CLEAN_BUILD $DLNOSIGNATURE $KEEP_PACKS $USEHIGHERDEPS $USEUSEDFORBUILD $CREATE_BUILD_BINARIES $RPMLIST "$MYSRCDIR/$RECIPEFILE" $ADDITIONAL_PACKS
 	echo "$* ..."
         start_time=`date +%s`
 	"$@" || cleanup_and_exit 1
--- build-20150115.orig/Build.pm
+++ build-20150115/Build.pm
@@ -173,11 +173,18 @@
   return $cf;
 }
 
+sub get_hostarch {
+	my $hostarch = `uname -m` || 'i586';
+	return $hostarch;
+}
+
 sub read_config {
   my ($arch, $cfile) = @_;
   my @macros = split("\n", $std_macros.$extra_macros);
   push @macros, "%define _target_cpu $arch";
   push @macros, "%define _target_os linux";
+  my $hostarch = get_hostarch();
+  push @macros, "%define hostarch $hostarch";
   my $config = {'macros' => \@macros, 'arch' => $arch};
   my @config;
   if (ref($cfile)) {
@@ -327,6 +334,10 @@
       } else {
 	push @{$config->{'constraint'}}, $l;
       }
+    } elsif ($l0 eq 'rpmbuildstage:') { # use the rpmbuild --stage option
+      $config->{'rpmbuildstage'} = $l[0];
+    } elsif ($l0 eq 'copylinkedpackages:') { # to enable the RPM compariton tool for prerelease projects
+      # Since it is not used in build package, do nothing.
     } elsif ($l0 !~ /^[#%]/) {
       warn("unknown keyword in config: $l0\n");
     }
@@ -575,11 +586,13 @@
 sub readdeps {
   my ($config, $pkginfo, @depfiles) = @_;
 
-  my %requires;
   local *F;
+  my %requires;
   my %provides;
   my %pkgconflicts;
   my %pkgobsoletes;
+  my %recommends;
+  my %supplements;
   my $dofileprovides = %{$config->{'fileprovides'} || {}};
   for my $depfile (@depfiles) {
     if (ref($depfile) eq 'HASH') {
@@ -588,6 +601,8 @@
 	$requires{$rr} = $depfile->{$rr}->{'requires'};
 	$pkgconflicts{$rr} = $depfile->{$rr}->{'conflicts'};
 	$pkgobsoletes{$rr} = $depfile->{$rr}->{'obsoletes'};
+	$recommends{$rr} = $depfile->{$rr}->{'recommends'};
+	$supplements{$rr} = $depfile->{$rr}->{'supplements'};
       }
       next;
     }
@@ -629,7 +644,7 @@
       }
       my %ss;
       @ss = grep {!$ss{$_}++} @ss;
-      if ($s =~ /^(P|R|C|O):(.*)\.(.*)-\d+\/\d+\/\d+:$/) {
+      if ($s =~ /^(P|R|C|O|r|s):(.*)\.(.*)-\d+\/\d+\/\d+:$/) {
 	my $pkgid = $2;
 	my $arch = $3;
 	if ($1 eq "P") {
@@ -655,6 +670,16 @@
 	  $pkginfo->{$pkgid}->{'obsoletes'} = \@ss if $pkginfo;
 	  next;
 	}
+	if ($1 eq "r") {
+	  $recommends{$pkgid} = \@ss;
+	  $pkginfo->{$pkgid}->{'recommends'} = \@ss if $pkginfo;
+	  next;
+	}
+	if ($1 eq "s") {
+	  $supplements{$pkgid} = \@ss;
+	  $pkginfo->{$pkgid}->{'supplements'} = \@ss if $pkginfo;
+	  next;
+	}
       }
     }
     close F;
@@ -678,6 +703,8 @@
   $config->{'requiresh'} = \%requires;
   $config->{'pkgconflictsh'} = \%pkgconflicts;
   $config->{'pkgobsoletesh'} = \%pkgobsoletes;
+  $config->{'recommendsh'} = \%recommends;
+  $config->{'supplementsh'} = \%supplements;
   makewhatprovidesh($config);
 }
 
@@ -705,6 +732,8 @@
   print $fh "R:$id".join(' ', @{$pkg->{'requires'}})."\n" if $pkg->{'requires'};
   print $fh "C:$id".join(' ', @{$pkg->{'conflicts'}})."\n" if $pkg->{'conflicts'};
   print $fh "O:$id".join(' ', @{$pkg->{'obsoletes'}})."\n" if $pkg->{'obsoletes'};
+  print $fh "r:$id".join(' ', @{$pkg->{'recommends'}})."\n" if $pkg->{'recommends'};
+  print $fh "s:$id".join(' ', @{$pkg->{'supplements'}})."\n" if $pkg->{'supplements'};
   print $fh "I:$id".getbuildid($pkg)."\n";
 }
 
@@ -740,6 +769,8 @@
   delete $config->{'requiresh'};
   delete $config->{'pkgconflictsh'};
   delete $config->{'pkgobsoletesh'};
+  delete $config->{'recommendsh'};
+  delete $config->{'supplementsh'};
 }
 
 my %addproviders_fm = (
@@ -843,6 +874,17 @@
   return 0;
 }
 
+sub todo2recommended {
+  my ($config, $recommended, $todo) = @_;
+  my $whatprovides = $config->{'whatprovidesh'};
+  my $pkgrecommends = $config->{'recommendsh'} || {};
+  for my $p (splice @$todo) {
+    for my $r (@{$pkgrecommends->{$p} || []}) {
+      $recommended->{$_} = 1 for @{$whatprovides->{$r} || addproviders($config, $r)}
+    }
+  }
+}
+
 sub expand {
   my ($config, @p) = @_;
 
@@ -852,6 +894,8 @@
   my $prefer = $config->{'preferh'};
   my $ignore = $config->{'ignoreh'};
   my $ignoreconflicts = $config->{'expandflags:ignoreconflicts'};
+  my $ignoreignore;
+  my $userecommendsforchoices = 1;
 
   my $whatprovides = $config->{'whatprovidesh'};
   my $requires = $config->{'requiresh'};
@@ -869,8 +913,18 @@
   }
   @p = grep {!/^-/} @p;
 
-  my %p;		# expanded packages
   my %aconflicts;	# packages we are conflicting with
+  for (grep {/^!/} @p) {
+    my $r = /^!!/ ? substr($_, 2) : substr($_, 1);
+    my @q = @{$whatprovides->{$r} || addproviders($config, $r)};
+    @q = nevrmatch($config, $r, @q) if /^!!/;
+    $aconflicts{$_} = "is in BuildConflicts" for @q;
+  }
+  my %recommended;	# recommended by installed packages
+  my @rec_todo;		# installed todo
+
+  @p = grep {!/^[-!]/} @p;
+  my %p;		# expanded packages
 
   # add direct dependency packages. this is different from below,
   # because we add packages even if the dep is already provided and
@@ -899,6 +953,7 @@
 	$aconflicts{$_} = "is obsoleted by installed $q[0]" for nevrmatch($config, $r, @{$whatprovides->{$r} || addproviders($config, $r)});
       }
     }
+    push @rec_todo, $q[0] if $userecommendsforchoices;
   }
   push @p, @directdepsend;
 
@@ -964,6 +1019,12 @@
 		last;
 	    }
 	}
+	if ($doamb == 2) {
+	  todo2recommended($config, \%recommended, \@rec_todo) if @rec_todo;
+	  my @pq = grep {$recommended{$_}} @q;
+	  print "recommended [@pq] among [@q]\n" if $expand_dbg;
+	  @q = @pq if @pq;
+	}
 	if (@q > 1) {
 	  if ($r ne $p) {
 	    push @error, "have choice for $r needed by $p: @q";
@@ -985,6 +1046,7 @@
 	    $aconflicts{$_} = "is obsoleted by installed $q[0]" for nevrmatch($config, $r, @{$whatprovides->{$r} || addproviders($config, $r)});
 	  }
         }
+	push @rec_todo, $q[0] if $userecommendsforchoices;
 	@error = ();
 	$doamb = 0;
       }
@@ -993,11 +1055,12 @@
     next if @p;		# still work to do
 
     # only ambig stuff left
-    if (@pamb && !$doamb) {
+    if (@pamb && ($doamb == 0 || $doamb == 1)) {
       @p = @pamb;
       @pamb = ();
-      $doamb = 1;
-      print "now doing undecided dependencies\n" if $expand_dbg;
+      todo2recommended($config, \%recommended, \@rec_todo) if @rec_todo;
+      $doamb = %recommended ? 2 : 3;
+      print "now doing undecided dependencies, $doamb = $doamb\n" if $expand_dbg;
       next;
     }
     return undef, @error if @error;
@@ -1009,6 +1072,7 @@
   my ($config, @p) = @_;
 
   my $requires = $config->{'requiresh'};
+  my $recommends = $config->{'recommendsh'};
   my $whatprovides = $config->{'whatprovidesh'};
   my %deps;
   my %rdeps;
@@ -1106,6 +1170,7 @@
   my ($config, @p) = @_;
   my $whatprovides = $config->{'whatprovidesh'};
   my $requires = $config->{'requiresh'};
+  my $recommends = $config->{'recommendsh'};
   my %a;
   for my $p (@p) {
     for my $r (@{$requires->{$p} || [$p]}) {
--- build-20150115.orig/Build/Rpm.pm
+++ build-20150115/Build/Rpm.pm
@@ -436,6 +436,20 @@
       $hasif = 1;
       next;
     }
+    if ($line =~ /^\s*%ifhostarch(.*)$/) {
+      my $hostarch = $macros{'hostarch'} || 'unknown';
+      my @hostarchs = grep {$_ eq $hostarch} split(/\s+/, $1);
+      $skip = 1 if !@hostarchs;
+      $hasif = 1;
+      next;
+    }
+    if ($line =~ /^\s*%ifnhostarch(.*)$/) {
+      my $hostarch = $macros{'hostarch'} || 'unknown';
+      my @hostarchs = grep {$_ eq $hostarch} split(/\s+/, $1);
+      $skip = 1 if @hostarchs;
+      $hasif = 1;
+      next;
+    }
     if ($line =~ /^\s*%ifos(.*)$/) {
       my $os = $macros{'_target_os'} || 'unknown';
       my @oss = grep {$_ eq $os} split(/\s+/, $1);
--- build-20150115.orig/Build/Rpmmd.pm
+++ build-20150115/Build/Rpmmd.pm
@@ -169,7 +169,7 @@
   return if $dep =~ /^rpmlib\(/;
   if(exists $attr{'flags'}) {
     my $evr = $attr{'ver'};
-    return unless defined($evr) && exists($flagmap{$attr{'flags'}});
+    #return unless defined($evr) && exists($flagmap{$attr{'flags'}});
     $evr = "$attr{'epoch'}:$evr" if $attr{'epoch'};
     $evr .= "-$attr{'rel'}" if defined $attr{'rel'};
     $dep .= " $flagmap{$attr{'flags'}} $evr";
--- build-20150115.orig/debian/changelog
+++ build-20150115/debian/changelog
@@ -1,3 +1,29 @@
+build (20150115-tizen20170405) unstable; urgency=high
+
+  * update tizen version to tizen20170405
+
+ -- SoonKyu Park <sk7.park@samsung.com>  Wed, 5 Apr 2017 19:00:00 +0900
+
+build (20150115-tizen20170114) unstable; urgency=high
+
+  * update tizen version to tizen20170114
+
+ -- SoonKyu Park <sk7.park@samsung.com>  Sat, 14 Jan 2017 19:30:22 +0200
+
+build (20150115-tizen20161231) unstable; urgency=high
+
+  * update tizen version to tizen20161231
+
+ -- SoonKyu Park <sk7.park@samsung.com>  Sat, 31 Dec 2016 19:30:22 +0200
+
+
+build (20150115-tizen20160928) unstable; urgency=high
+
+  * update tizen version to tizen20160928
+
+ -- SoonKyu Park <sk7.park@samsung.com>  Wed, 28 Sep 2016 19:30:22 +0200
+
+
 build (20150115-tizen20160302) unstable; urgency=high
 
   * update to version 20150115
--- build-20150115.orig/debian/control
+++ build-20150115/debian/control
@@ -10,9 +10,9 @@
 Depends: ${perl:Depends},
   rpm,
   libxml-parser-perl,
-  libcrypt-ssleay-perl (= 0.64-tizen20130308),
+  libcrypt-ssleay-perl (>= 0.64-tizen20130308),
   binfmt-support,
-  tizen-qemu-arm-static-2013.12.12
+  tizen-qemu-arm-static-2016.12.31
 Recommends: rpm2cpio
 Description: A script to build SUSE Linux RPMs
  This package provides a script for building RPMs for SUSE Linux
--- build-20150115.orig/debian/compat
+++ build-20150115/debian/compat
@@ -1 +1 @@
-4
+7
--- build-20150115.orig/packaging/build.changes
+++ build-20150115/packaging/build.changes
@@ -1,4 +1,34 @@
 -------------------------------------------------------------------
+Wed Apr 5 19:00:00 KST 2017 - sk7.park@samsung.com
+
+- update tizen version to tizen20170405
+
+-------------------------------------------------------------------
+Sat Jan 14 19:30:00 CST 2017 - sk7.park@samsung.com
+
+- update tizen version to tizen20170114
+
+-------------------------------------------------------------------
+Sat Dec 31 19:30:00 CST 2016 - sk7.park@samsung.com
+
+- update tizen version to tizen20161231
+
+-------------------------------------------------------------------
+Wed Sep 28 19:30:00 CST 2016 - sk7.park@samsung.com
+
+- update tizen version to tizen20160928
+
+-------------------------------------------------------------------
+Wed Mar 2 19:30:00 CST 2016 - jiankang.fan@samsung.com
+
+- update to version 20150115
+
+-------------------------------------------------------------------
+Wed Sep 12 09:05:24 CST 2012 - qiang.z.zhang@intel.com
+
+- update to version 2013.11.12
+
+-------------------------------------------------------------------
 Wed Sep 11 09:05:24 CST 2012 - qiang.z.zhang@intel.com
 
 - update to version 2012.09.11
--- build-20150115.orig/packaging/build.spec
+++ build-20150115/packaging/build.spec
@@ -1,4 +1,4 @@
-#
+#	
 # spec file for package build
 #
 # Copyright (c) 2012 SUSE LINUX Products GmbH, Nuernberg, Germany.
@@ -45,7 +45,7 @@
 Requires:       perl(Crypt::SSLeay)
 Requires:       perl(XML::Parser)
 Requires:       perl(Archive::Tar)
-Requires:       tizen-qemu-arm-static >= 2013.12.12
+Requires:       tizen-qemu-arm-static >= 2016.12.31
 Requires:       perl-Crypt-SSLeay >= 0.64-tizen20130308
 
 %if 0%{?fedora_version} || 0%{?suse_version} == 1220 || 0%{?centos_version}
@@ -72,7 +72,7 @@
 %if 0%{?suse_version} > 1120 || 0%{?mdkversion}
 Recommends:     build-mkdrpms
 %endif
-Provides:   tizen-build = 20160311
+Provides:   tizen-build = 20170405
 %description
 This package provides a script for building RPMs for SUSE Linux in a
 chroot environment.
@@ -116,7 +116,7 @@
 Requires:       build
 BuildRequires:  gcc
 BuildRequires:  glibc-devel
-Provides:       tizen-build-initvm-%{initvm_arch} = 20160311
+Provides:       tizen-build-initvm-%{initvm_arch} = 20170405
 Obsoletes:      build-initvm
 %if 0%{?suse_version}
 BuildRequires:  glibc-devel-static
@@ -136,7 +136,7 @@
 make CFLAGS="$RPM_BUILD_FLAGS" initvm-all
 
 %if 0%{?fedora} == 23
-cp -f find-debuginfo.sh /usr/lib/rpm/find-debuginfo.sh
+%global debug_package %{nil}
 %endif
 
 %install
@@ -194,6 +194,14 @@
 /usr/lib/build/initvm.*
 
 %changelog
+* Wed Apr 5 2017 sk7.park@samsung.com
+- update tizen version to tizen20170405
+* Sat Jan 14 2017 sk7.park@samsung.com
+- update tizen version to tizen20170114
+* Sat Dec 31 2016 sk7.park@samsung.com
+- update tizen version to tizen20161231
+* Wed Sep 28 2016 sk7.park@samsung.com
+- update tizen version to tizen20160928
 * Mon Feb 29 2016 jiankang.fan@samsung.com
 - update to version 2015.11.12
 * Tue Sep 11 2012 qiang.z.zhang@intel.com
