--- 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");
     }
--- 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/createdirdeps
+++ build-20150115/createdirdeps
@@ -85,7 +85,7 @@
 	}
       }
     }
-    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, 'alldeps' => 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/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/init_buildsystem
+++ build-20150115/init_buildsystem
@@ -59,6 +59,7 @@
 CREATE_BUILD_BINARIES=
 DLNOSIGNATURE=
 CACHE_DIR=/var/cache/build
+USEHIGHERDEPS=
 
 while test -n "$1" ; do
     case "$1" in
@@ -112,6 +113,10 @@
 	    shift
 	    DLNOSIGNATURE="--nosignature"
 	    ;;
+	--use-higher-deps)
+	    shift
+	    USEHIGHERDEPS="--usehigherdeps"
+	    ;;
 	*)
 	    break
 	    ;;
@@ -208,6 +213,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
@@ -573,7 +579,7 @@
 	#
 	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
+	if ! $BUILD_DIR/expanddeps $USEUSEDFORBUILD $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
--- build-20150115.orig/build
+++ build-20150115/build
@@ -97,6 +97,7 @@
 CCACHE=
 DLNOSIGNATURE=
 CACHE_DIR=/var/cache/build
+USEHIGHERDEPS=
 
 
 # This is for insserv
@@ -422,9 +423,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 +448,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 +460,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 +931,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 +1004,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 +1144,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/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);
 
 $configdir = ($::ENV{'BUILD_DIR'} || '/usr/lib/build') . '/configs';
 
@@ -77,6 +77,11 @@
     Build::define("_without_$def --without-$def");
     next;
   }
+  if ($ARGV[0] eq '--usehigherdeps') {
+    shift @ARGV;
+    $usehigherdeps = 1;
+    next;
+  }
   last;
 }
 
@@ -194,16 +199,36 @@
     }
   } 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 (/^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 (/^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;
@@ -216,6 +241,9 @@
       $req{$i}  = $pkgR;
       $con{$i}  = $pkgC if defined $pkgC;
       $obs{$i}  = $pkgO if defined $pkgO;
+    } else {
+      next if $ids{$1};
+      $ids{$1} = $2;
     }
     undef $pkgF;
     undef $pkgP;
--- build-20150115.orig/debian/changelog
+++ build-20150115/debian/changelog
@@ -1,3 +1,10 @@
+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,7 +10,7 @@
 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
 Recommends: rpm2cpio
--- build-20150115.orig/packaging/build.changes
+++ build-20150115/packaging/build.changes
@@ -1,4 +1,19 @@
 -------------------------------------------------------------------
+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
@@ -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,8 @@
 /usr/lib/build/initvm.*
 
 %changelog
+* 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
--- 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";
