Commit 9f01ba14bc450e869c70ac073bd27aac3231f0f5

Daniel Mendler 2019-10-26T18:48:41

add "testme.sh --c89" and "make c89" * replace int*_t and bool by custom typedefs * the result is tested in CI

diff --git a/.travis.yml b/.travis.yml
index 2f94615..42960d0 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -140,6 +140,7 @@ matrix:
     # clang for x86-64 architecture (64-bit longs and 64-bit pointers)
     - env: SANITIZER=1 CONV_WARNINGS=relaxed BUILDOPTIONS='--with-cc=clang-7 --with-m64 --with-travis-valgrind'
     - env: SANITIZER=1 CONV_WARNINGS=strict BUILDOPTIONS='--with-cc=clang-7 --with-m64 --with-travis-valgrind'
+    - env: SANITIZER=1 CONV_WARNINGS=strict BUILDOPTIONS='--with-cc=clang-7 --c89 --with-m64 --with-travis-valgrind'
     - env: SANITIZER=1 BUILDOPTIONS='--with-cc=clang-6.0 --with-m64 --with-travis-valgrind'
       addons:
         apt:
diff --git a/makefile b/makefile
index 179176b..be7ef0c 100644
--- a/makefile
+++ b/makefile
@@ -152,6 +152,29 @@ new_file:
 perlcritic:
 	perlcritic *.pl doc/*.pl
 
+c89:
+	@echo "Applying substitutions for c89 compatibility..."
+	@sed -i \
+	-e 's/#include <stdbool.h>//g' \
+	-e 's/#include <stdint.h>/#include "tommath_c89.h"/g' \
+	-e 's/bool/mp_bool/g' \
+	-e 's/true/MP_YES/g' \
+	-e 's/false/MP_NO/g' \
+	-e 's/uint\([0-9][0-9]*\)_t/mp_u\1/g' \
+	-e 's/int\([0-9][0-9]*\)_t/mp_i\1/g' \
+	*.c *.h demo/*.c demo/*.h etc/*.c
+	@echo "/* please adapt this header to your needs */" > tommath_c89.h
+	@echo "typedef enum { MP_NO, MP_YES } mp_bool;" >> tommath_c89.h
+	@echo "typedef __INT8_TYPE__   mp_i8;"          >> tommath_c89.h
+	@echo "typedef __INT16_TYPE__  mp_i16;"         >> tommath_c89.h
+	@echo "typedef __INT32_TYPE__  mp_i32;"         >> tommath_c89.h
+	@echo "typedef __INT64_TYPE__  mp_i64;"         >> tommath_c89.h
+	@echo "typedef __UINT8_TYPE__  mp_u8;"          >> tommath_c89.h
+	@echo "typedef __UINT16_TYPE__ mp_u16;"         >> tommath_c89.h
+	@echo "typedef __UINT32_TYPE__ mp_u32;"         >> tommath_c89.h
+	@echo "typedef __UINT64_TYPE__ mp_u64;"         >> tommath_c89.h
+
+
 astyle:
 	@echo "   * run astyle on all sources"
 	@astyle --options=astylerc --formatted $(OBJECTS:.o=.c) tommath*.h demo/*.c etc/*.c mtest/mtest.c
diff --git a/testme.sh b/testme.sh
index 2f7235f..3375fa6 100755
--- a/testme.sh
+++ b/testme.sh
@@ -195,6 +195,7 @@ VALGRIND_OPTS=" --leak-check=full --show-leak-kinds=all --error-exitcode=1 "
 #VALGRIND_OPTS=""
 VALGRIND_BIN=""
 CHECK_FORMAT=""
+C89=""
 TUNE_CMD="./etc/tune -t -r 10 -L 3"
 
 alive_pid=0
@@ -217,6 +218,9 @@ do
     "--with-m64" | "--with-m32" | "--with-mx32")
       ARCHFLAGS="$ARCHFLAGS ${1:6}"
     ;;
+    --c89)
+      C89="1"
+    ;;
     --with-cc=*)
       COMPILERS="$COMPILERS ${1#*=}"
     ;;
@@ -291,6 +295,8 @@ function _check_git() {
   git diff-index --quiet HEAD -- . || ( echo "FAILURE: $*" && exit 1 )
 }
 
+[[ "$C89" == "1" ]] && make c89
+
 if [[ "$CHECK_FORMAT" == "1" ]]
 then
   make astyle