Make GMP optional for the examples

This commit is contained in:
Patrick Pelissier committed 2019-11-24 08:34:39 +01:00
1 parent 87183573ce
commit dde090d4b0
3 files changed
+25 -5

No files matched your search

+11 -5
View File
@@ -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 <gmp.h>\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
+7
View File
@@ -1,3 +1,5 @@
#if HAVE_GMP
#include <gmp.h>
#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
+7
View File
@@ -1,3 +1,5 @@
#if HAVE_GMP
#include <stdio.h>
#include <gmp.h>
@@ -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