From 45ac04c23387128ba1817f9c51cd25f9e4a0a505 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sa=C3=BAl=20Valdelvira?= Date: Sun, 21 Apr 2024 19:31:26 +0200 Subject: [PATCH] Add make examples recipe --- Makefile | 8 +++++++- example/avl_map.c | 3 ++- example/destructors.c | 2 +- example/dict_demo.c | 2 +- example/fib.c | 4 ++-- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 5b6e115..a11ecfb 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: default clean libs test install uninstall doxygen +.PHONY: default clean libs test examples install uninstall doxygen SRC = src BIN = bin @@ -6,6 +6,7 @@ BIN = bin CFILES = $(wildcard $(SRC)/*.c) $(wildcard $(SRC)/*/*.c) OFILES = $(patsubst %.c,%.o,$(CFILES)) TESTFILES = $(wildcard test/*) +EXAMPLES = $(wildcard example/*.c) CC = cc CCFLAGS += -Wall -Wextra -pedantic -std=c99 -Wstrict-prototypes -g -fPIC -O3 @@ -50,6 +51,11 @@ test: $(TESTFILES) libs | $(BIN)/ $(CC) $(CCFLAGS) -o $(BIN)/$(patsubst %.c,%.out, $(notdir $(T))) $(T) -L./$(BIN)/ -lGDS-static; \ $(NO-RUN) || $(BIN)/$(patsubst %.c,%.out, $(notdir $(T))) || exit 1;) +examples: $(EXAMPLES) $(OFILES) | $(BIN)/ + @ $(foreach F,$(EXAMPLES), \ + echo " CC $(F)" ; \ + $(CC) $(CCFLAGS) -o $(patsubst example/%.c,bin/%,$(F)) $(F) $(OFILES) ;) + doxygen: ./doxygen/ @ echo -e "\ /** @mainpage \n \ diff --git a/example/avl_map.c b/example/avl_map.c index 581b2f1..9390304 100644 --- a/example/avl_map.c +++ b/example/avl_map.c @@ -21,7 +21,7 @@ int compare_pair(const void *e_1, const void *e_2){ } } -int main(){ +int main(void){ AVLTree *tree = avl_init(sizeof(struct Pair), compare_pair); struct Pair p; @@ -39,4 +39,5 @@ int main(){ } avl_free(tree); + return 0; } diff --git a/example/destructors.c b/example/destructors.c index 3f24f16..c0a419a 100644 --- a/example/destructors.c +++ b/example/destructors.c @@ -13,7 +13,7 @@ void destroy_person(void *p){ free(person.name); } -int main(){ +int main(void){ Vector *v = vector_init(sizeof(char*), compare_equal); // The destructor will treat every element in the // vector as a pointer that must be freed diff --git a/example/dict_demo.c b/example/dict_demo.c index 6bd536c..52c733e 100644 --- a/example/dict_demo.c +++ b/example/dict_demo.c @@ -9,7 +9,7 @@ #include #include "../src/Dictionary.h" -int main(){ +int main(void){ Dictionary *dict = dict_init(sizeof(char*), sizeof(int), hash_string); for (;;){ char option; diff --git a/example/fib.c b/example/fib.c index aecb9bd..98d78e0 100644 --- a/example/fib.c +++ b/example/fib.c @@ -18,7 +18,7 @@ Vector *fib_cache; -double fib(int n){ +double fib(size_t n){ double f; if (vector_size(fib_cache) > n){ vector_at(fib_cache, n, &f); @@ -35,7 +35,7 @@ double fib(int n){ return f; } -double main(int argc, char *argv[]){ +int main(int argc, char *argv[]){ fib_cache = vector_init(sizeof(double), compare_double) ; vector_append(fib_cache, &(double){0.0}); vector_append(fib_cache, &(double){1.0}); -- 2.11.4.GIT