feat: installation through Makefile
authorametama <ametama@wafflesoft.org>
Thu, 22 Jan 2026 17:09:57 +0000 (18:09 +0100)
committerametama <ametama@wafflesoft.org>
Thu, 22 Jan 2026 17:09:57 +0000 (18:09 +0100)
Makefile
README [new file with mode: 0644]
include/argph.h [new file with mode: 0644]
include/cgo.h [deleted file]
src/argp.c [new file with mode: 0644]
src/main.c

index dfe18b5e15b97b7ecb50fbd711f7e7a6ae2afb8a..db23bb6e71c98afe4647c942b80279476d347603 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,15 @@
 build: compile_flags lib executable
 
+install: install-bin install-lib
+
+install-bin: compile_flags executable
+       mv cgo /usr/local/bin
+
+install-lib: compile_flags lib
+       mv libcgo.a /usr/local/lib
+       mkdir -p /usr/local/include/cgo
+       cp include/* /usr/local/include/cgo
+
 #compile_flags_gtk:
 #      echo "-Iinclude `pkg-config --cflags gtk4` -lm -fopenmp `pkg-config --libs gtk4`" | perl -pe 's|(-.*?)\s|\1\n|g' > compile_flags.txt
 #      echo "-o cgo" >> compile_flags.txt
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..3e9a6d5
--- /dev/null
+++ b/README
@@ -0,0 +1,11 @@
+cgo: collection of generic optimizers
+
+!!!  HOW TO INSTALL  !!!
+
+Running `sudo make install` (or your flavour of privilege elevation) at project root
+places library/header/executable files in /usr/local. The program may then be
+launched using `cgo` in any shell, or its functions may be included in your project by
+linking against `cgo` (-lcgo for gcc) and including its headers (e.g. <cgo/de.h>).
+
+`sudo make install-lib` only does the library/header portion of this and skips the binary.
+`sudo make install-bin` only installs the binary.
diff --git a/include/argph.h b/include/argph.h
new file mode 100644 (file)
index 0000000..13f3fc8
--- /dev/null
@@ -0,0 +1,11 @@
+#include <argp.h>
+
+enum algorithm {
+    de,
+    pso
+};
+struct arguments {
+    enum algorithm algorithm;
+    char *outfile;
+};
+static struct argp argp;
diff --git a/include/cgo.h b/include/cgo.h
deleted file mode 100644 (file)
index f81d509..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-#include "de.h"
-#include "pso.h"
-#include "vector.h"
diff --git a/src/argp.c b/src/argp.c
new file mode 100644 (file)
index 0000000..6b79b7e
--- /dev/null
@@ -0,0 +1,29 @@
+#include <string.h>
+#include "argph.h"
+
+static char doc[] = "cgo: collection of generic optimizers";
+static char args_doc[] = "FILE";
+static struct argp_option options[] = {
+    {"algorithm", 'a', "{de,pso}", 0, "optimization algorithm (default: de)"}
+};
+static error_t parse_opt(int key, char *arg, struct argp_state *state) {
+    struct arguments *args = state->input;
+    switch (key) {
+        case 'a':
+            if (strcmp(arg, "de") == 0) args->algorithm = de;
+            else if (strcmp(arg, "pso") == 0) args->algorithm = pso;
+            else argp_usage(state);
+            break;
+        case ARGP_KEY_ARG:
+            if (state->arg_num > 0) argp_usage(state);
+            args->outfile = arg;
+            break;
+        case ARGP_KEY_END:
+            // if (state->arg_num < 2) argp_usage(state);
+            break;
+        default:
+            return ARGP_ERR_UNKNOWN;
+    }
+    return 0;
+}
+static struct argp argp = { options, parse_opt, args_doc, doc };
index f900b93f2385fc628b79bc5386fa48dd385e1f3d..fa4c9ef800c266c9a089a75d9d232a0440473194 100644 (file)
@@ -1,45 +1,7 @@
-#include <argp.h>
-#include <string.h>
 #include <math.h>
-#include "cgo.h"
-
-enum algorithm {
-    de,
-    pso
-};
-
-static char doc[] = "cgo: collection of generic optimizers";
-static char args_doc[] = "FILE";
-static struct argp_option options[] = {
-    {"algorithm", 'a', "{de,pso}", 0, "optimization algorithm (default: de)"}
-};
-struct arguments {
-    enum algorithm algorithm;
-    char *outfile;
-};
-
-static error_t parse_opt(int key, char *arg, struct argp_state *state) {
-    struct arguments *args = state->input;
-    switch (key) {
-        case 'a':
-            if (strcmp(arg, "de") == 0) args->algorithm = de;
-            else if (strcmp(arg, "pso") == 0) args->algorithm = pso;
-            else argp_usage(state);
-            break;
-        case ARGP_KEY_ARG:
-            if (state->arg_num > 0) argp_usage(state);
-            args->outfile = arg;
-            break;
-        case ARGP_KEY_END:
-            // if (state->arg_num < 2) argp_usage(state);
-            break;
-        default:
-            return ARGP_ERR_UNKNOWN;
-    }
-    return 0;
-}
-
-static struct argp argp = { options, parse_opt, args_doc, doc };
+#include "argph.h"
+#include "vector.h"
+#include "de.h"
 
 double b0(double *x) {
   return -x[0];