From: ametama Date: Thu, 22 Jan 2026 17:09:57 +0000 (+0100) Subject: feat: installation through Makefile X-Git-Url: https://git.wafflesoft.org/?a=commitdiff_plain;h=f4e9622723736293a04f769ff585582d7acf6b28;p=cgo.git feat: installation through Makefile --- diff --git a/Makefile b/Makefile index dfe18b5..db23bb6 100644 --- 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 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. ). + +`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 index 0000000..13f3fc8 --- /dev/null +++ b/include/argph.h @@ -0,0 +1,11 @@ +#include + +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 index f81d509..0000000 --- a/include/cgo.h +++ /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 index 0000000..6b79b7e --- /dev/null +++ b/src/argp.c @@ -0,0 +1,29 @@ +#include +#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 }; diff --git a/src/main.c b/src/main.c index f900b93..fa4c9ef 100644 --- a/src/main.c +++ b/src/main.c @@ -1,45 +1,7 @@ -#include -#include #include -#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];