dpdk: build nasm from source

As not all distros have the minimum required nasm version (2.12.01)
available, build nasm from sources when building Intel IPsec MB library.

Change-Id: Iaa9da87f612c0f84da5704162c3bf430b3351076
Signed-off-by: Sergio Gonzalez Monroy <sergio.gonzalez.monroy@intel.com>
diff --git a/Makefile b/Makefile
index 799fa7e..4bdaab3 100644
--- a/Makefile
+++ b/Makefile
@@ -19,12 +19,6 @@
 SAMPLE_PLUGIN?=no
 MACHINE=$(shell uname -m)
 
-ifeq ($(MACHINE),$(filter $(MACHINE),x86_64))
-export AESNI?=y
-else
-export AESNI?=N
-endif
-
 ,:=,
 define disable_plugins
 $(if $(1), \
@@ -67,7 +61,7 @@
 DEB_DEPENDS  = curl build-essential autoconf automake bison ccache
 DEB_DEPENDS += debhelper dkms git libtool libapr1-dev dh-systemd
 DEB_DEPENDS += libconfuse-dev git-review exuberant-ctags cscope pkg-config
-DEB_DEPENDS += lcov chrpath autoconf nasm indent clang-format libnuma-dev
+DEB_DEPENDS += lcov chrpath autoconf indent clang-format libnuma-dev
 DEB_DEPENDS += python-all python-dev python-virtualenv python-pip libffi6 check
 DEB_DEPENDS += libboost-all-dev
 ifeq ($(OS_VERSION_ID),14.04)
@@ -113,11 +107,6 @@
 # +ganglia-devel if building the ganglia plugin
 
 RPM_DEPENDS += chrpath libffi-devel rpm-build
-ifeq ($(OS_ID),fedora)
-	RPM_DEPENDS += nasm
-else ifeq ($(findstring y,$(AESNI)),y)
-	RPM_DEPENDS += https://kojipkgs.fedoraproject.org//packages/nasm/2.12.02/2.fc26/x86_64/nasm-2.12.02-2.fc26.x86_64.rpm
-endif
 
 SUSE_NAME= $(shell grep '^NAME=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g' | cut -d' ' -f2)
 RPM_SUSE_BUILDTOOLS_DEPS = autoconf automake bison ccache check-devel chrpath clang indent libtool make
@@ -129,11 +118,9 @@
 ifneq ($(SUSE_NAME),Tumbleweed)
 	RPM_SUSE_DEVEL_DEPS += boost_1_61-devel gcc6 
 	RPM_SUSE_PYTHON_DEPS += python-virtualenv
-	RPM_SUSE_BUILDTOOL_DEPS += https://download.opensuse.org/tumbleweed/repo/oss/suse/x86_64/nasm-2.13.01-2.2.x86_64.rpm
 else
 	RPM_SUSE_DEVEL_DEPS += boost_1_65-devel gcc
 	RPM_SUSE_PYTHON_DEPS += python2-virtualenv
-	RPM_SUSE_BUILDTOOL_DEPS += nasm
 endif
 endif
 
diff --git a/dpdk/Makefile b/dpdk/Makefile
index 01e2e44..9c9708c 100644
--- a/dpdk/Makefile
+++ b/dpdk/Makefile
@@ -34,6 +34,12 @@
 DPDK_SOURCE := $(B)/dpdk-$(DPDK_VERSION)
 MACHINE=$(shell uname -m)
 
+NASM_BASE_URL := http://www.nasm.us/pub/nasm/releasebuilds
+NASM_VER := 2.13.01
+NASM_TARBALL := nasm-$(NASM_VER).tar.xz
+NASM_TAR_URL := $(NASM_BASE_URL)/$(NASM_VER)/$(NASM_TARBALL)
+NASM_SOURCE := $(B)/nasm-$(NASM_VER)
+
 ISA_L_CRYPTO_LIB := n
 
 IPSEC_MB_VER ?= 0.46
@@ -225,6 +231,12 @@
 	fi
 	@rm -f $(B)/.download.ok
 
+$(CURDIR)/$(NASM_TARBALL):
+	@if [ -e $(DPDK_DOWNLOAD_DIR)/$(NASM_TARBALL) ] ; \
+		then cp $(DPDK_DOWNLOAD_DIR)/$(NASM_TARBALL) $(CURDIR) ; \
+		else curl -o $(CURDIR)/$(NASM_TARBALL) -LO $(NASM_TAR_URL) ; \
+	fi
+
 $(CURDIR)/$(AESNIMB_LIB_TARBALL):
 	@if [ -e $(DPDK_DOWNLOAD_DIR)/$(AESNIMB_LIB_TARBALL) ] ; \
 		then cp $(DPDK_DOWNLOAD_DIR)/$(AESNIMB_LIB_TARBALL) $(CURDIR) ; \
@@ -239,6 +251,7 @@
 
 DPDK_DOWNLOADS = $(CURDIR)/$(DPDK_TARBALL)
 ifeq ($(AESNI),y)
+DPDK_DOWNLOADS += $(CURDIR)/$(NASM_TARBALL)
 DPDK_DOWNLOADS += $(CURDIR)/$(AESNIMB_LIB_TARBALL)
 endif
 ifeq ($(ISA_L_CRYPTO_LIB),y)
@@ -260,6 +273,8 @@
 	@echo --- extracting $(DPDK_TARBALL) ---
 	@tar --directory $(B) --extract --file $(CURDIR)/$(DPDK_TARBALL)
 ifeq ($(AESNI),y)
+	@echo --- extracting $(NASM_TARBALL) ---
+	@tar --directory $(B) --extract --file $(CURDIR)/$(NASM_TARBALL)
 	@echo --- extracting $(AESNIMB_LIB_TARBALL) ---
 	@tar --directory $(B) --extract --file $(CURDIR)/$(AESNIMB_LIB_TARBALL)
 endif
@@ -292,12 +307,16 @@
 .PHONY: config
 config: $(B)/.config.ok
 
+.PHONY: build-nasm
+build-nasm:
+	cd $(NASM_SOURCE) && sh configure && make -j
+
 .PHONY: build-ipsec-mb
 build-ipsec-mb:
 	mkdir -p $(I)/lib/
 	# Do not build GCM stuff if we are building ISA_L
 	make -C $(AESNIMB_LIB_SOURCE) -j NO_GCM=$(ISA_L_CRYPTO_LIB) \
-	  DEBUG=$(DPDK_DEBUG) EXTRA_CFLAGS=-fPIC
+	  DEBUG=$(DPDK_DEBUG) EXTRA_CFLAGS=-fPIC NASM=$(NASM_SOURCE)/nasm
 	cp $(AESNIMB_LIB_SOURCE)/libIPSec_MB.a $(I)/lib/
 
 .PHONY: build-isal-crypto
@@ -316,6 +335,7 @@
 
 # Order matters
 ifeq ($(AESNI),y)
+BUILD_TARGETS += build-nasm
 BUILD_TARGETS += build-ipsec-mb
 endif
 ifeq ($(ISA_L_CRYPTO_LIB),y)
diff --git a/extras/rpm/vpp.spec b/extras/rpm/vpp.spec
index 7490a16..6dc04b8 100644
--- a/extras/rpm/vpp.spec
+++ b/extras/rpm/vpp.spec
@@ -50,9 +50,6 @@
 BuildRequires: libffi-devel
 BuildRequires: glibc-static, java-1.8.0-openjdk, java-1.8.0-openjdk-devel yum-utils, redhat-lsb
 BuildRequires: apr-devel
-%if %{with aesni}
-BuildRequires: nasm
-%endif
 BuildRequires: numactl-devel
 BuildRequires: autoconf automake libtool byacc bison flex
 
diff --git a/extras/vagrant/update.sh b/extras/vagrant/update.sh
index 18bc257..3fb456b 100755
--- a/extras/vagrant/update.sh
+++ b/extras/vagrant/update.sh
@@ -44,8 +44,4 @@
     # Standard update + upgrade dance
     yum check-update
     yum update -y
-elif [ "$OS_ID" == "opensuse" ]; then
-    zypper update -y
-    # NASM >= 2.12 is not available in previous openSUSE release; need to install it from TW
-    zypper install -y https://download.opensuse.org/tumbleweed/repo/oss/suse/x86_64/nasm-2.13.01-2.1.x86_64.rpm
 fi