diff --git a/gpakosz/whereami/f15606a65908bb097e1887a08a40ae083e9a5c53/CMakeLists.txt b/gpakosz/whereami/f15606a65908bb097e1887a08a40ae083e9a5c53/CMakeLists.txt new file mode 100644 index 0000000..1502af0 --- /dev/null +++ b/gpakosz/whereami/f15606a65908bb097e1887a08a40ae083e9a5c53/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.12) +project(whereami C) + +if (WIN32 AND BUILD_SHARED_LIBS) + set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) +endif() + +add_library(${CMAKE_PROJECT_NAME} src/whereami.c src/whereami.h) +target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src) +set_property(TARGET ${CMAKE_PROJECT_NAME} PROPERTY C_STANDARD 99) + +include(GNUInstallDirs) +install(TARGETS ${CMAKE_PROJECT_NAME}) +install(FILES src/whereami.h DESTINATION include) diff --git a/gpakosz/whereami/f15606a65908bb097e1887a08a40ae083e9a5c53/whereami_llar.gox b/gpakosz/whereami/f15606a65908bb097e1887a08a40ae083e9a5c53/whereami_llar.gox new file mode 100644 index 0000000..6c968de --- /dev/null +++ b/gpakosz/whereami/f15606a65908bb097e1887a08a40ae083e9a5c53/whereami_llar.gox @@ -0,0 +1,119 @@ +import ( + "os" + "path/filepath" + "slices" + "strings" +) + +const consumerSource = `#include +#include +#include + +int main(void) { + int length = wai_getExecutablePath(NULL, 0, NULL); + if (length <= 0) { + return 1; + } + + char* path = (char*)malloc((size_t)length + 1); + if (!path) { + return 1; + } + + int dirname_length = 0; + if (wai_getExecutablePath(path, length, &dirname_length) != length) { + free(path); + return 1; + } + path[length] = '\0'; + printf("Executable path: %s\n", path); + + length = wai_getModulePath(NULL, 0, NULL); + if (length <= 0) { + free(path); + return 1; + } + free(path); + return 0; +} +` + +id "gpakosz/whereami" + +fromVer "f15606a65908bb097e1887a08a40ae083e9a5c53" + +defaults { + "shared": "OFF", + "fPIC": "ON", +} + +filter => { + for name, values in target.options { + if name != "shared" && name != "fPIC" { + return false + } + for value in values { + if value != "ON" && value != "OFF" { + return false + } + } + } + return true +} + +onBuild ctx => { + installDir := ctx.outputDir + cMakeLists := ctx.Proj.readFile("f15606a65908bb097e1887a08a40ae083e9a5c53/CMakeLists.txt")! + os.writeFile(filepath.join(ctx.SourceDir, "CMakeLists.txt"), cMakeLists, 0o644)! + + shared := slices.contains(target.options["shared"], "ON") + fPIC := slices.contains(target.options["fPIC"], "ON") + c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir) + c.define "CMAKE_INSTALL_LIBDIR", "lib" + c.defineBool "BUILD_SHARED_LIBS", shared + c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC + c.configure + c.build + c.install + + licenseDir := filepath.join(installDir, "licenses") + os.mkdirAll(licenseDir, 0o755)! + for name in []string{"LICENSE.MIT", "LICENSE.WTFPLv2"} { + license := os.readFile(filepath.join(ctx.SourceDir, name))! + os.writeFile(filepath.join(licenseDir, name), license, 0o644)! + } + + metadata := []string{ + "-I" + filepath.join(installDir, "include"), + "-L" + filepath.join(installDir, "lib"), + "-lwhereami", + } + ctx.setMetadata strings.join(metadata, " ") +} + +onTest ctx => { + installDir := ctx.outputDir + testDir := filepath.join(ctx.SourceDir, "_llar_consumer") + testSource := filepath.join(testDir, "consumer.c") + testBuild := filepath.join(testDir, "_build") + binary := filepath.join(testBuild, "consumer") + os.mkdirAll(testDir, 0o755)! + os.writeFile(testSource, []byte(consumerSource), 0o644)! + + args := []string{ + testSource, + "-I" + filepath.join(installDir, "include"), + "-L" + filepath.join(installDir, "lib"), + "-lwhereami", + "-o", binary, + } + exec "cc", args... + lastErr! + + if slices.contains(target.options["shared"], "ON") { + os.setenv("LD_LIBRARY_PATH", filepath.join(installDir, "lib"))! + os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))! + } + exec binary + lastErr! +} diff --git a/gpakosz/whereami/versions.json b/gpakosz/whereami/versions.json new file mode 100644 index 0000000..082c4a7 --- /dev/null +++ b/gpakosz/whereami/versions.json @@ -0,0 +1,4 @@ +{ + "path": "gpakosz/whereami", + "deps": {} +}