From dde090d4b026530b4bf5a63be5b63dd2694c1254 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sun, 24 Nov 2019 08:34:39 +0100 Subject: [PATCH] Make GMP optional for the examples --- example/Makefile | 16 +++++++++++----- example/ex-array04.c | 7 +++++++ example/ex-multi02.c | 7 +++++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/example/Makefile b/example/Makefile index 6110176b..9c155bf7 100644 --- a/example/Makefile +++ b/example/Makefile @@ -1,18 +1,24 @@ CC=cc -std=c99 CFLAGS=-Wall -W -pedantic -Wshadow -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wswitch-default -Wswitch-enum -Wcast-align -Wpointer-arith -Wbad-function-cast -Wstrict-overflow=5 -Wstrict-prototypes -Winline -Wundef -Wnested-externs -Wcast-qual -Wshadow -Wunreachable-code -Wlogical-op -Wstrict-aliasing=2 -Wredundant-decls -Wold-style-definition -Wno-unused-function -CPPFLAGS=-I.. -LDFLAGS=-pthread -lgmp +GMP_DIR= +CPPFLAGS=-I.. -I$(GMP_DIR)/include +LDFLAGS=-pthread -L$(GMP_DIR)/lib RM=rm -f .SUFFIXES: .c .exe .c.exe: - $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $< -o $@ + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) `cat config` $< -o $@ -all: +all: config $(MAKE) `ls ex-*.c|sed -e 's/\.c/\.exe/g'` +config: + printf "#include \nint main(void){mpz_t z; mpz_init(z); return 0;}\n" > config-test.c + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -lgmp config-test.c -o config-test.exe 2> /dev/null && echo "-DHAVE_GMP=1 -lgmp" > config || echo "-DHAVE_GMP=0" > config + $(RM) config-test.* + clean: - $(RM) *.exe *.s *~ *.o ./a.dat + $(RM) *.exe *.s *~ *.o ./a.dat config diff --git a/example/ex-array04.c b/example/ex-array04.c index 8987845d..2f0fdeba 100644 --- a/example/ex-array04.c +++ b/example/ex-array04.c @@ -1,3 +1,5 @@ +#if HAVE_GMP + #include #include "m-array.h" @@ -35,3 +37,8 @@ int main(void) array_mpz_clear(a); mpz_clear(z); } + +#else +// Nothing to do +int main(void) { return 0; } +#endif diff --git a/example/ex-multi02.c b/example/ex-multi02.c index 41bd91ec..c65d448c 100644 --- a/example/ex-multi02.c +++ b/example/ex-multi02.c @@ -1,3 +1,5 @@ +#if HAVE_GMP + #include #include @@ -61,3 +63,8 @@ int main(void) } } /* All variables are automatically cleared beyond this point */ } + +#else +// Nothing to do +int main(void) { return 0; } +#endif