Skip to content

Commit

Permalink
Add support for more Linux/Windows platforms (#2)
Browse files Browse the repository at this point in the history
The following platforms are added:
- linuxArm64
- linuxArm32Hfp
- mingwX86
  • Loading branch information
39aldo39 committed May 7, 2021
1 parent 8dd3997 commit 8786487
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 36 deletions.
22 changes: 18 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
prefix?=/usr
BUILD_DIR=build/bin/linuxX64/releaseShared

INSTALL=install
RM=rm -f

uname_m := $(shell uname -m)
ifeq ($(uname_m),x86_64)
platform=linuxX64
else ifeq ($(uname_m:arm%=),)
bits := $(shell getconf LONG_BIT)
ifeq ($(bits),64)
platform=linuxArm64
else
platform=linuxArm32Hfp
endif
else
$(error Unsupported platform $(uname_m))
endif

BUILD_DIR=build/bin/$(platform)/releaseShared
SOURCES=$(wildcard src/*/kotlin/org/decsync/library/*.kt)
PC_PREFIX:=prefix=$(prefix)

.PHONY: all
all: $(BUILD_DIR)/libdecsync_api.h $(BUILD_DIR)/libdecsync.so $(BUILD_DIR)/decsync.pc

$(BUILD_DIR)/libdecsync_api.h $(BUILD_DIR)/libdecsync.so: $(SOURCES)
./gradlew linkReleaseSharedLinuxX64
./gradlew linkReleaseShared$(platform)

$(BUILD_DIR)/decsync.pc: src/linuxX64Main/decsync.pc.in
$(file > $(BUILD_DIR)/decsync.pc,$(PC_PREFIX))
cat src/linuxX64Main/decsync.pc.in >> $(BUILD_DIR)/decsync.pc
cat src/linuxMain/decsync.pc.in >> $(BUILD_DIR)/decsync.pc

.PHONY: install
install: $(BUILD_DIR)/libdecsync_api.h $(BUILD_DIR)/libdecsync.so $(BUILD_DIR)/decsync.pc
$(INSTALL) -d $(DESTDIR)$(prefix)/include
$(INSTALL) -m 644 $(BUILD_DIR)/libdecsync_api.h $(DESTDIR)$(prefix)/include
$(INSTALL) -m 644 src/linuxX64Main/libdecsync.h $(DESTDIR)$(prefix)/include
$(INSTALL) -m 644 src/linuxMain/libdecsync.h $(DESTDIR)$(prefix)/include
$(INSTALL) -d $(DESTDIR)$(prefix)/lib
$(INSTALL) -m 644 $(BUILD_DIR)/libdecsync.so $(DESTDIR)$(prefix)/lib
$(INSTALL) -d $(DESTDIR)$(prefix)/share/pkgconfig
Expand Down
48 changes: 42 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,34 @@ kotlin {
}
}
}
linuxArm64 {
binaries {
sharedLib {
baseName = "decsync"
}
}
}
linuxArm32Hfp {
binaries {
sharedLib {
baseName = "decsync"
}
}
}
mingwX64 {
binaries {
sharedLib {
baseName = "decsync"
}
}
}
mingwX86 {
binaries {
sharedLib {
baseName = "decsync"
}
}
}

sourceSets {
commonMain {
Expand All @@ -104,17 +125,32 @@ kotlin {
nativeTest {
dependsOn commonTest
}
linuxX64Main {
linuxMain {
dependsOn nativeMain
}
linuxX64Test {
dependsOn nativeTest
linux64Main {
dependsOn linuxMain
}
mingwX64Main {
linux32Main {
dependsOn linuxMain
}
linuxX64Main {
dependsOn linux64Main
}
linuxArm64Main {
dependsOn linux64Main
}
linuxArm32HfpMain {
dependsOn linux32Main
}
windowsMain {
dependsOn nativeMain
}
mingwX64Test {
dependsOn nativeTest
mingwX64Main {
dependsOn windowsMain
}
mingwX86Main {
dependsOn windowsMain
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@

package org.decsync.library

import kotlinx.cinterop.*
import platform.posix.*

actual fun Int.off_t(): off_t = this
actual fun gethostnameCustom(name: CValuesRef<ByteVar>, size: Int): Int = gethostname(name, size)

actual fun getDefaultDecsyncDir(): String =
getenv("DECSYNC_DIR")?.toKString() ?: getenv("USERPROFILE")!!.toKString() + "/DecSync"
actual fun Int.size_t(): size_t = this.toUInt()
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* libdecsync - NativeFile.kt
* libdecsync - Utils.kt
*
* Copyright (C) 2019 Aldo Gunsing
*
Expand All @@ -18,16 +18,7 @@

package org.decsync.library

import kotlinx.cinterop.*
import platform.posix.*

actual val openFlagsBinary = 0
actual fun mkdirCustom(path: String, mode: Int) {
mkdir(path, mode.toUInt())
}
actual fun readCustom(fd: Int, buf: CValuesRef<*>?, len: Int) {
read(fd, buf, len.toULong())
}
actual fun writeCustom(fd: Int, buf: CValuesRef<*>?, size: Int) {
write(fd, buf, size.toULong())
}
actual fun Int.off_t(): off_t = this.toLong()
actual fun Int.size_t(): size_t = this.toULong()
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,19 @@ package org.decsync.library
import kotlinx.cinterop.*
import platform.posix.*

actual fun Int.off_t(): off_t = this.toLong()
actual fun gethostnameCustom(name: CValuesRef<ByteVar>, size: Int): Int = gethostname(name, size.toULong())
expect fun Int.size_t(): size_t

actual val openFlagsBinary = 0
actual fun mkdirCustom(path: String, mode: Int) {
mkdir(path, mode.toUInt())
}
actual fun readCustom(fd: Int, buf: CValuesRef<*>?, len: Int) {
read(fd, buf, len.size_t())
}
actual fun writeCustom(fd: Int, buf: CValuesRef<*>?, size: Int) {
write(fd, buf, size.size_t())
}
actual fun gethostnameCustom(name: CValuesRef<ByteVar>, size: Int): Int = gethostname(name, size.size_t())

actual fun getDefaultDecsyncDir(): String =
getenv("DECSYNC_DIR")?.toKString() ?: getUserDataDir() + "/decsync"
Expand Down
File renamed without changes.
6 changes: 1 addition & 5 deletions src/nativeMain/kotlin/org/decsync/library/NativeFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ package org.decsync.library
import kotlinx.cinterop.*
import platform.posix.*

expect val openFlagsBinary: Int
const val createModeDir = S_IRWXU or S_IRGRP or S_IXGRP or S_IROTH or S_IXOTH
const val createModeFile = S_IRUSR or S_IWUSR or S_IRGRP or S_IROTH
expect fun mkdirCustom(path: String, mode: Int)
expect fun readCustom(fd: Int, buf: CValuesRef<*>?, len: Int)
expect fun writeCustom(fd: Int, buf: CValuesRef<*>?, size: Int)

class RealFileImpl(private val path: String, name: String) : RealFile(name) {
override fun delete() {
Expand All @@ -53,7 +49,7 @@ class RealFileImpl(private val path: String, name: String) : RealFile(name) {
val buf = ByteArray(len - readBytes)
lseek(fd, readBytes.off_t(), SEEK_SET)
buf.usePinned { bufPin ->
readCustom(fd, bufPin.addressOf(0), len - readBytes)
readCustom(fd, bufPin.addressOf(0), (len - readBytes))
}
close(fd)
return buf
Expand Down
4 changes: 4 additions & 0 deletions src/nativeMain/kotlin/org/decsync/library/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import kotlinx.cinterop.*
import platform.posix.*

expect fun Int.off_t(): off_t
expect val openFlagsBinary: Int
expect fun mkdirCustom(path: String, mode: Int)
expect fun readCustom(fd: Int, buf: CValuesRef<*>?, len: Int)
expect fun writeCustom(fd: Int, buf: CValuesRef<*>?, size: Int)
expect fun gethostnameCustom(name: CValuesRef<ByteVar>, size: Int): Int

actual fun getDeviceName(): String {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* libdecsync - NativeFile.kt
* libdecsync - Utils.kt
*
* Copyright (C) 2019 Aldo Gunsing
*
Expand All @@ -21,6 +21,7 @@ package org.decsync.library
import kotlinx.cinterop.*
import platform.posix.*

actual fun Int.off_t(): off_t = this
actual val openFlagsBinary = O_BINARY
actual fun mkdirCustom(path: String, mode: Int) {
mkdir(path)
Expand All @@ -30,4 +31,8 @@ actual fun readCustom(fd: Int, buf: CValuesRef<*>?, len: Int) {
}
actual fun writeCustom(fd: Int, buf: CValuesRef<*>?, size: Int) {
write(fd, buf, size.toUInt())
}
}
actual fun gethostnameCustom(name: CValuesRef<ByteVar>, size: Int): Int = gethostname(name, size)

actual fun getDefaultDecsyncDir(): String =
getenv("DECSYNC_DIR")?.toKString() ?: getenv("USERPROFILE")!!.toKString() + "/DecSync"

0 comments on commit 8786487

Please sign in to comment.