aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2024-05-02 00:42:08 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2024-05-02 00:42:08 -0400
commita970d40094aca5ce43e3bf91b9a5a2323c41ead8 (patch)
treeebeed41a1ad333678b5da3892a8b65f3adcabf71
parent2f26379607d6829f598c03e06de6ebc0b38880d6 (diff)
downloadstasis-a970d40094aca5ce43e3bf91b9a5a2323c41ead8.tar.gz
Convert ohmycal to a library
-rw-r--r--CMakeLists.txt2
-rw-r--r--include/omc.h5
-rw-r--r--src/CMakeLists.txt13
-rw-r--r--src/globals.c51
-rw-r--r--src/omc_main.c (renamed from src/main.c)48
-rw-r--r--src/utils.c2
6 files changed, 69 insertions, 52 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ccd7e90..e9a001e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.15)
project(OMC C)
include(GNUInstallDirs)
-set(nix_cflags -Wall -Wextra)
+set(nix_cflags -Wall -Wextra -fPIC)
set(win_cflags /Wall)
set(CMAKE_C_STANDARD 99)
diff --git a/include/omc.h b/include/omc.h
index 3283a80..45f5671 100644
--- a/include/omc.h
+++ b/include/omc.h
@@ -85,6 +85,11 @@ struct OMC_GLOBAL {
char *url;
} jfrog;
};
+extern struct OMC_GLOBAL globals;
+extern const char *VERSION;
+extern const char *AUTHOR;
+extern const char *BANNER;
+
/**
* Free memory allocated in global configuration structure
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 102a4e5..752f78e 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -2,8 +2,8 @@ include_directories(${CMAKE_BINARY_DIR}/include)
include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${PROJECT_BINARY_DIR})
-add_executable(omc
- main.c
+add_library(ohmycal STATIC
+ globals.c
str.c
strlist.c
ini.c
@@ -22,4 +22,13 @@ add_executable(omc
rules.c
docker.c
)
+
+add_executable(omc
+ omc_main.c
+)
+target_link_libraries(omc ohmycal)
+add_executable(omc_indexer
+ omc_indexer.c
+)
+target_link_libraries(omc_indexer ohmycal)
install(TARGETS omc RUNTIME)
diff --git a/src/globals.c b/src/globals.c
new file mode 100644
index 0000000..fa45afc
--- /dev/null
+++ b/src/globals.c
@@ -0,0 +1,51 @@
+#include <stdlib.h>
+#include <stdbool.h>
+#include "omc.h"
+
+const char *VERSION = "1.0.0";
+const char *AUTHOR = "Joseph Hunkeler";
+const char *BANNER = "---------------------------------------------------------------------\n"
+ " ██████╗ ██╗ ██╗ ███╗ ███╗██╗ ██╗ ██████╗ █████╗ ██╗ \n"
+ "██╔═══██╗██║ ██║ ████╗ ████║╚██╗ ██╔╝ ██╔════╝██╔══██╗██║ \n"
+ "██║ ██║███████║ ██╔████╔██║ ╚████╔╝ ██║ ███████║██║ \n"
+ "██║ ██║██╔══██║ ██║╚██╔╝██║ ╚██╔╝ ██║ ██╔══██║██║ \n"
+ "╚██████╔╝██║ ██║ ██║ ╚═╝ ██║ ██║ ╚██████╗██║ ██║███████╗\n"
+ " ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚══════╝\n"
+ "---------------------------------------------------------------------\n"
+ " Delivery Generator \n"
+ " v%s \n"
+ "---------------------------------------------------------------------\n"
+ "Copyright (C) 2023-2024 %s,\n"
+ "Association of Universities for Research in Astronomy (AURA)\n";
+
+struct OMC_GLOBAL globals = {
+ .verbose = false,
+ .continue_on_error = false,
+ .always_update_base_environment = false,
+ .conda_fresh_start = true,
+ .conda_install_prefix = NULL,
+ .conda_packages = NULL,
+ .pip_packages = NULL,
+ .tmpdir = NULL,
+ .enable_docker = true,
+ .enable_artifactory = true,
+ .enable_testing = true,
+};
+
+void globals_free() {
+ guard_free(globals.tmpdir);
+ guard_free(globals.sysconfdir);
+ guard_free(globals.conda_install_prefix);
+ guard_strlist_free(&globals.conda_packages);
+ guard_strlist_free(&globals.pip_packages);
+ guard_free(globals.jfrog.arch);
+ guard_free(globals.jfrog.os);
+ guard_free(globals.jfrog.url);
+ guard_free(globals.jfrog.repo);
+ guard_free(globals.jfrog.version);
+ guard_free(globals.jfrog.cli_major_ver);
+ guard_free(globals.jfrog.jfrog_artifactory_base_url);
+ guard_free(globals.jfrog.jfrog_artifactory_product);
+ guard_free(globals.jfrog.remote_filename);
+ guard_free(globals.workaround.tox_posargs);
+}
diff --git a/src/main.c b/src/omc_main.c
index 0b2fab8..3ee3a00 100644
--- a/src/main.c
+++ b/src/omc_main.c
@@ -5,36 +5,6 @@
#include <getopt.h>
#include "omc.h"
-const char *VERSION = "1.0.0";
-const char *AUTHOR = "Joseph Hunkeler";
-const char *BANNER = "---------------------------------------------------------------------\n"
- " ██████╗ ██╗ ██╗ ███╗ ███╗██╗ ██╗ ██████╗ █████╗ ██╗ \n"
- "██╔═══██╗██║ ██║ ████╗ ████║╚██╗ ██╔╝ ██╔════╝██╔══██╗██║ \n"
- "██║ ██║███████║ ██╔████╔██║ ╚████╔╝ ██║ ███████║██║ \n"
- "██║ ██║██╔══██║ ██║╚██╔╝██║ ╚██╔╝ ██║ ██╔══██║██║ \n"
- "╚██████╔╝██║ ██║ ██║ ╚═╝ ██║ ██║ ╚██████╗██║ ██║███████╗\n"
- " ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚══════╝\n"
- "---------------------------------------------------------------------\n"
- " Delivery Generator \n"
- " v%s \n"
- "---------------------------------------------------------------------\n"
- "Copyright (C) 2023-2024 %s,\n"
- "Association of Universities for Research in Astronomy (AURA)\n";
-
-struct OMC_GLOBAL globals = {
- .verbose = false,
- .continue_on_error = false,
- .always_update_base_environment = false,
- .conda_fresh_start = true,
- .conda_install_prefix = NULL,
- .conda_packages = NULL,
- .pip_packages = NULL,
- .tmpdir = NULL,
- .enable_docker = true,
- .enable_artifactory = true,
- .enable_testing = true,
-};
-
#define OPT_ALWAYS_UPDATE_BASE 1000
#define OPT_NO_DOCKER 1001
#define OPT_NO_ARTIFACTORY 1002
@@ -125,23 +95,7 @@ static void usage(char *progname) {
}
}
-void globals_free() {
- guard_free(globals.tmpdir);
- guard_free(globals.sysconfdir);
- guard_free(globals.conda_install_prefix);
- guard_strlist_free(&globals.conda_packages);
- guard_strlist_free(&globals.pip_packages);
- guard_free(globals.jfrog.arch);
- guard_free(globals.jfrog.os);
- guard_free(globals.jfrog.url);
- guard_free(globals.jfrog.repo);
- guard_free(globals.jfrog.version);
- guard_free(globals.jfrog.cli_major_ver);
- guard_free(globals.jfrog.jfrog_artifactory_base_url);
- guard_free(globals.jfrog.jfrog_artifactory_product);
- guard_free(globals.jfrog.remote_filename);
- guard_free(globals.workaround.tox_posargs);
-}
+
static void check_system_requirements() {
const char *tools_required[] = {
diff --git a/src/utils.c b/src/utils.c
index d41400e..c1f78e5 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -1,8 +1,6 @@
#include <stdarg.h>
#include "omc.h"
-extern struct OMC_GLOBAL globals;
-
char *dirstack[OMC_DIRSTACK_MAX];
const ssize_t dirstack_max = sizeof(dirstack) / sizeof(dirstack[0]);
ssize_t dirstack_len = 0;