diff options
| author | StevenWdV <stevenwdv@gmail.com> | 2022-02-04 01:18:12 +0100 |
|---|---|---|
| committer | StevenWdV <stevenwdv@gmail.com> | 2022-02-04 01:18:12 +0100 |
| commit | b60ecf2fe5ddfe506e02093286b3931873187e91 (patch) | |
| tree | b3804b1b95e70e96dec98cb0c2b571e0b895ebdd /exports | |
| parent | bb85487e40b47d701e64085e7574cb477a431f1e (diff) | |
More Makefile cleanup, support building in folder with spaces
Diffstat (limited to 'exports')
| -rw-r--r-- | exports/Makefile | 4 | ||||
| -rw-r--r-- | exports/common.mk | 44 | ||||
| -rw-r--r-- | exports/platform.mk | 33 |
3 files changed, 46 insertions, 35 deletions
diff --git a/exports/Makefile b/exports/Makefile index 67ddc61..cfb9604 100644 --- a/exports/Makefile +++ b/exports/Makefile @@ -1,6 +1,6 @@ .PHONY: build copy-to clean -include platform.mk +include common.mk ifeq ($(LIB_SUFFIX),.so) # Add SONAME as cgo does not currently do this. Mostly for Android, see https://stackoverflow.com/a/48291044 @@ -11,7 +11,7 @@ endif build: lib/$(GOOS)/$(GOARCH)/$(LIB_FILE) # Build shared library and remove lib prefix (if any) from header name -# GOOS and GOARCH envvars are set by platform.mk +# GOOS and GOARCH envvars are set by common.mk # This extra target prevents unnecessary rebuild lib/$(GOOS)/$(GOARCH)/$(LIB_FILE): exports.go ../verify.go CGO_ENABLED=1 go build -o $@ -buildmode=c-shared $< diff --git a/exports/common.mk b/exports/common.mk new file mode 100644 index 0000000..f2757c2 --- /dev/null +++ b/exports/common.mk @@ -0,0 +1,44 @@ +# Prevent executing `go env ...` multiple times for the same property +# export is needed for this and also to pass the values on to the Go compiler +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 + +# Library name without prefixes/suffixes +LIB_NAME ?= eduvpn_common +# Library file name +LIB_FILE ?= $(LIB_PREFIX)$(LIB_NAME)$(LIB_SUFFIX) + +# Get exports/ directory when included from a wrapper +EXPORTS_PATH = $(dir $(lastword $(MAKEFILE_LIST))) +# Remove trailing slash +EXPORTS_PATH := $(EXPORTS_PATH:/=) + +EXPORTS_LIB_PATH ?= $(EXPORTS_PATH)/lib +EXPORTS_LIB_SUBFOLDER_PATH ?= $(EXPORTS_LIB_PATH)/$(GOOS)/$(GOARCH) + +# Add library to dynamic linker path for running tests +ifeq (Windows_NT,$(OS)) +export PATH := $(abspath $(EXPORTS_LIB_SUBFOLDER_PATH)):$(PATH) +else +export LD_LIBRARY_PATH := $(abspath $(EXPORTS_LIB_SUBFOLDER_PATH)):$(LD_LIBRARY_PATH) +endif + +.try_build_lib: +ifneq ($(wildcard $(EXPORTS_PATH)/Makefile),) + $(MAKE) -C $(EXPORTS_PATH) +endif diff --git a/exports/platform.mk b/exports/platform.mk deleted file mode 100644 index cd1248b..0000000 --- a/exports/platform.mk +++ /dev/null @@ -1,33 +0,0 @@ -# Prevent executing `go env ...` multiple times for the same property -# export is needed for this and also to pass the values on to the Go compiler -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 - -# Library name without prefixes/suffixes -LIB_NAME = eduvpn_common -# Library file name -LIB_FILE = $(LIB_PREFIX)$(LIB_NAME)$(LIB_SUFFIX) - -# Get exports/ directory when included from a wrapper -exports_dir = $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) -# Add library to dynamic linker path for running tests -ifeq (Windows_NT,$(OS)) -export PATH := $(exports_dir)/lib/$(GOOS)/$(GOARCH):$(PATH) -else -export LD_LIBRARY_PATH := $(exports_dir)/lib/$(GOOS)/$(GOARCH):$(LD_LIBRARY_PATH) -endif |
