diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d13ecd2..bd25506 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,6 +3,9 @@ name: Generate source build on: push: branches: [ master ] + pull_request: + branches: [ master ] + jobs: build: @@ -16,7 +19,7 @@ jobs: run: | sudo snap install yq sudo apt-get update --fix-missing - sudo apt-get install -y -f -o Acquire::Retries=3 libfuse2 + sudo apt-get install -y -f -o Acquire::Retries=3 libfuse2 jq libjson-c-dev libcurl4-openssl-dev pkg-config - name: configure run: ./configure --wget-json-search --yq-go --compile-json-c @@ -25,6 +28,7 @@ jobs: run: | sudo chsh -s $(which bash) $(whoami) make main.c osc_sdk.c osc_sdk.h oapi-cli-completion.bash + make oapi-cli-x86_64.AppImage # tar c osc_sdk.c osc_sdk.h main.c oapi-cli-completion.bash > build-src.tar # commented, because uploading generated source is made in oapi-cli/osc-sdk-c projects diff --git a/oapi-cli.AppDir/AppRun b/AppRun similarity index 64% rename from oapi-cli.AppDir/AppRun rename to AppRun index 116a99f..627150a 100755 --- a/oapi-cli.AppDir/AppRun +++ b/AppRun @@ -2,11 +2,11 @@ for opt in "$@"; do if [ "${opt}" == "--bash-completion" ]; then - cat "${APPDIR}/usr/bin/oapi-cli-completion.bash" + cat "${APPDIR}/usr/bin/____cli_name____-completion.bash" exit 0 fi done export COGNAC_HELP_APPEND="$(echo -en '\t--bash-completion\tprint bash completion(appimage only)\n\t--appimage-help\t\tappimage helps')" -LD_LIBRARY_PATH=${APPDIR}/usr/lib/ "${APPDIR}/usr/bin/oapi-cli" "$@" +LD_LIBRARY_PATH=${APPDIR}/usr/lib/ "${APPDIR}/usr/bin/____cli_name____" "$@" diff --git a/HACKING.md b/HACKING.md new file mode 100644 index 0000000..fcc67c5 --- /dev/null +++ b/HACKING.md @@ -0,0 +1,29 @@ +# Do You Want To Know More? + +*Essential Information for Hacking COGNAC* + +## Unix Philosophy and COGNAC Paradigms. + +Most people have heard the phrase "Do One Thing and Do It Well" and associate it with the Unix philosophy. It’s said that this is how Unix operates and how it should be. + +Personally, I used to wonder how much truth there was to this statement, or whether it was even a good idea. Like many others, I would nod along, pretending to understand it, but I didn’t really get it. Now, though, I feel I have a much better understanding of what it truly means. + +ow, you ask? By reading the source code of some Unix-based OSes. +When I read a complete [shell](https://github.com/dspinellis/unix-history-repo/blob/BSD-1-Snapshot-Development/s1/sh.c), the whole source of [ls](https://github.com/dspinellis/unix-history-repo/blob/BSD-1-Snapshot-Development/s6/ls.c), or a fully running [cat](https://github.com/klange/toaruos/blob/master/apps/cat.c), I had a realization: most of these programs are written in far fewer lines of code than I would need just to write half of an object interface in a modern language. + +It started to make sense. These programs were built to interact with each other. While we tend to view programs as entire projects nowadays, in Unix, a program was designed to do just one thing—and do it well. Modularity wasn’t a priority. Why create a complex interface when writing an entirely new program could be faster? In Unix, programs like cat, grep, and wc are almost like objects in an object-oriented system, inheriting basic text-handling class. + +COGNAC is based on Bash, and it follows a similar philosophy. + +It uses a lot of small programs that interact with each other and is supplemented by a few utilities in the bin/ directory that handle text processing tasks. + +The Makefile was originally created to "make" files, and COGNAC uses it in that way. + +The scripts used by the Makefile handle the actual file creation, while the Makefile itself checks if files need to be rebuilt or not. + +## Templating + +COGNAC’s templating system is homemade. It reads SRC files and generates DEST files. It uses several keywords, each surrounded by four underscores (e.g., `____api_version____`). +For example, you can check out [lib.h](./lib.h) or [main_tpl.c](./main_tpl.c) + +Some rules support multiple languages, like `____func_code____`, which generates function calls. Others, like `____functions_proto____`, currently support only C. diff --git a/Makefile b/Makefile index 02335f1..ee5066a 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # COGNAC for: Code Outscale Generator New Automatic Creator # you can find a better name if you want. -all: oapi-cli-completion.bash oapi-cli +all: make_cli config.mk: @echo "config.mk is not present" @@ -9,21 +9,27 @@ config.mk: @exit 1 OAPI_RULE_DEPEDENCIES=main.c osc_sdk.h osc_sdk.c main-helper.h -OAPI_APPIMAGE_RULE_DEPEDENCIES=oapi-cli-completion.bash +OAPI_APPIMAGE_RULE_DEPEDENCIES=$(CLI_NAME)-completion.bash list_api_version: curl -s https://api.github.com/repos/outscale/osc-api/tags | $(JSON_SEARCH) -R name +include config.mk + help: @echo "Available targets:" - @echo "- osc_sdk.c/osc_sdk.h/main.c/oapi-cli-completion.bash: make the file" + @echo "- osc_sdk.c/osc_sdk.h/main.c/$(CLI_NAME)-completion.bash: make the file" @echo "- list_api_version: list all version avable on github" @echo "- clean: remove every generated files" -include config.mk include oapi-cli.mk +osc-api.json:: + ./bin/osc-api-seems-valid.sh osc-api.json "need_remove" + +make_cli: $(CLI_NAME) $(CLI_NAME)-completion.bash + bin/funclist: bin/funclist.c $(CC) -O3 bin/funclist.c $(JSON_C_LDFLAGS) $(JSON_C_CFLAGS) -o bin/funclist @@ -39,16 +45,13 @@ osc_sdk.c: bin/line_check osc-api.json call_list arguments-list.json config.sh l osc_sdk.h: bin/line_check osc-api.json call_list arguments-list.json config.sh lib.h cognac_gen.sh mk_args.c.sh ./cognac_gen.sh lib.h osc_sdk.h c -oapi-cli-completion.bash: bin/line_check osc-api.json call_list arguments-list.json config.sh oapi-cli-completion-tpl.bash cognac_gen.sh - ./cognac_gen.sh oapi-cli-completion-tpl.bash oapi-cli-completion.bash bash +$(CLI_NAME)-completion.bash: bin/line_check osc-api.json call_list arguments-list.json config.sh oapi-cli-completion-tpl.bash cognac_gen.sh + ./cognac_gen.sh oapi-cli-completion-tpl.bash $(CLI_NAME)-completion.bash bash config.sh: echo "alias json-search=$(JSON_SEARCH)" > config.sh echo $(SED_ALIAS) >> config.sh - -osc-api.json: - curl -s https://raw.githubusercontent.com/outscale/osc-api/$(API_VERSION)/outscale.yaml \ - | yq $(YQ_ARG) > osc-api.json + echo "export CLI_NAME=$(CLI_NAME)" >> config.sh arguments-list.json: osc-api.json $(JSON_SEARCH) -s Request osc-api.json | $(JSON_SEARCH) -K properties \ @@ -61,7 +64,7 @@ call_list: osc-api.json bin/funclist clean: - rm -vf osc-api.json call_list osc_sdk.c arguments-list.json osc_sdk.h main.c oapi-cli config.sh oapi-cli-completion.bash bin/line_check + rm -vf osc-api.json call_list osc_sdk.c arguments-list.json osc_sdk.h main.c $(CLI_NAME) config.sh $(CLI_NAME)-completion.bash bin/line_check bin/funclist -.PHONY: clean list_api_version help +.PHONY: clean list_api_version help make_cli diff --git a/README.md b/README.md index eda1586..0f19cb9 100644 --- a/README.md +++ b/README.md @@ -3,21 +3,96 @@ ## Usage -configure COGNAC using `./configure`, then use either `cognac_gen.sh SOURCE DEST LANGUAGE` directly, or the Makefile. +*note: The primary purpose of this repository is to generate source code. If your goal is to compile osc-sdk-c or oapi-cli, please refer to their respective repositories, which handle the code generation process for you.* -*note: The main purpose of this repository is to generate source code. If your goal is to compile osc-sdk-c or oapi-cli, please use their respective repositories, which handle the code generation process for you.* +### Brief -## Dependency +To configure the COGNAC Makefile, use `./configure.` +You can use `cognac_gen.sh SOURCE DEST LANGUAGE` to generate files from a template. +The Makefile is designed to help you generate all the required files. +If you want to generate everything, simply run `make`. -Non exaustive list: +### Generated Files + +COGNAC generates four main files: +- main.c: Source code for the CLI. +- osc_sdk.h: Header file for the C library. +- osc_sdk.c: Source code for the C library. +- $(CLI_NAME)-completion.bash: Autocompletion file for the CLI. + +### cognac_gen.sh + +cognac_gen.sh is the script responsible for generating all the necessary files. It’s a shell script that calls sub-shell scripts and executes a few C binaries, which are compiled by the Makefile (see bin/). + +It takes three arguments: a source file, a destination file, and a language. +The language argument is crucial as certain keywords might be interpreted differently depending on the target language. + +The script uses a file called osc-api.json, which represents the OpenAPI specification in JSON format. +For the Outscale API, the YAML source is converted to JSON using yq. + +When generating API calls, COGNAC assumes that the OpenAPI file contains components named CallRequest. +For example, if the API has a call named `CreatePony`, the corresponding component should be located at `#/components/schemas/CreatePonyRequest`. + +*Note: There are two versions of yq: one written in Python and one in Go. The default version depends on your distribution. On Arch-based distributions, the Python version is typically the default, whereas on Debian-based distributions, the Go version is default. COGNAC supports both, but to use the Go version, you need to pass `--yq-go` to `./configure`.* + +### Example: Generating a CLI for a New API + +Let’s say you have an API that is not the Outscale API, and you want to generate a CLI for it. +You have a URL to a YAML file, such as `https://ponyapi.yolo/`, and the API request components are named `XInput` instead of `XRequest`. + +To configure the Makefile to generate the CLI with the name `pony-cli`, and adjust the component naming convention, follow these steps: + +Run the following command: +```bash +./configure --cli-name=pony-cli --api-script='curl -s https://ponyapi.yolo | yq $(YQ_ARG) | sed "s/Input/Request/" > osc-api.json' +``` + +`-cli-name=pony-cli` set the generated binary name to `pony-cli` + +```bash +--api-script='curl -s https://ponyapi.yolo | yq $(YQ_ARG) | sed "s/Input/Request/" > osc-api.json' +``` +This script is used to fetch the API file. + + +Here’s what the script does: + +1. Retrieves the API in YAML format using curl -s `https://ponyapi.yolo/.` +2. Converts the YAML to JSON using yq `$(YQ_ARG)`. *Note the usage of `$(YQ_ARG)`, so ./configure can handle go version of yq* +3. Renames all components named `XInput` to `XRequest`. + +Once this setup is complete, you can now use the Makefile. It's also a good idea to run ./configure --help, as it contains several useful options. +- `--wget-json-search`: Helps with downloading `json-search`, which can be tricky to install, **If unsure, we recommend using this by default** +- `--compile-json-c`: Ensures a recent version of `json-c` is compiled, required for color support. **If unsure, we recommend using this by default** + +Now, simply run `make` to generate all necessary files and compile the CLI. This will also create a C SDK, consisting of two files: `osc-sdk.c` and `osc-sdk.h`. + +If you want more control over the generation process, you can manually invoke specific Makefile rules: +```bash +make main.c osc_sdk.c osc_sdk.h pony-cli-completion.bash pony-cli +``` + + +## Dependencies + +Here’s a non-exhaustive list of required dependencies: - GNU sed - bash - jq - [json-search](https://github.com/cosmo-ray/json-search) - make - pkg-config -- C Compiller +- C Compiler + +### Optional Dependencies +- libfuse2 (require if building appimage or with `--wget-json-search`) -## contribution + +## Contribution Open Pull Requests and Issues are welcome. + +If you want to add binaries to the bin/ directory, please ensure they are easy to compile. +This means avoiding additional dependencies that are not already required by the CLI. + +For more information about cognac code, see [HACKING.md](./HACKING.md) diff --git a/oapi-cli.AppDir/appimage-logo.png b/appimage-logo.png similarity index 100% rename from oapi-cli.AppDir/appimage-logo.png rename to appimage-logo.png diff --git a/bin/funclist.c b/bin/funclist.c index 38143d2..b34cf5a 100644 --- a/bin/funclist.c +++ b/bin/funclist.c @@ -6,8 +6,15 @@ int main(int ac, char **av) { struct json_object *j_file = json_object_from_file(av[1]); - struct json_object *compo = json_object_object_get(j_file, "components"); - struct json_object *schema = json_object_object_get(compo, "schemas"); + struct json_object *compo; + struct json_object *schema; + int ret = 0; + ret = json_object_object_get_ex(j_file, "components", &compo); + if (!ret) + return 1; + json_object_object_get_ex(compo, "schemas", &schema); + if (!ret) + return 1; int first = 1; json_object_object_foreach(schema, k, v_) { @@ -23,4 +30,5 @@ int main(int ac, char **av) free(new_k); } json_object_put(j_file); + return 0; } diff --git a/bin/osc-api-seems-valid.sh b/bin/osc-api-seems-valid.sh new file mode 100755 index 0000000..85640c7 --- /dev/null +++ b/bin/osc-api-seems-valid.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# check if $1 is valide, if $2 is present, remove invalide file +config_path=$(realpath $(dirname $0))/../config.sh + +shopt -s expand_aliases +source $config_path + +test=$(json-search -sn Request $1 | json-search -n properties) +test_ret=$? + +if [ "$test_ret" == "1" -o "$test" == "null" ]; then + echo "$1 is invalide" >&2 + if [ "$#" -gt 1 ]; then + rm $1 + fi +fi + + diff --git a/oapi-cli.AppDir/oapi-cli.desktop b/cli.desktop similarity index 77% rename from oapi-cli.AppDir/oapi-cli.desktop rename to cli.desktop index 73b5e5d..06d3b1a 100644 --- a/oapi-cli.AppDir/oapi-cli.desktop +++ b/cli.desktop @@ -1,7 +1,7 @@ [Desktop Entry] Type=Application -Name=oapi-cli -Exec=oapi-cli +Name=____cli_name____ +Exec=____cli_name____ Comment=CLI-of Outscale Granting Net Accessible Calls Categories=Development;Network; Terminal=true diff --git a/cognac_gen.sh b/cognac_gen.sh index aa436a7..bff3162 100755 --- a/cognac_gen.sh +++ b/cognac_gen.sh @@ -207,8 +207,6 @@ replace_args() SDK_VERSION=$(cat sdk-version) while IFS= read -r line do - #check ____args____ here - arg_check=$(bin/line_check ____args____ ____func_code____ ____functions_proto____ ____cli_parser____ ____complex_struct_func_parser____ ____complex_struct_to_string_func____ ____call_list_dec____ ____call_list_descriptions____ ____call_list_args_descriptions____ <<< "$line") if [ "$arg_check" == "____args____" ]; then @@ -306,7 +304,8 @@ EOF #for s in "skip"; do struct_name=$(to_snakecase <<< $s) - A_LST=$(jq .components.schemas.$s < osc-api.json | json-search -Kn properties | tr -d '",[]') + local componant=$(jq .components.schemas.$s < osc-api.json) + A_LST=$(json-search -Kn properties <<< $componant | tr -d '",[]') if [ "$A_LST" != "null" ]; then echo "int ${struct_name}_parser(void *v_s, char *str, char *aa, struct ptr_array *pa) {" @@ -319,12 +318,31 @@ EOF echo " if ((aret = argcmp(str, \"$a\")) == 0 || aret == '=' || aret == '.') {" cli_c_type_parser "$a" "$t" " " done - cat <additional_strs, elem, pa); + elem->key = str; + elem->val = aa; + } +EOF + fi + echo " return 0;" echo -e '}\n' fi @@ -455,9 +473,7 @@ EOF while IFS= read -r fline do - grep ____construct_data____ <<< "$fline" > /dev/null - local have_construct_data=$? - if [ $have_construct_data == 0 ]; then + if [[ $( grep -q ____construct_data____ <<< "$fline" )$? == 0 ]]; then ./construct_data.${lang}.sh $x else sed "s/____func____/$x/g; s/____snake_func____/$snake_x/g;s/____dashed_args____/$dashed_args/g" <<< "$fline" @@ -465,7 +481,7 @@ EOF done < function.${lang} done else - sed "s/____call_list____/${CALL_LIST}/g;s/____piped_call_list____/${PIPED_CALL_LIST}/;s/____api_version____/${API_VERSION}/g;s/____sdk_version____/${SDK_VERSION}/g;s/____cli_version____/$(cat cli-version)/g" <<< "$line"; + sed "s/____call_list____/${CALL_LIST}/g;s/____piped_call_list____/${PIPED_CALL_LIST}/;s/____api_version____/${API_VERSION}/g;s/____sdk_version____/${SDK_VERSION}/g;s/____cli_version____/$(cat cli-version)/g;s/____cli_name____/${CLI_NAME}/" <<< "$line"; fi done < $1 } diff --git a/configure b/configure index c362812..7de164b 100755 --- a/configure +++ b/configure @@ -15,7 +15,10 @@ LD_CURLLIB_PATH='' LD_JSONCLIB_PATH='' API_VERSION=master SDK_VERSION=0xC061AC +CLI_NAME=oapi-cli +API_SCRIPT='curl -s https://raw.githubusercontent.com/outscale/osc-api/$(API_VERSION)/outscale.yaml | yq $(YQ_ARG) > osc-api.json' +inc=1 for arg in $@; do if [ "--help" = $arg ]; then cat <additional_strs; + + for (struct osc_additional_strings **e = elems; e && *e; ++e) { + TRY_APPEND_COL(count_args, data); + STRY(osc_str_append_string(data, "\"" )); + STRY(osc_str_append_string(data, (*e)->key )); + STRY(osc_str_append_string(data, "\":" )); + STRY(osc_str_append_string(data, "\"" )); + STRY(osc_str_append_string(data, (*e)->val )); + STRY(osc_str_append_string(data, "\"" )); + } +EOF +fi + + if [ "$args" == "null" ]; then exit fi diff --git a/helper.sh b/helper.sh index 37d7381..280c892 100644 --- a/helper.sh +++ b/helper.sh @@ -19,7 +19,7 @@ get_type_direct() { local have_any_of=$? if [ $have_any_of == 0 -a "$any_of" != 'null' ]; then one_of="$any_of" - have_any_of=have_one_of + have_one_of=$have_any_of fi if [ $have_type == 0 -a "$types" != 'null' ]; then if [ "$types" == 'integer' ]; then @@ -34,8 +34,15 @@ get_type_direct() { elif [ "$types" == 'array' ]; then local item_one_off=$(jq -r .items.oneOf 2> /dev/null <<< $arg_info) local item_is_one_of=$? + local item_any_of=$(jq -r .items.anyOf 2> /dev/null <<< $arg_info) + local item_have_any_of=$? local sub_type=$(jq -r .items.type 2> /dev/null <<< $arg_info) have_stype=$? + if [ $item_have_any_of == 0 -a "$item_any_of" != 'null' ]; then + local the_one=$(jq .[0] <<< $item_any_of) + sub_type=$(get_type_direct "$the_one") + have_stype=0 + fi if [ $item_is_one_of == 0 -a "$item_one_off" != 'null' ]; then local the_one=$(jq .[0] <<< $item_one_off) sub_type=$(get_type_direct "$the_one") @@ -103,7 +110,7 @@ get_sub_type_description() { return fi for p in $properties; do - local properties=$(json-search $p <<< $st_info) + local properties=$(jq .properties[\"$p\"] <<< $st_info) local desc=$(jq .description <<< $properties) local type=$(get_type_direct "$properties") diff --git a/lib.h b/lib.h index a1d1d39..2ee5202 100644 --- a/lib.h +++ b/lib.h @@ -127,6 +127,11 @@ static const char *osc_sdk_version_str(void) return ret; } +struct osc_additional_strings { + char *key; + char *val; +}; + ____args____ int osc_load_ak_sk_from_conf(const char *profile, char **ak, char **sk); diff --git a/main-helper.h b/main-helper.h index 52662a1..c98608b 100644 --- a/main-helper.h +++ b/main-helper.h @@ -42,6 +42,9 @@ struct ptr_array { */ #define OBJ_SIZE 8 +/* a is an array with a flexible size, v is the value to push, + * and pa is used to store the pointer so that we can easily free everything later. + */ #define SET_NEXT(a,v,pa) do { \ int cnt; \ if (!a) { \ diff --git a/main_tpl.c b/main_tpl.c index 3c6c378..097e368 100644 --- a/main_tpl.c +++ b/main_tpl.c @@ -49,7 +49,7 @@ #define OAPI_CLI_VERSION "____cli_version____" -#define OAPI_CLI_UAGENT "oapi-cli/"OAPI_CLI_VERSION"; osc-sdk-c/" +#define OAPI_CLI_UAGENT "____cli_name____/"OAPI_CLI_VERSION"; osc-sdk-c/" #define STRY(f, args...) \ do { \ @@ -295,9 +295,10 @@ int main(int ac, char **av) } else if (!strcmp("--insecure", av[i])) { flag |= OSC_INSECURE_MODE; } else if (!strcmp("--version", av[i])) { - printf("oapi-cli version: %s\n" + printf("%s version: %s\n" "osc-sdk-c version: %s\n" "based on osc-api: %s\n", + program_name, OAPI_CLI_VERSION, osc_sdk_version_str(), OSC_API_VERSION); @@ -401,11 +402,11 @@ int main(int ac, char **av) "\t --color try to colorize json if json-c support it\n" "\t --config=PATH config file path\n" "\t --file PATH use content of PATH as an agrument for a call, example:\n" - "\t\t\t\toapi-cli CreateCa --CaPem --file /$CA_DIR/cert.pem\n" + "\t\t\t\t____cli_name____ CreateCa --CaPem --file /$CA_DIR/cert.pem\n" "\t --jsonstr-file PATH same as --file, except the content is surrounded by \"\n" "\t\t\t\tand \" inside the file are escape with a \\, this option is useful for CreatePolicy\n" - "\t --set-var ID=VARIABLE_PATH Create an oapi-cli variable, that can be use with --var\n" - "\t\t\t\tExamples: ./oapi-cli ReadVms --Filters.TagValues[] VM_NAME --set-var id=Vms.0.VmId ReadVms --Filters.VmIds[] --var id\n" + "\t --set-var ID=VARIABLE_PATH Create an ____cli_name____ variable, that can be use with --var\n" + "\t\t\t\tExamples: ____cli_name____ ReadVms --Filters.TagValues[] VM_NAME --set-var id=Vms.0.VmId ReadVms --Filters.VmIds[] --var id\n" "\t\t\t\twill find the vm with VM_NAME as it's tag, and read it again, but using it's VmId as filter this time\n" "\t --var use variabble content created by --set-var\n" "\t-h, --help [CallName] this, can be used with call name, example:\n\t\t\t\t%s --help ReadVms\n" @@ -416,7 +417,7 @@ int main(int ac, char **av) "\t --profile=PROFILE select profile\n" "\t --raw-print doesn't format the output\n" "\t --verbose curl backend is now verbose\n" - "\t --version oapi-cli version info\n%s%s", + "\t --version ____cli_name____ version info\n%s%s", program_name, program_name, help_appent ? help_appent : "", help_appent ? "\n" : ""); return 0; diff --git a/mk_args.c.sh b/mk_args.c.sh index 67ed9e9..ea7a0a3 100755 --- a/mk_args.c.sh +++ b/mk_args.c.sh @@ -75,6 +75,13 @@ write_struct() { type_to_ctype "$t" "$snake_n" done + aditional=$(json-search -n additionalProperties <<< $st_info) + + if [[ "$aditional" != "null" && "$aditional" != "false" ]]; then + # no type checks are made here, the additional stuff is assumed to be a string + echo -e '\tstruct osc_additional_strings **additional_strs;' + fi + echo -e '};\n' } diff --git a/oapi-cli-completion-tpl.bash b/oapi-cli-completion-tpl.bash index 1912dd7..97f3274 100644 --- a/oapi-cli-completion-tpl.bash +++ b/oapi-cli-completion-tpl.bash @@ -35,9 +35,9 @@ _cognac() esac } -complete -F _cognac oapi-cli -complete -F _cognac oapi-cli-x86_64.AppImage +complete -F _cognac ____cli_name____ +complete -F _cognac ____cli_name____-x86_64.AppImage # thoses one are for debug -complete -F _cognac ./oapi-cli -complete -F _cognac ./oapi-cli-x86_64.AppImage +complete -F _cognac ./____cli_name____ +complete -F _cognac ./____cli_name____-x86_64.AppImage diff --git a/oapi-cli.mk b/oapi-cli.mk index ff75a4f..41654c3 100644 --- a/oapi-cli.mk +++ b/oapi-cli.mk @@ -1,18 +1,23 @@ #-Wincompatible-pointer-types -oapi-cli: $(OAPI_RULE_DEPEDENCIES) $(JSON_C_RULE) - $(CC) -g -Wall -Wextra -Wno-unused-function -Wno-unused-parameter main.c osc_sdk.c $(CURL_LD) $(JSON_C_LDFLAGS) $(CURL_CFLAGS) $${CURL_BASH_CFLAGS} $(JSON_C_CFLAGS) -o oapi-cli -DWITH_DESCRIPTION=1 $(CFLAGS) +$(CLI_NAME): $(OAPI_RULE_DEPEDENCIES) $(JSON_C_RULE) + $(CC) -g -std=gnu11 -Wall -Wextra -Wno-unused-function -Wno-unused-parameter main.c osc_sdk.c $(CURL_LD) $(JSON_C_LDFLAGS) $(CURL_CFLAGS) $${CURL_BASH_CFLAGS} $(JSON_C_CFLAGS) -o $(CLI_NAME) -DWITH_DESCRIPTION=1 $(CFLAGS) appimagetool-x86_64.AppImage: wget https://github.com/AppImage/AppImageKit/releases/download/12/appimagetool-x86_64.AppImage chmod +x appimagetool-x86_64.AppImage -oapi-cli-x86_64.AppImage: oapi-cli appimagetool-x86_64.AppImage - mkdir -p oapi-cli.AppDir/usr/ - install -D $$(curl-config --ca) oapi-cli.AppDir/$$(curl-config --ca) - echo export CURL_CA_BUNDLE='$${APPDIR}'/$$(curl-config --ca) > oapi-cli.AppDir/import-ssl.sh - mkdir -p oapi-cli.AppDir/usr/bin/ - mkdir -p oapi-cli.AppDir/usr/lib/ - cp oapi-cli oapi-cli.AppDir/usr/bin/ - cp oapi-cli-completion.bash oapi-cli.AppDir/usr/bin/ - LD_LIBRARY_PATH="$(LD_LIB_PATH)" ./cp-lib.sh oapi-cli ./oapi-cli.AppDir/usr/lib/ - ./appimagetool-x86_64.AppImage $(APPIMAGETOOL_OPTION) oapi-cli.AppDir +$(CLI_NAME)-x86_64.AppImage: $(CLI_NAME) $(CLI_NAME)-completion.bash appimagetool-x86_64.AppImage + mkdir -p $(CLI_NAME).AppDir/ + mkdir -p $(CLI_NAME).AppDir/usr/ + install -D $$(curl-config --ca | tr -d '"') $(CLI_NAME).AppDir/$$(curl-config --ca) + echo export CURL_CA_BUNDLE='$${APPDIR}'/$$(curl-config --ca | tr -d '"') > $(CLI_NAME).AppDir/import-ssl.sh + mkdir -p $(CLI_NAME).AppDir/usr/bin/ + mkdir -p $(CLI_NAME).AppDir/usr/lib/ + cat cli.desktop | sed "s/____cli_name____/$(CLI_NAME)/" > $(CLI_NAME).AppDir/$(CLI_NAME).desktop + cat AppRun | sed "s/____cli_name____/$(CLI_NAME)/" > $(CLI_NAME).AppDir/AppRun + chmod +x $(CLI_NAME).AppDir/AppRun + cp $(CLI_NAME) $(CLI_NAME).AppDir/usr/bin/ + cp appimage-logo.png $(CLI_NAME).AppDir/ + cp $(CLI_NAME)-completion.bash $(CLI_NAME).AppDir/usr/bin/ + LD_LIBRARY_PATH="$(LD_LIB_PATH)" ./cp-lib.sh $(CLI_NAME) ./$(CLI_NAME).AppDir/usr/lib/ + ./appimagetool-x86_64.AppImage $(APPIMAGETOOL_OPTION) $(CLI_NAME).AppDir