diff --git a/Makefile b/Makefile index 4c2b631..4487f0a 100644 --- a/Makefile +++ b/Makefile @@ -65,27 +65,20 @@ detected_OS := $(shell uname -s) endif BUILD_COMMAND ?= libsdsDynamic - -ifeq ($(detected_OS),Windows) - LIB_EXT_DYNAMIC = dll - LIB_EXT_STATIC = lib -else ifeq ($(detected_OS),Darwin) - LIB_EXT_DYNAMIC = dylib - LIB_EXT_STATIC = a -else ifeq ($(detected_OS),Linux) - LIB_EXT_DYNAMIC = so - LIB_EXT_STATIC = a -endif - -LIB_EXT := $(LIB_EXT_DYNAMIC) - ifeq ($(STATIC), 1) - LIB_EXT = $(LIB_EXT_STATIC) BUILD_COMMAND = libsdsStatic endif +ifeq ($(detected_OS),Windows) + BUILD_COMMAND := $(BUILD_COMMAND)Windows +else ifeq ($(detected_OS),Darwin) + BUILD_COMMAND := $(BUILD_COMMAND)Mac +else ifeq ($(detected_OS),Linux) + BUILD_COMMAND := $(BUILD_COMMAND)Linux +endif + libsds: | deps - echo -e $(BUILD_MSG) "build/$@.$(LIB_EXT)" && $(ENV_SCRIPT) nim $(BUILD_COMMAND) $(NIM_PARAMS) sds.nims + $(ENV_SCRIPT) nim $(BUILD_COMMAND) $(NIM_PARAMS) sds.nims ##################### ## Mobile Bindings ## diff --git a/sds.nimble b/sds.nimble index 305e96e..3e70507 100644 --- a/sds.nimble +++ b/sds.nimble @@ -11,7 +11,13 @@ srcDir = "src" requires "nim >= 2.2.4", "chronicles", "chronos", "stew", "stint", "metrics", "libp2p", "results" -proc buildLibrary(name: string, srcDir = "./", params = "", `type` = "static") = +proc buildLibrary( + outLibNameAndExt: string, + name: string, + srcDir = "./", + params = "", + `type` = "static", +) = if not dirExists "build": mkDir "build" # allow something like "nim nimbus --verbosity:0 --hints:off nimbus.nims" @@ -19,17 +25,16 @@ proc buildLibrary(name: string, srcDir = "./", params = "", `type` = "static") = for i in 2 ..< paramCount(): extra_params &= " " & paramStr(i) if `type` == "static": - exec "nim c" & " --out:build/" & name & - ".a --threads:on --app:staticlib --opt:size --noMain --mm:refc --header --nimMainPrefix:libsds --skipParentCfg:on " & + exec "nim c" & " --out:build/" & outLibNameAndExt & + " --threads:on --app:staticlib --opt:size --noMain --mm:refc --header --nimMainPrefix:libsds --skipParentCfg:on " & extra_params & " " & srcDir & name & ".nim" else: - let lib_name = (when defined(windows): toDll(name) else: name & ".so") when defined(windows): - exec "nim c" & " --out:build/" & lib_name & + exec "nim c" & " --out:build/" & outLibNameAndExt & " --threads:on --app:lib --opt:size --noMain --mm:refc --header --nimMainPrefix:libsds --skipParentCfg:off " & extra_params & " " & srcDir & name & ".nim" else: - exec "nim c" & " --out:build/" & lib_name & + exec "nim c" & " --out:build/" & outLibNameAndExt & " --threads:on --app:lib --opt:size --noMain --mm:refc --header --nimMainPrefix:libsds --skipParentCfg:on " & extra_params & " " & srcDir & name & ".nim" @@ -38,13 +43,54 @@ task test, "Run the test suite": exec "nim c -r tests/test_bloom.nim" exec "nim c -r tests/test_reliability.nim" -task libsdsDynamic, "Generate bindings": +task libsdsDynamicWindows, "Generate bindings": + let outLibNameAndExt = "libsds.dll" let name = "libsds" - buildLibrary name, - "library/", + buildLibrary outLibNameAndExt, + name, "library/", """-d:chronicles_line_numbers --warning:Deprecated:off --warning:UnusedImport:on -d:chronicles_log_level=TRACE """, "dynamic" +task libsdsDynamicLinux, "Generate bindings": + let outLibNameAndExt = "libsds.so" + let name = "libsds" + buildLibrary outLibNameAndExt, + name, "library/", + """-d:chronicles_line_numbers --warning:Deprecated:off --warning:UnusedImport:on -d:chronicles_log_level=TRACE """, + "dynamic" + +task libsdsDynamicMac, "Generate bindings": + let outLibNameAndExt = "libsds.dylib" + let name = "libsds" + buildLibrary outLibNameAndExt, + name, "library/", + """-d:chronicles_line_numbers --warning:Deprecated:off --warning:UnusedImport:on -d:chronicles_log_level=TRACE """, + "dynamic" + +task libsdsStaticWindows, "Generate bindings": + let outLibNameAndExt = "libsds.lib" + let name = "libsds" + buildLibrary outLibNameAndExt, + name, "library/", + """-d:chronicles_line_numbers --warning:Deprecated:off --warning:UnusedImport:on -d:chronicles_log_level=TRACE """, + "static" + +task libsdsStaticLinux, "Generate bindings": + let outLibNameAndExt = "libsds.a" + let name = "libsds" + buildLibrary outLibNameAndExt, + name, "library/", + """-d:chronicles_line_numbers --warning:Deprecated:off --warning:UnusedImport:on -d:chronicles_log_level=TRACE """, + "static" + +task libsdsStaticMac, "Generate bindings": + let outLibNameAndExt = "libsds.a" + let name = "libsds" + buildLibrary outLibNameAndExt, + name, "library/", + """-d:chronicles_line_numbers --warning:Deprecated:off --warning:UnusedImport:on -d:chronicles_log_level=TRACE """, + "static" + ### Mobile Android proc buildMobileAndroid(srcDir = ".", params = "") = let cpu = getEnv("CPU")