--- phc-winner-argon2-20190702/Makefile.orig	2019-05-20 12:18:00.000000000 +0300
+++ phc-winner-argon2-20190702/Makefile	2019-07-03 08:38:14.045372200 +0300
@@ -36,6 +36,12 @@
 SRC_BENCH = src/bench.c
 SRC_GENKAT = src/genkat.c
 OBJ = $(SRC:.c=.o)
+AR ?= ar
+LN_S = 'ln -s'
+TAR ?= 'tar'
+MKDIR ?= 'mkdir -p'
+RM ?= 'rm -f'
+RMDIR ?= 'rm -rf'
 
 CFLAGS += -std=c89 -O3 -Wall -g -Iinclude -Isrc
 
@@ -51,6 +57,16 @@
 OPTTARGET ?= native
 OPTTEST := $(shell $(CC) -Iinclude -Isrc -march=$(OPTTARGET) src/opt.c -c \
 			-o /dev/null 2>/dev/null; echo $$?)
+# Try with -msse2 flag
+ifneq ($(OPTTEST), 0)
+OPTTEST := $(shell $(CC) -Iinclude -Isrc -march=$(OPTTARGET) -msse2 src/opt.c -c \
+			-o /dev/null 2>/dev/null; echo $$?)
+#if we have -msse2 flag, use it
+ifeq ($(OPTTEST), 0)
+	CFLAGS += -msse2
+	CI_CFLAGS += -msse2
+endif
+endif
 # Detect compatible platform
 ifneq ($(OPTTEST), 0)
 $(info Building without optimizations)
@@ -66,6 +82,7 @@
 MACHINE_NAME := $(shell uname -m)
 
 LIB_NAME = argon2
+LIB_SH_RT=
 PC_NAME = lib$(LIB_NAME).pc
 PC_SRC = $(PC_NAME).in
 
@@ -73,7 +90,7 @@
 	LIB_EXT := so.$(ABI_VERSION)
 	LIB_CFLAGS := -shared -fPIC -fvisibility=hidden -DA2_VISCTL=1
 	SO_LDFLAGS := -Wl,-soname,lib$(LIB_NAME).$(LIB_EXT)
-	LINKED_LIB_EXT := so
+	LN_SED_LIB_EXT := so
 	PC_EXTRA_LIBS ?= -lrt -ldl
 endif
 ifeq ($(KERNEL_NAME), $(filter $(KERNEL_NAME),DragonFly FreeBSD NetBSD OpenBSD))
@@ -84,21 +101,27 @@
 ifeq ($(KERNEL_NAME), Darwin)
 	LIB_EXT := $(ABI_VERSION).dylib
 	LIB_CFLAGS := -dynamiclib -install_name @rpath/lib$(LIB_NAME).$(LIB_EXT)
-	LINKED_LIB_EXT := dylib
+	LN_SED_LIB_EXT := dylib
 	PC_EXTRA_LIBS ?=
 endif
 ifeq ($(findstring CYGWIN, $(KERNEL_NAME)), CYGWIN)
 	LIB_EXT := dll
+	LN_S = 'cp -p'
+	LIB_SH_RT := cyg$(LIB_NAME).$(LIB_EXT)
 	LIB_CFLAGS := -shared -Wl,--out-implib,lib$(LIB_NAME).$(LIB_EXT).a
 	PC_EXTRA_LIBS ?=
 endif
 ifeq ($(findstring MINGW, $(KERNEL_NAME)), MINGW)
 	LIB_EXT := dll
+	LN_S = 'cp -p'
+	LIB_SH_RT := lib$(LIB_NAME).$(LIB_EXT)
 	LIB_CFLAGS := -shared -Wl,--out-implib,lib$(LIB_NAME).$(LIB_EXT).a
 	PC_EXTRA_LIBS ?=
 endif
 ifeq ($(findstring MSYS, $(KERNEL_NAME)), MSYS)
 	LIB_EXT := dll
+	LN_S = 'cp -p'
+	LIB_SH_RT := msys-$(LIB_NAME).$(LIB_EXT)
 	LIB_CFLAGS := -shared -Wl,--out-implib,lib$(LIB_NAME).$(LIB_EXT).a
 	PC_EXTRA_LIBS ?=
 endif
@@ -116,11 +139,15 @@
 endif
 endif
 
+ifeq ($(LIB_SH_RT),)
 LIB_SH := lib$(LIB_NAME).$(LIB_EXT)
+else
+LIB_SH := lib$(LIB_NAME).$(LIB_EXT).a
+endif
 LIB_ST := lib$(LIB_NAME).a
 
-ifdef LINKED_LIB_EXT
-LINKED_LIB_SH := lib$(LIB_NAME).$(LINKED_LIB_EXT)
+ifdef LN_SED_LIB_EXT
+LN_SED_LIB_SH := lib$(LIB_NAME).$(LN_SED_LIB_EXT)
 endif
 
 
@@ -178,21 +205,28 @@
 $(GENKAT):      $(SRC) $(SRC_GENKAT)
 		$(CC) $(CFLAGS) $^ -o $@ -DGENKAT
 
+ifeq ($(LIB_SH_RT),)
 $(LIB_SH): 	$(SRC)
 		$(CC) $(CFLAGS) $(LIB_CFLAGS) $(LDFLAGS) $(SO_LDFLAGS) $^ -o $@
+else
+$(LIB_SH_RT):	$(SRC)
+		$(CC) $(CFLAGS) $(LIB_CFLAGS) $(LDFLAGS) $(SO_LDFLAGS) $^ -o $@
+
+$(LIB_SH): 	$(LIB_SH_RT)
+endif
 
 $(LIB_ST): 	$(OBJ)
-		ar rcs $@ $^
+		$(AR) rcs $@ $^
 
 .PHONY: clean
 clean:
-		rm -f '$(RUN)' '$(BENCH)' '$(GENKAT)'
-		rm -f '$(LIB_SH)' '$(LIB_ST)' kat-argon2* '$(PC_NAME)'
-		rm -f testcase
-		rm -rf *.dSYM
-		cd src/ && rm -f *.o
-		cd src/blake2/ && rm -f *.o
-		cd kats/ &&  rm -f kat-* diff* run_* make_*
+		$(RM) '$(RUN)' '$(BENCH)' '$(GENKAT)'
+		$(RM) '$(LIB_SH)' '$(LIB_ST)' kat-argon2* '$(PC_NAME)'
+		$(RM) testcase
+		$(RMDIR) *.dSYM
+		cd src/ && $(RM) *.o
+		cd src/blake2/ && $(RM) *.o
+		cd kats/ &&  $(RM) kat-* diff* run_* make_*
 
 
 # all substitutions to pc template
@@ -211,7 +245,7 @@
 .PHONY: dist
 dist:
 		cd ..; \
-		tar -c --exclude='.??*' -z -f $(DIST)-`date "+%Y%m%d"`.tgz $(DIST)/*
+		$(TAR) -c --exclude='.??*' -z -f $(DIST)-`date "+%Y%m%d"`.tgz $(DIST)/*
 
 .PHONY: test
 test:           $(SRC) src/test.c
@@ -237,17 +271,28 @@
 	$(INSTALL) -m 0644 $(HEADERS) $(INST_INCLUDE)
 	$(INSTALL) -d $(INST_LIBRARY)
 	$(INSTALL) -m 0644 $(LIBRARIES) $(INST_LIBRARY)
-ifdef LINKED_LIB_SH
-	cd $(INST_LIBRARY) && ln -s $(notdir $(LIB_SH) $(LINKED_LIB_SH))
-endif
+ifneq ($(LIB_SH_RT),)
+	$(INSTALL) -d $(INST_BINARY)
+	$(INSTALL) -m 0755 $(LIB_SH_RT) $(INST_BINARY)
+	$(INSTALL) -m 0644 $(LIB_SH) $(INST_LIBRARY)
+	$(INSTALL) -m 0644 $(LIB_ST) $(INST_LIBRARY)
+else
 	$(INSTALL) -d $(INST_BINARY)
+endif
+ifdef LN_SED_LIB_SH
+	cd $(INST_LIBRARY) && $(LN_S) $(notdir $(LIB_SH) $(LN_SED_LIB_SH))
+endif
 	$(INSTALL) $(RUN) $(INST_BINARY)
 	$(INSTALL) -d $(INST_PKGCONFIG)
 	$(INSTALL) -m 0644 $(PC_NAME) $(INST_PKGCONFIG)
 
 .PHONY: uninstall
 uninstall:
-	cd $(INST_INCLUDE) && rm -f $(notdir $(HEADERS))
-	cd $(INST_LIBRARY) && rm -f $(notdir $(LIBRARIES) $(LINKED_LIB_SH))
-	cd $(INST_BINARY) && rm -f $(notdir $(RUN))
-	cd $(INST_PKG_CONFIG) && rm -f $(notdir $(PC_NAME))
+	cd $(INST_INCLUDE) && $(RM) $(notdir $(HEADERS))
+	cd $(INST_LIBRARY) && $(RM) $(notdir $(LIBRARIES) $(LN_SED_LIB_SH))
+ifneq ($(LIB_SH_RT),)
+	cd $(INST_BINARY) && $(RM) $(notdir $(LIB_SH_RT))
+endif
+	cd $(INST_BINARY) && $(RM) $(notdir $(RUN))
+	cd $(INST_PKG_CONFIG) && $(RM) $(notdir $(PC_NAME))
+
