--- old/usr/src/pkg/Makefile	Mon Aug  5 17:17:29 2019
+++ new/usr/src/pkg/Makefile	Mon Aug  5 17:17:29 2019
@@ -21,6 +21,7 @@
 
 #
 # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright 2014 Nexenta Systems, Inc. All rights reserved.
 # Copyright 2015, OmniTI Computer Consulting, Inc. All rights reserved.
 # Copyright 2015 Igor Kozhukhov <ikozhukhov@gmail.com>
 #
@@ -242,11 +243,17 @@
 PROC_SYNTH_PKGS= $(SYNTH_PKGS:%=$(PDIR)/%.mog)
 
 #
-# Root of pkg image to use for dependency resolution
-# Normally / on the machine used to build the binaries
+# Root of pkg image to use for dependency resolution Normally / on the machine
+# used to build the binaries, or the ADJUNCT_PROTO
 #
-PKGDEP_RESOLVE_IMAGE = /
+PKG_ADJUNCT.cmd= AP=$${ADJUNCT_PROTO:-/}; if [[ -d $${AP}/var/pkg ]]; then \
+		echo $$AP; \
+	else	\
+		echo /;	\
+	fi
 
+PKGDEP_RESOLVE_IMAGE = $(PKG_ADJUNCT.cmd:sh)
+
 #
 # For each package, we determine the target repository based on
 # manifest-embedded metadata.  Because we make that determination on
@@ -360,6 +367,10 @@
 
 ALL_TARGETS= $(PROC_SYNTH_PKGS) proto_list_$(PKGMACH)
 
+# This may be empty, or set to "ips", or "deb"
+PKGTYPE=ips
+include Makefile.$(PKGTYPE)
+
 all: $(ALL_TARGETS)
 
 #
@@ -385,8 +396,8 @@
 		done; \
 	else \
 		print "Resolving dependencies"; \
-		pkgdepend -R $(PKGDEP_RESOLVE_IMAGE) resolve \
-		    -m $(DEP_SYNTH_PKGS) $(DEP_PKGS); \
+		pkgdepend $(PKGDEP_FLAGS) resolve \
+		    $(PKGRES_FLAGS) $(DEP_SYNTH_PKGS) $(DEP_PKGS); \
 		for p in $(DEP_SYNTH_PKGS:%.dep=%) $(DEP_PKGS:%.dep=%); do \
 			if [ "$$(print $$p.metadata.*)" = \
 			     "$$(print $$p.metadata.noincorp.*)" ]; \
@@ -403,41 +414,7 @@
 	fi
 	$(PKGDEBUG)$(TOUCH) $(@)
 
-install: $(ALL_TARGETS) repository-metadata
-
-repository-metadata: publish_pkgs
-	$(PKGDEBUG)for r in $(REPOS); do \
-		pkgrepo refresh -s $(PKGDEST)/repo.$$r; \
-	done
-
 #
-# Since we create zero-length processed manifests for a graceful abort
-# from pkgmogrify, we need to detect that here and make no effort to
-# publish the package.
-#
-# For all other packages, we publish them regardless of status.  We
-# derive the target repository as a component of the metadata-derived
-# symlink for each package.
-#
-publish_pkgs: $(REPOS:%=$(PKGDEST)/repo.%) $(PDIR)/gendeps .WAIT $(PUB_PKGS)
-
-#
-# Before publishing, we want to pull the license files from $CODEMGR_WS
-# into the proto area.  This allows us to NOT pass $SRC (or
-# $CODEMGR_WS) as a basedir for publication.
-#
-$(PUB_PKGS): stage-licenses
-
-#
-# Initialize the empty on-disk repositories
-#
-$(REPOS:%=$(PKGDEST)/repo.%):
-	@print "Initializing $(@F)"
-	$(PKGDEBUG)$(INS.dir)
-	$(PKGDEBUG)pkgsend -s file://$(@) create-repository \
-		--set-property publisher.prefix=$(PKGPUBLISHER)
-
-#
 # rule to process real manifests
 #
 # To allow redistributability and package status to change, we must
@@ -498,7 +475,7 @@
 $(PDIR)/%.mog: manifests/%.mf
 	@print "Processing manifest $(<F)"
 	@env PKGFMT_OUTPUT=v1 pkgfmt -c $<
-	$(PKGDEBUG)$(RM) $(@) $(@:%.mog=%) $(@:%.mog=%.nodepend) \
+	$(PKGDEBUG)$(RM) -r $(@) $(@:%.mog=%) $(@:%.mog=%.nodepend) \
 		$(@:%.mog=%.lics) $(PDIR)/$(@F:%.mog=%).metadata.* $(@).vars
 	$(PKGDEBUG)$(PKGMOGRIFY) $(PKGMOG_VERBOSE) $(PM_INC:%= -I %) \
 		$(PKGMOG_DEFINES:%=-D %) -P $(@).vars -O $(@) \
@@ -532,25 +509,6 @@
 	fi
 
 #
-# The full chain implies that there should be a .dep.res suffix rule,
-# but dependency generation is done on a set of manifests, rather than
-# on a per-manifest basis.  Instead, see the gendeps rule above.
-#
-
-$(PDIR)/%.pub: $(PDIR)/%.res
-	$(PKGDEBUG)m=$$(basename $(@:%.pub=%).metadata.*); \
-	r=$${m#$(@F:%.pub=%.metadata.)+(?).}; \
-	if [ -s $(<) ]; then \
-		print "Publishing $(@F:%.pub=%) to $$r repository"; \
-		pkgsend -s file://$(PKGDEST)/repo.$$r publish \
-		    -d $(PKGROOT) -d $(TOOLSROOT) \
-		    -d license_files -d $(PKGROOT)/licenses \
-		    --fmri-in-manifest --no-index --no-catalog $(<) \
-		    > /dev/null; \
-	fi; \
-	$(TOUCH) $(@);
-
-#
 # rule to build the synthetic manifests
 #
 # This rule necessarily has PKGDEP_TYPE that changes according to
@@ -708,7 +666,6 @@
 #
 $(PKGS) $(SYNTH_PKGS): $(PDIR)/$$(@:%=%.mog)
 
-$(PKGS:%=%.pub) $(SYNTH_PKGS:%=%.pub): $(PDIR)/$$(@)
 
 #
 # This is a convenience target to resolve dependencies without publishing
