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..601dc61 --- /dev/null +++ b/gpakosz/whereami/f15606a65908bb097e1887a08a40ae083e9a5c53/whereami_llar.gox @@ -0,0 +1,123 @@ +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)! + } + + pcDir := filepath.join(installDir, "lib", "pkgconfig") + os.mkdirAll(pcDir, 0o755)! + pc := `prefix=$${pcfiledir}/../.. +includedir=$${prefix}/include +libdir=$${prefix}/lib + +Name: whereami +Description: A drop-in two files library to locate the current executable and the current module on the file system +Version: f15606a65908bb097e1887a08a40ae083e9a5c53 +Libs: -L$${libdir} -lwhereami +Cflags: -I$${includedir} +` + os.writeFile(filepath.join(pcDir, "whereami.pc"), []byte(pc), 0o644)! + + pkgconfig.use installDir + ctx.setMetadata pkgconfig.lookup("whereami")! +} + +onTest ctx => { + installDir := ctx.outputDir + testDir := os.mkdirTemp("", "whereami-consumer-")! + defer os.removeAll(testDir) + testSource := filepath.join(testDir, "consumer.c") + binary := filepath.join(testDir, "consumer") + os.writeFile(testSource, []byte(consumerSource), 0o644)! + + pkgconfig.use installDir + args := []string{testSource} + args <- strings.fields(pkgconfig.lookup("whereami")!)... + args <- "-o", binary + cc! args... + + 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 +} 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": {} +}