diff options
| -rw-r--r-- | exports/Makefile | 14 | ||||
| -rw-r--r-- | exports/platform.mk | 23 | ||||
| -rw-r--r-- | wrappers/php/Makefile | 11 | ||||
| -rw-r--r-- | wrappers/php/src/Impl/GoSlice.php | 4 | ||||
| -rw-r--r-- | wrappers/swift/Makefile | 5 |
5 files changed, 29 insertions, 28 deletions
diff --git a/exports/Makefile b/exports/Makefile index b3dc3db..547ee92 100644 --- a/exports/Makefile +++ b/exports/Makefile @@ -1,18 +1,6 @@ .PHONY: build copy-to clean -GOOS != go env GOHOSTOS -GOARCH != go env GOHOSTARCH - -ifeq (windows,$(GOOS)) -LIB_PREFIX = -LIB_SUFFIX = .dll -else ifeq (darwin,$(GOOS)) -LIB_PREFIX = lib -LIB_SUFFIX = .dylib -else -LIB_PREFIX = lib -LIB_SUFFIX = .so -endif +include platform.mk # Creates targets like 'linux/amd64/eduvpn_verify.so' build: $(GOOS)/$(GOARCH)/$(LIB_PREFIX)eduvpn_verify$(LIB_SUFFIX) diff --git a/exports/platform.mk b/exports/platform.mk new file mode 100644 index 0000000..60f47ee --- /dev/null +++ b/exports/platform.mk @@ -0,0 +1,23 @@ +ifndef GOOS +export GOOS != go env GOHOSTOS +endif +ifndef GOARCH +export GOARCH != go env GOHOSTARCH +endif + +ifeq (windows,$(GOOS)) +LIB_PREFIX = +LIB_SUFFIX = .dll +else ifeq (darwin,$(GOOS)) +LIB_PREFIX = lib +LIB_SUFFIX = .dylib +else +LIB_PREFIX = lib +LIB_SUFFIX = .so +endif + +ifeq (Windows_NT,$(OS)) +export PATH := $(abspath ../../exports/$(GOOS)/$(GOARCH)):$(PATH) +else +export LD_LIBRARY_PATH := $(abspath ../../exports/$(GOOS)/$(GOARCH)):$(LD_LIBRARY_PATH) +endif diff --git a/wrappers/php/Makefile b/wrappers/php/Makefile index bab4305..06c49f1 100644 --- a/wrappers/php/Makefile +++ b/wrappers/php/Makefile @@ -1,16 +1,9 @@ .PHONY: install-header test install-dev-dependencies clean ifneq (clean,$(MAKECMDGOALS)) -GOOS != go env GOHOSTOS -GOARCH != go env GOHOSTARCH +include ../../exports/platform.mk export PATH := $(abspath vendor/bin):$(PATH) - -ifeq (Windows_NT,$(OS)) -export PATH := $(abspath ../../exports/$(GOOS)/$(GOARCH)):$(PATH) -else -export LD_LIBRARY_PATH := $(abspath ../../exports/$(GOOS)/$(GOARCH)):$(LD_LIBRARY_PATH) -endif endif install-header: @@ -21,7 +14,7 @@ install-header: -e 's/__SIZE_TYPE__/size_t/g' \ -e 's/[^\n]*_Complex[^\n]*//g' \ -e 's/#ifdef __cplusplus[^#]*#endif//g' \ - -e 's/^/#define FFI_LIB "eduvpn_verify"\n\n/' \ + -e 's/^/#define FFI_LIB "$(LIB_PREFIX)eduvpn_verify$(LIB_SUFFIX)"\n\n/' \ "../../exports/$(GOOS)/$(GOARCH)/eduvpn_verify.h" > src/headers/eduvpn_verify_php.h test: install-header install-dev-dependencies diff --git a/wrappers/php/src/Impl/GoSlice.php b/wrappers/php/src/Impl/GoSlice.php index 441b460..b285cfd 100644 --- a/wrappers/php/src/Impl/GoSlice.php +++ b/wrappers/php/src/Impl/GoSlice.php @@ -18,12 +18,12 @@ class GoSlice { $len = strlen($data); $cData = FFI::new(FFI::arrayType(FFI::type('char'), [$len]), false); - if (!$cData) throw new RuntimeException('error allocating buffer'); + if ($cData === null) throw new RuntimeException('error allocating buffer'); $this->cData = $cData; FFI::memcpy($cData, $data, $len); $slice = $ffi->new('GoSlice'); - if (!$slice) throw new RuntimeException('error allocating buffer'); + if ($slice === null) throw new RuntimeException('error allocating buffer'); $this->slice = $slice; $slice->data = FFI::addr($cData); // $cData must not be destroyed while $slice is in use $slice->cap = $slice->len = $len; diff --git a/wrappers/swift/Makefile b/wrappers/swift/Makefile index 826dde3..84b3cc1 100644 --- a/wrappers/swift/Makefile +++ b/wrappers/swift/Makefile @@ -1,15 +1,12 @@ .PHONY: build test clean ifneq (clean,$(MAKECMDGOALS)) -GOOS != go env GOHOSTOS -GOARCH != go env GOHOSTARCH +include ../../exports/platform.mk ifeq (Windows_NT,$(OS)) SWIFT = ./swift.cmd -export PATH := $(abspath ../../exports/$(GOOS)/$(GOARCH)):$(PATH) else SWIFT = swift -export LD_LIBRARY_PATH := $(abspath ../../exports/$(GOOS)/$(GOARCH)):$(LD_LIBRARY_PATH) endif endif |
