mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
add C compiler and C include checks for calc
Fixed have_statfs optional executable file extension ${EXT{ in the ${UTIL_PROGS} make variable. Prevented the "fake boolean value" when <stdbool.h> is missing, from complicating C compilers post c17 standard. Test if <stdint.h> exists and set HAVE_STDINT_H accordingly in have_stdint.h. Added HAVE_STDINT_H to allow one to force this value. Test if <inttypes.h> exists and set HAVE_INTTYPES_H accordingly in have_inttypes.h. Added HAVE_INTTYPES_H to allow one to force this value. Added c_chk.c to check the compiler and C include for calc requirements. If you are unable to compile this program, or if this program when compiles does not exit 0, then your C compiler and/or C include fails to meet calc requirements. Compilers that are at least c99 MUST be able to compile this program such that when run will exit 0. The "make hsrc" file will attempt to compile and run c_chk and will warn if the C compiler and/or C include fails to meet calc requirements. The "make debug" system will run c_chk -c to print information about the C compiler and C include. Currently failure to compile cc_chk.c or c_chk exiting non-0 will just print "WARNING!!" strings to stderr.
This commit is contained in:
11
.gitignore
vendored
11
.gitignore
vendored
@@ -11,16 +11,17 @@ align32.h
|
|||||||
args.h
|
args.h
|
||||||
cal/.all
|
cal/.all
|
||||||
calc
|
calc
|
||||||
|
calc-static
|
||||||
calc.1
|
calc.1
|
||||||
|
calc.spec
|
||||||
|
calc.usage
|
||||||
calcerr.c
|
calcerr.c
|
||||||
calcerr.h
|
calcerr.h
|
||||||
calc.spec
|
|
||||||
calc-static
|
|
||||||
calc.usage
|
|
||||||
charbit.h
|
charbit.h
|
||||||
|
chk_c
|
||||||
conf.h
|
conf.h
|
||||||
cscript/4dsphere
|
|
||||||
cscript/.all
|
cscript/.all
|
||||||
|
cscript/4dsphere
|
||||||
cscript/fproduct
|
cscript/fproduct
|
||||||
cscript/mersenne
|
cscript/mersenne
|
||||||
cscript/piforever
|
cscript/piforever
|
||||||
@@ -45,6 +46,7 @@ have_getpgid.h
|
|||||||
have_getprid.h
|
have_getprid.h
|
||||||
have_getsid.h
|
have_getsid.h
|
||||||
have_gettime.h
|
have_gettime.h
|
||||||
|
have_inttypes.h
|
||||||
have_limits.h
|
have_limits.h
|
||||||
have_memmv.h
|
have_memmv.h
|
||||||
have_newstr.h
|
have_newstr.h
|
||||||
@@ -53,6 +55,7 @@ have_posscl.h
|
|||||||
have_rusage.h
|
have_rusage.h
|
||||||
have_statfs.h
|
have_statfs.h
|
||||||
have_stdbool.h
|
have_stdbool.h
|
||||||
|
have_stdint.h
|
||||||
have_stdlib.h
|
have_stdlib.h
|
||||||
have_stdvs
|
have_stdvs
|
||||||
have_strdup.h
|
have_strdup.h
|
||||||
|
28
CHANGES
28
CHANGES
@@ -42,6 +42,34 @@ The following are the changes from calc version 2.14.3.5 to date:
|
|||||||
Replaced in C source, TRUE with true, FALSE with false, and
|
Replaced in C source, TRUE with true, FALSE with false, and
|
||||||
BOOL with bool.
|
BOOL with bool.
|
||||||
|
|
||||||
|
Fixed have_statfs optional executable file extension ${EXT{ in
|
||||||
|
the ${UTIL_PROGS} make variable.
|
||||||
|
|
||||||
|
Prevented the "fake boolean value" when <stdbool.h> is missing,
|
||||||
|
from complicating C compilers post c17 standard.
|
||||||
|
|
||||||
|
Test if <stdint.h> exists and set HAVE_STDINT_H accordingly
|
||||||
|
in have_stdint.h. Added HAVE_STDINT_H to allow one to force
|
||||||
|
this value.
|
||||||
|
|
||||||
|
Test if <inttypes.h> exists and set HAVE_INTTYPES_H accordingly
|
||||||
|
in have_inttypes.h. Added HAVE_INTTYPES_H to allow one to force
|
||||||
|
this value.
|
||||||
|
|
||||||
|
Added c_chk.c to check the compiler and C include for calc
|
||||||
|
requirements. If you are unable to compile this program, or
|
||||||
|
if this program when compiles does not exit 0, then your C
|
||||||
|
compiler and/or C include fails to meet calc requirements.
|
||||||
|
Compilers that are at least c99 MUST be able to compile this
|
||||||
|
program such that when run will exit 0.
|
||||||
|
|
||||||
|
The "make hsrc" file will attempt to compile and run c_chk and
|
||||||
|
will warn if the C compiler and/or C include fails to meet
|
||||||
|
calc requirements. The "make debug" system will run c_chk -c
|
||||||
|
to print information about the C compiler and C include.
|
||||||
|
Currently failure to compile cc_chk.c or c_chk exiting non-0
|
||||||
|
will just print "WARNING!!" strings to stderr.
|
||||||
|
|
||||||
|
|
||||||
The following are the changes from calc version 2.14.3.4 to 2.14.3.5:
|
The following are the changes from calc version 2.14.3.4 to 2.14.3.5:
|
||||||
|
|
||||||
|
126
Makefile
126
Makefile
@@ -179,7 +179,8 @@ BUILD_H_SRC= align32.h args.h calcerr.h conf.h endian_calc.h \
|
|||||||
have_uid_t.h have_unistd.h have_unused.h have_urandom.h \
|
have_uid_t.h have_unistd.h have_unused.h have_urandom.h \
|
||||||
have_ustat.h longbits.h terminal.h have_environ.h \
|
have_ustat.h longbits.h terminal.h have_environ.h \
|
||||||
have_arc4random.h have_limits.h charbit.h have_sys_vfs.h \
|
have_arc4random.h have_limits.h charbit.h have_sys_vfs.h \
|
||||||
have_sys_param.h have_sys_mount.h have_statfs.h have_stdbool.h
|
have_sys_param.h have_sys_mount.h have_statfs.h have_stdbool.h \
|
||||||
|
have_stdint.h
|
||||||
|
|
||||||
# we build these .c files during the make
|
# we build these .c files during the make
|
||||||
#
|
#
|
||||||
@@ -195,7 +196,7 @@ UTIL_C_SRC= align32.c endian.c longbits.c have_newstr.c have_uid_t.c \
|
|||||||
have_ustat.c have_getsid.c have_getpgid.c have_environ.c \
|
have_ustat.c have_getsid.c have_getpgid.c have_environ.c \
|
||||||
have_gettime.c have_getprid.c have_rusage.c have_strdup.c \
|
have_gettime.c have_getprid.c have_rusage.c have_strdup.c \
|
||||||
have_unused.c have_ban_pragma.c have_strlcpy.c have_strlcat.c \
|
have_unused.c have_ban_pragma.c have_strlcpy.c have_strlcat.c \
|
||||||
have_arc4random.c charbit.c have_statfs.c
|
have_arc4random.c charbit.c have_statfs.c chk_c.c
|
||||||
|
|
||||||
# these awk and sed tools are used in the process of building BUILD_H_SRC
|
# these awk and sed tools are used in the process of building BUILD_H_SRC
|
||||||
# and BUILD_C_SRC
|
# and BUILD_C_SRC
|
||||||
@@ -213,7 +214,7 @@ UTIL_OBJS= endian.o longbits.o have_newstr.o have_uid_t.o \
|
|||||||
have_ustat.o have_getsid.o have_getpgid.o have_environ.o \
|
have_ustat.o have_getsid.o have_getpgid.o have_environ.o \
|
||||||
have_gettime.o have_getprid.o ver_calc.o have_rusage.o have_strdup.o \
|
have_gettime.o have_getprid.o ver_calc.o have_rusage.o have_strdup.o \
|
||||||
have_unused.o have_ban_pragma.o have_strlcpy.o have_strlcat.o \
|
have_unused.o have_ban_pragma.o have_strlcpy.o have_strlcat.o \
|
||||||
have_arc4random.o charbit.o have_statfs.o
|
have_arc4random.o charbit.o have_statfs.o chk_c.o
|
||||||
|
|
||||||
# these temp files may be created (and removed) during the build of BUILD_C_SRC
|
# these temp files may be created (and removed) during the build of BUILD_C_SRC
|
||||||
#
|
#
|
||||||
@@ -232,7 +233,7 @@ UTIL_PROGS= align32${EXT} fposval${EXT} have_uid_t${EXT} have_const${EXT} \
|
|||||||
have_unused${EXT} have_fpos${EXT} have_fpos_pos${EXT} \
|
have_unused${EXT} have_fpos${EXT} have_fpos_pos${EXT} \
|
||||||
have_offscl${EXT} have_rusage${EXT} have_ban_pragma${EXT} \
|
have_offscl${EXT} have_rusage${EXT} have_ban_pragma${EXT} \
|
||||||
have_strlcpy${EXT} have_strlcat${EXT} have_arc4random${EXT} \
|
have_strlcpy${EXT} have_strlcat${EXT} have_arc4random${EXT} \
|
||||||
charbit${EXT} have_statfs${ENT}
|
charbit${EXT} have_statfs${EXT} chk_c${EXT}
|
||||||
|
|
||||||
# these utility files and scripts may be created in the process of building
|
# these utility files and scripts may be created in the process of building
|
||||||
# the BUILD_H_SRC file set
|
# the BUILD_H_SRC file set
|
||||||
@@ -569,7 +570,7 @@ file.o: file.c ${MK_SET}
|
|||||||
#
|
#
|
||||||
###
|
###
|
||||||
|
|
||||||
hsrc: ${BUILD_H_SRC} ${BUILD_C_SRC}
|
hsrc: ${BUILD_H_SRC} ${BUILD_C_SRC} chk_c${EXT}
|
||||||
|
|
||||||
.hsrc: ${BUILD_H_SRC} ${BUILD_C_SRC}
|
.hsrc: ${BUILD_H_SRC} ${BUILD_C_SRC}
|
||||||
${Q} ${RM} -f .hsrc
|
${Q} ${RM} -f .hsrc
|
||||||
@@ -962,6 +963,78 @@ have_stdbool.h: ${MK_SET}
|
|||||||
${TRUE}; \
|
${TRUE}; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
have_stdint.h: ${MK_SET}
|
||||||
|
${Q} ${RM} -f $@
|
||||||
|
${H} echo 'forming $@'
|
||||||
|
${Q} echo '/*' > $@
|
||||||
|
${Q} echo ' * DO NOT EDIT -- generated by the Makefile rule $@' >> $@
|
||||||
|
${Q} echo ' */' >> $@
|
||||||
|
${Q} echo '' >> $@
|
||||||
|
${Q} echo '' >> $@
|
||||||
|
${Q} echo '#if !defined(CALC_HAVE_STDINT_H)' >> $@
|
||||||
|
${Q} echo '#define CALC_HAVE_STDINT_H' >> $@
|
||||||
|
${Q} echo '' >> $@
|
||||||
|
${Q} echo '' >> $@
|
||||||
|
${Q} echo '/* do we have <stdint.h>? */' >> $@
|
||||||
|
-${Q} if [ X"${HAVE_STDINT_H}" = X"YES" ]; then \
|
||||||
|
echo '#define HAVE_STDINT_H /* yes */' >> $@; \
|
||||||
|
elif [ X"${HAVE_STDINT_H}" = X"NO" ]; then \
|
||||||
|
echo '#undef HAVE_STDINT_H /* no */' >> $@; \
|
||||||
|
elif echo '#include <stdint.h>' | ${CC} -E - ${S}; then \
|
||||||
|
echo '#define HAVE_STDINT_H /* yes */' >> $@; \
|
||||||
|
else \
|
||||||
|
echo '#undef HAVE_STDINT_H /* no */' >> $@; \
|
||||||
|
fi
|
||||||
|
${Q} echo '' >> $@
|
||||||
|
${Q} echo '' >> $@
|
||||||
|
${Q} echo '#endif /* !CALC_HAVE_STDINT_H */' >> $@
|
||||||
|
${H} echo '$@ formed'
|
||||||
|
-@if [ -z "${Q}" ]; then \
|
||||||
|
echo ''; \
|
||||||
|
echo '=-=-= start of $@ =-=-='; \
|
||||||
|
${CAT} $@; \
|
||||||
|
echo '=-=-= end of $@ =-=-='; \
|
||||||
|
echo ''; \
|
||||||
|
else \
|
||||||
|
${TRUE}; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
have_inttypes.h: ${MK_SET}
|
||||||
|
${Q} ${RM} -f $@
|
||||||
|
${H} echo 'forming $@'
|
||||||
|
${Q} echo '/*' > $@
|
||||||
|
${Q} echo ' * DO NOT EDIT -- generated by the Makefile rule $@' >> $@
|
||||||
|
${Q} echo ' */' >> $@
|
||||||
|
${Q} echo '' >> $@
|
||||||
|
${Q} echo '' >> $@
|
||||||
|
${Q} echo '#if !defined(CALC_HAVE_INTTYPES_H)' >> $@
|
||||||
|
${Q} echo '#define CALC_HAVE_INTTYPES_H' >> $@
|
||||||
|
${Q} echo '' >> $@
|
||||||
|
${Q} echo '' >> $@
|
||||||
|
${Q} echo '/* do we have <inttypes.h>? */' >> $@
|
||||||
|
-${Q} if [ X"${HAVE_INTTYPES_H}" = X"YES" ]; then \
|
||||||
|
echo '#define HAVE_INTTYPES_H /* yes */' >> $@; \
|
||||||
|
elif [ X"${HAVE_INTTYPES_H}" = X"NO" ]; then \
|
||||||
|
echo '#undef HAVE_INTTYPES_H /* no */' >> $@; \
|
||||||
|
elif echo '#include <inttypes.h>' | ${CC} -E - ${S}; then \
|
||||||
|
echo '#define HAVE_INTTYPES_H /* yes */' >> $@; \
|
||||||
|
else \
|
||||||
|
echo '#undef HAVE_INTTYPES_H /* no */' >> $@; \
|
||||||
|
fi
|
||||||
|
${Q} echo '' >> $@
|
||||||
|
${Q} echo '' >> $@
|
||||||
|
${Q} echo '#endif /* !CALC_HAVE_INTTYPES_H */' >> $@
|
||||||
|
${H} echo '$@ formed'
|
||||||
|
-@if [ -z "${Q}" ]; then \
|
||||||
|
echo ''; \
|
||||||
|
echo '=-=-= start of $@ =-=-='; \
|
||||||
|
${CAT} $@; \
|
||||||
|
echo '=-=-= end of $@ =-=-='; \
|
||||||
|
echo ''; \
|
||||||
|
else \
|
||||||
|
${TRUE}; \
|
||||||
|
fi
|
||||||
|
|
||||||
have_string.h: ${MK_SET}
|
have_string.h: ${MK_SET}
|
||||||
${Q} ${RM} -f $@
|
${Q} ${RM} -f $@
|
||||||
${H} echo 'forming $@'
|
${H} echo 'forming $@'
|
||||||
@@ -2313,6 +2386,26 @@ have_strlcat.h: have_strlcat.c banned.h have_ban_pragma.h have_string.h \
|
|||||||
${TRUE}; \
|
${TRUE}; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
chk_c${EXT}: chk_c.c have_stdint.h have_inttypes.h have_stdlib.h bool.h have_ban_pragma.h banned.h
|
||||||
|
${V} echo '=-=-=-=-= ${MAKE_FILE} start of $@ rule =-=-=-=-='
|
||||||
|
${Q} ${RM} -f chk_c.o chk_c${EXT}
|
||||||
|
-${Q} ${LCC} ${ICFLAGS} chk_c.c -c ${S} \
|
||||||
|
|| echo "WARNING!! failed to compile chk_c.c" 1>&2
|
||||||
|
-${Q} ${LCC} ${ILDFLAGS} chk_c.o -o chk_c${EXT} ${S} \
|
||||||
|
|| echo "WARNING!! failed to form chk_c${EXT} executable" 1>&2
|
||||||
|
-${Q}if [ ! -x chk_c${EXT} ]; then \
|
||||||
|
echo "WARNING!! Your C compiler and/or C include does not meet calc requirements" 1>&2; \
|
||||||
|
else \
|
||||||
|
echo "formed $@ executable"; \
|
||||||
|
echo 'about to run $@'; \
|
||||||
|
if ! ./$@; then \
|
||||||
|
echo "WARNING!! $@ failed to validate C compiler and/or C include for calc requirements" 1>&2; \
|
||||||
|
else \
|
||||||
|
echo "Good news everyone! :-) The C compiler and C include appears to meet calc requirements" 1>&2; \
|
||||||
|
fi; \
|
||||||
|
fi
|
||||||
|
${V} echo '=-=-=-=-= ${MAKE_FILE} end of $@ rule =-=-=-=-='
|
||||||
|
|
||||||
###
|
###
|
||||||
#
|
#
|
||||||
# These two .all rules are used to determine of the lower level
|
# These two .all rules are used to determine of the lower level
|
||||||
@@ -2780,6 +2873,7 @@ env:
|
|||||||
@echo 'HAVE_GETRUSAGE=${HAVE_GETRUSAGE}'; echo ''
|
@echo 'HAVE_GETRUSAGE=${HAVE_GETRUSAGE}'; echo ''
|
||||||
@echo 'HAVE_GETSID=${HAVE_GETSID}'; echo ''
|
@echo 'HAVE_GETSID=${HAVE_GETSID}'; echo ''
|
||||||
@echo 'HAVE_GETTIME=${HAVE_GETTIME}'; echo ''
|
@echo 'HAVE_GETTIME=${HAVE_GETTIME}'; echo ''
|
||||||
|
@echo 'HAVE_INTTYPES_H=${HAVE_INTTYPES_H}'; echo ''
|
||||||
@echo 'HAVE_LIMITS_H=${HAVE_LIMITS_H}'; echo ''
|
@echo 'HAVE_LIMITS_H=${HAVE_LIMITS_H}'; echo ''
|
||||||
@echo 'HAVE_MEMMOVE=${HAVE_MEMMOVE}'; echo ''
|
@echo 'HAVE_MEMMOVE=${HAVE_MEMMOVE}'; echo ''
|
||||||
@echo 'HAVE_NEWSTR=${HAVE_NEWSTR}'; echo ''
|
@echo 'HAVE_NEWSTR=${HAVE_NEWSTR}'; echo ''
|
||||||
@@ -2788,6 +2882,7 @@ env:
|
|||||||
@echo 'HAVE_PRAGMA_GCC_POSION=${HAVE_PRAGMA_GCC_POSION}'; echo ''
|
@echo 'HAVE_PRAGMA_GCC_POSION=${HAVE_PRAGMA_GCC_POSION}'; echo ''
|
||||||
@echo 'HAVE_STATFS=${HAVE_STATFS}'; echo ''
|
@echo 'HAVE_STATFS=${HAVE_STATFS}'; echo ''
|
||||||
@echo 'HAVE_STDBOOL_H=${HAVE_STDBOOL_H}'; echo ''
|
@echo 'HAVE_STDBOOL_H=${HAVE_STDBOOL_H}'; echo ''
|
||||||
|
@echo 'HAVE_STDINT_H=${HAVE_STDINT_H}'; echo ''
|
||||||
@echo 'HAVE_STDLIB_H=${HAVE_STDLIB_H}'; echo ''
|
@echo 'HAVE_STDLIB_H=${HAVE_STDLIB_H}'; echo ''
|
||||||
@echo 'HAVE_STRDUP=${HAVE_STRDUP}'; echo ''
|
@echo 'HAVE_STRDUP=${HAVE_STRDUP}'; echo ''
|
||||||
@echo 'HAVE_STRING_H=${HAVE_STRING_H}'; echo ''
|
@echo 'HAVE_STRING_H=${HAVE_STRING_H}'; echo ''
|
||||||
@@ -2928,22 +3023,29 @@ full_debug: calcinfo env
|
|||||||
@echo '=-=-=-= Contents of ${TARGET_MKF} follows =-=-=-='
|
@echo '=-=-=-= Contents of ${TARGET_MKF} follows =-=-=-='
|
||||||
-@${CAT} ${TARGET_MKF}
|
-@${CAT} ${TARGET_MKF}
|
||||||
@echo '=-=-=-= End of contents of ${TARGET_MKF} =-=-=-='
|
@echo '=-=-=-= End of contents of ${TARGET_MKF} =-=-=-='
|
||||||
@echo '=-=-=-= Invoking ${MAKE} -f Makefile Q= V=@ clobber =-=-=-='
|
@echo '=-=-= Invoking ${MAKE} -f Makefile Q= V=@ clobber =-=-=-='
|
||||||
-@${MAKE} -f Makefile Q= H=@ S= E= V=@ clobber
|
-@${MAKE} -f Makefile Q= H=@ S= E= V=@ clobber
|
||||||
@echo '=-=-=-= Back to the main Makefile for $@ rule =-=-=-='
|
@echo '=-=-=-= Back to the main Makefile for $@ rule =-=-=-='
|
||||||
@echo '=-=-=-= Invoking ${MAKE} -f Makefile Q= V=@ all =-=-=-='
|
@echo '=-=-= Invoking ${MAKE} -f Makefile Q= V=@ all =-=-=-='
|
||||||
@echo '=-=-= this may take a bit of time =-=-='
|
@echo '=-=-= this may take a bit of time =-=-='
|
||||||
-@${MAKE} -f Makefile Q= H=@ S= E= V=@ all
|
-@${MAKE} -f Makefile Q= H=@ S= E= V=@ all
|
||||||
@echo '=-=-=-= Back to the main Makefile for $@ rule =-=-=-='
|
@echo '=-=-=-= Back to the main Makefile for $@ rule =-=-=-='
|
||||||
|
@echo '=-=-=-= Determining C compiler and C enviroment compatibility =-=-=-='
|
||||||
|
@echo '=-=-= Invoking ${MAKE} -f Makefile Q= V=@ chk_c${EXT} =-=-=-='
|
||||||
|
-@${MAKE} -f Makefile Q= H=@ S= E= V=@ chk_c${EXT}
|
||||||
|
@echo '=-=-= Executing chk_c${EXT} -c =-=-=-='
|
||||||
|
-@./chk_c${EXT} -c
|
||||||
|
@echo '=-=-=-= Back to the main Makefile for $@ rule =-=-=-='
|
||||||
@echo '=-=-=-= Determining the source version =-=-=-='
|
@echo '=-=-=-= Determining the source version =-=-=-='
|
||||||
|
@echo '=-=-= Invoking ${MAKE} -f Makefile Q= H=@ S= E= V=@ ver_calc${EXT} =-=-=-='
|
||||||
-@${MAKE} -f Makefile Q= H=@ S= E= V=@ ver_calc${EXT}
|
-@${MAKE} -f Makefile Q= H=@ S= E= V=@ ver_calc${EXT}
|
||||||
-@./ver_calc${EXT}
|
-@./ver_calc${EXT}
|
||||||
@echo '=-=-=-= Back to the main Makefile for $@ rule =-=-=-='
|
@echo '=-=-=-= Back to the main Makefile for $@ rule =-=-=-='
|
||||||
-@${ECHON} '=-=-=-= Print #defile values if custom functions '
|
-@${ECHON} '=-=-=-= Print #define values if custom functions '
|
||||||
@echo 'are allowed =-=-=-='
|
@echo 'are allowed =-=-=-='
|
||||||
-@${CALC_ENV} ./calc${EXT} -e -q -C 'print custom("sysinfo", 2);'
|
-@${CALC_ENV} ./calc${EXT} -e -q -C 'print custom("sysinfo", 2);'
|
||||||
@echo '=-=-=-= Back to the main Makefile for $@ rule =-=-=-='
|
@echo '=-=-=-= Back to the main Makefile for $@ rule =-=-=-='
|
||||||
@echo '=-=-=-= Invoking ${MAKE} -f Makefile Q= V=@ check =-=-=-='
|
@echo '=-=-= Invoking ${MAKE} -f Makefile Q= V=@ check =-=-=-='
|
||||||
@echo '=-=-= this may take a while =-=-='
|
@echo '=-=-= this may take a while =-=-='
|
||||||
-@${MAKE} -f Makefile Q= V=@ check
|
-@${MAKE} -f Makefile Q= V=@ check
|
||||||
@echo '=-=-=-= Back to the main Makefile for $@ rule =-=-=-='
|
@echo '=-=-=-= Back to the main Makefile for $@ rule =-=-=-='
|
||||||
@@ -4000,6 +4102,12 @@ charbit.o: banned.h
|
|||||||
charbit.o: charbit.c
|
charbit.o: charbit.c
|
||||||
charbit.o: have_ban_pragma.h
|
charbit.o: have_ban_pragma.h
|
||||||
charbit.o: have_limits.h
|
charbit.o: have_limits.h
|
||||||
|
chk_c.o: banned.h
|
||||||
|
chk_c.o: bool.h
|
||||||
|
chk_c.o: chk_c.c
|
||||||
|
chk_c.o: have_ban_pragma.h
|
||||||
|
chk_c.o: have_stdint.h
|
||||||
|
chk_c.o: have_stdlib.h
|
||||||
codegen.o: alloc.h
|
codegen.o: alloc.h
|
||||||
codegen.o: attribute.h
|
codegen.o: attribute.h
|
||||||
codegen.o: banned.h
|
codegen.o: banned.h
|
||||||
|
@@ -717,6 +717,30 @@ HAVE_STDBOOL_H=
|
|||||||
#HAVE_STDBOOL_H= YES
|
#HAVE_STDBOOL_H= YES
|
||||||
#HAVE_STDBOOL_H= NO
|
#HAVE_STDBOOL_H= NO
|
||||||
|
|
||||||
|
# Determine if we have the <stdint.h> include file.
|
||||||
|
#
|
||||||
|
# HAVE_STDINT_H= let the Makefile look for the include file
|
||||||
|
# HAVE_STDINT_H= YES assume that the include file exists
|
||||||
|
# HAVE_STDINT_H= NO assume that the include file does not exist
|
||||||
|
#
|
||||||
|
# When in doubt, leave HAVE_STDINT_H empty.
|
||||||
|
#
|
||||||
|
HAVE_STDINT_H=
|
||||||
|
#HAVE_STDINT_H= YES
|
||||||
|
#HAVE_STDINT_H= NO
|
||||||
|
|
||||||
|
# Determine if we have the <inttypes.h> include file.
|
||||||
|
#
|
||||||
|
# HAVE_INTTYPES_H= let the Makefile look for the include file
|
||||||
|
# HAVE_INTTYPES_H= YES assume that the include file exists
|
||||||
|
# HAVE_INTTYPES_H= NO assume that the include file does not exist
|
||||||
|
#
|
||||||
|
# When in doubt, leave HAVE_INTTYPES_H empty.
|
||||||
|
#
|
||||||
|
HAVE_INTTYPES_H=
|
||||||
|
#HAVE_INTTYPES_H= YES
|
||||||
|
#HAVE_INTTYPES_H= NO
|
||||||
|
|
||||||
# Determine if our compiler allows the unused attribute
|
# Determine if our compiler allows the unused attribute
|
||||||
#
|
#
|
||||||
# If HAVE_UNUSED is empty, this Makefile will run the have_unused program
|
# If HAVE_UNUSED is empty, this Makefile will run the have_unused program
|
||||||
|
4
bool.h
4
bool.h
@@ -42,7 +42,9 @@
|
|||||||
#if !defined(HAVE_STDBOOL_H)
|
#if !defined(HAVE_STDBOOL_H)
|
||||||
|
|
||||||
/* fake a <stdbool.h> header file */
|
/* fake a <stdbool.h> header file */
|
||||||
typedef unsigned char bool; /* fake boolean value */
|
#if __STDC_VERSION__ <= 201710
|
||||||
|
typedef unsigned int bool; /* fake boolean typedef */
|
||||||
|
#endif /* __STDC_VERSION__ <= 201710 */
|
||||||
#undef true
|
#undef true
|
||||||
#define true ((bool)(1))
|
#define true ((bool)(1))
|
||||||
#undef false
|
#undef false
|
||||||
|
313
chk_c.c
Normal file
313
chk_c.c
Normal file
@@ -0,0 +1,313 @@
|
|||||||
|
/*
|
||||||
|
* chk_c - chk C compiler and C include for calc requirements
|
||||||
|
*
|
||||||
|
* This program, to successfully compile, must include:
|
||||||
|
*
|
||||||
|
* #include <stdint.h>
|
||||||
|
* #include <inttypes.h>
|
||||||
|
*
|
||||||
|
* and must be able to compile all of these types:
|
||||||
|
*
|
||||||
|
* int8_t uint8_t
|
||||||
|
* int16_t uint16_t
|
||||||
|
* int32_t uint32_t
|
||||||
|
* int64_t uint64_t
|
||||||
|
* intmax_t uintmax_t
|
||||||
|
*
|
||||||
|
* be able to sum values from all of those files,
|
||||||
|
* plus the INTX_C(val) and UINTX_C(val) composing macros,
|
||||||
|
* and be able to print for signed and unsigned 32-bit, 64-bit and max-bit values.
|
||||||
|
*
|
||||||
|
* If you are unable to compile this program, or if this program when
|
||||||
|
* compiles does not exit 0, then your C compiler and/or C include
|
||||||
|
* fails to meet calc requirements.
|
||||||
|
*
|
||||||
|
* Compilers that are at least c99 MUST be able to compile this program
|
||||||
|
* such that when run will exit 0.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2023 Landon Curt Noll
|
||||||
|
*
|
||||||
|
* Calc is open software; you can redistribute it and/or modify it under
|
||||||
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
|
* as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* Calc is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||||
|
* Public License for more details.
|
||||||
|
*
|
||||||
|
* A copy of version 2.1 of the GNU Lesser General Public License is
|
||||||
|
* distributed with calc under the filename COPYING-LGPL. You should have
|
||||||
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
* Under source code control: 2023/08/20 23:57:50
|
||||||
|
* File existed as early as: 2023
|
||||||
|
*
|
||||||
|
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||||
|
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "have_stdint.h"
|
||||||
|
#if defined(HAVE_STDINT_H)
|
||||||
|
#include <stdint.h>
|
||||||
|
#endif /* HAVE_STDINT_H */
|
||||||
|
|
||||||
|
#include "have_inttypes.h"
|
||||||
|
#if defined(HAVE_INTTYPES_H)
|
||||||
|
#include <inttypes.h>
|
||||||
|
#endif /* HAVE_INTTYPES_H */
|
||||||
|
|
||||||
|
#include "have_stdlib.h"
|
||||||
|
#if defined(HAVE_STDLIB_H)
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif /* HAVE_STDLIB_H */
|
||||||
|
|
||||||
|
#include "bool.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* our version
|
||||||
|
*/
|
||||||
|
#define CHK_C_VERSION "1.0 2023-08-20"
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* usage:
|
||||||
|
*/
|
||||||
|
static char const *usage =
|
||||||
|
"usage: %s [-h] [-c] [-V]\n"
|
||||||
|
"\n"
|
||||||
|
"\t-h\t\toutput this message and exit\n"
|
||||||
|
"\t-c\t\toutput C compiler and C include info (def: no stdout output)\n"
|
||||||
|
"\t-V\t\tprint version string and exit\n"
|
||||||
|
"\n"
|
||||||
|
"Exit codes:\n"
|
||||||
|
" 0 all OK\n"
|
||||||
|
" 1 C compiler and C include is insufficient for calc\n"
|
||||||
|
" 2 -h and help string printed or -V and version string printed\n"
|
||||||
|
" 3 invalid command line, invalid option or option missing an argument\n"
|
||||||
|
" >= 10 internal error\n"
|
||||||
|
"\n"
|
||||||
|
"chk_c version: %s\n";
|
||||||
|
|
||||||
|
|
||||||
|
#include "banned.h" /* include after system header <> includes */
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char *program = "((NULL))"; /* our name */
|
||||||
|
int opt; /* the -option found or -1 */
|
||||||
|
bool c_flag = false; /* if -h was found */
|
||||||
|
#if defined(HAVE_STDINT_H) && defined(HAVE_INTTYPES_H)
|
||||||
|
int i = -1; /* signed int test value */
|
||||||
|
unsigned int ui = 1; /* unsigned int test value */
|
||||||
|
long l = -2L; /* signed long test value */
|
||||||
|
unsigned long ul = 2UL; /* unsigned long test value */
|
||||||
|
long long ll = -4LL; /* signed long long test value */
|
||||||
|
unsigned long long ull = 4ULL; /* unsigned long long test value */
|
||||||
|
int8_t i8 = INT8_C(-8); /* signed 8-bit test value */
|
||||||
|
uint8_t ui8 = UINT8_C(8); /* unsigned 8-bit test value */
|
||||||
|
int16_t i16 = INT16_C(-16); /* signed 16-bit test value */
|
||||||
|
uint16_t ui16 = UINT16_C(16); /* unsigned 16-bit test value */
|
||||||
|
int32_t i32 = INT32_C(-32); /* signed 32-bit test value */
|
||||||
|
uint32_t ui32 = UINT32_C(32); /* unsigned 32-bit test value */
|
||||||
|
int64_t i64 = INT64_C(-64); /* signed 64-bit test value */
|
||||||
|
uint64_t ui64 = UINT64_C(64); /* unsigned 64-bit test value */
|
||||||
|
intmax_t imax = INTMAX_C(-256); /* maximum sized signed int test value */
|
||||||
|
uintmax_t uimax = UINTMAX_C(256); /* maximum sized unsigned int test value */
|
||||||
|
uintmax_t isum = 0; /* sum of all test values as signed value */
|
||||||
|
uintmax_t uisum = 0; /* sum of all test values as unsigned value */
|
||||||
|
#endif /* HAVE_STDINT_H && HAVE_INTTYPES_H */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* parse args
|
||||||
|
*/
|
||||||
|
program = argv[0];
|
||||||
|
while ((opt = getopt(argc, argv, "hcV")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'h':
|
||||||
|
fprintf(stderr, usage, program, CHK_C_VERSION);
|
||||||
|
exit(2);
|
||||||
|
break;
|
||||||
|
case 'c':
|
||||||
|
c_flag = true;
|
||||||
|
break;
|
||||||
|
case 'V':
|
||||||
|
printf("%s\n", CHK_C_VERSION);
|
||||||
|
exit(2);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(stderr, usage, program, CHK_C_VERSION);
|
||||||
|
exit(3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (optind != argc) {
|
||||||
|
fprintf(stderr, usage, program, CHK_C_VERSION);
|
||||||
|
exit(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* must have <stdint.h>
|
||||||
|
*/
|
||||||
|
#if !defined(HAVE_STDINT_H)
|
||||||
|
if (c_flag == true) {
|
||||||
|
printf("HAVE_STDINT_H is undefined\n");
|
||||||
|
}
|
||||||
|
fprintf(stderr, "calc requires <stdint.h> include file\n");
|
||||||
|
exit(1);
|
||||||
|
#else /* HAVE_STDINT_H */
|
||||||
|
if (c_flag == true) {
|
||||||
|
printf("HAVE_STDINT_H is defined\n");
|
||||||
|
printf("<stdint.h> successfully included\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* must have <inttypes.h>
|
||||||
|
*/
|
||||||
|
#if !defined(HAVE_INTTYPES_H)
|
||||||
|
if (c_flag == true) {
|
||||||
|
printf("HAVE_INTTYPES_H is undefined\n");
|
||||||
|
}
|
||||||
|
fprintf(stderr, "calc requires <inttypes.h> include file\n");
|
||||||
|
exit(1);
|
||||||
|
#else /* HAVE_INTTYPES_H */
|
||||||
|
if (c_flag == true) {
|
||||||
|
printf("\nHAVE_INTTYPES_H is defined\n");
|
||||||
|
printf("<inttypes.h> successfully included\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check for __STDC__ defined
|
||||||
|
*/
|
||||||
|
#if !defined(__STDC__)
|
||||||
|
fprintf(stderr, "__STDC__ is not defined\n");
|
||||||
|
exit(1);
|
||||||
|
#endif /* __STDC__ */
|
||||||
|
if (c_flag == true) {
|
||||||
|
printf("\n__STDC__ is defined\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check for __STDC_VERSION__ defined
|
||||||
|
*/
|
||||||
|
#if !defined(__STDC__)
|
||||||
|
fprintf(stderr, "__STDC_VERSION__ is not defined\n");
|
||||||
|
exit(1);
|
||||||
|
#endif /* __STDC_VERSION__ */
|
||||||
|
if (c_flag == true) {
|
||||||
|
printf("__STDC_VERSION__: %ld is defined\n", __STDC_VERSION__);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check for __STDC_VERSION__ >= 199901L for c99 or later
|
||||||
|
*/
|
||||||
|
#if __STDC_VERSION__ < 199901L
|
||||||
|
fprintf(stderr, "__STDC_VERSION__: %ld < 199901L\n", __STDC_VERSION__);
|
||||||
|
exit(1);
|
||||||
|
#endif /* __STDC_VERSION__ >= 199901L */
|
||||||
|
if (c_flag == true) {
|
||||||
|
printf("__STDC_VERSION__: %ld >= 199901L\n", __STDC_VERSION__);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* calculate sum of all test values as signed value
|
||||||
|
*/
|
||||||
|
isum = i + ui + l + ul + ll + ull + i8 + ui8 + i16 + ui16 + i32 + ui32 + i64 + ui64 + imax + uimax;
|
||||||
|
if (c_flag == true) {
|
||||||
|
printf("\nzero valued isum: %jd\n", isum);
|
||||||
|
}
|
||||||
|
if (isum != 0) {
|
||||||
|
fprintf(stderr, "failed to add all required integer types into a signed value\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* calculate sum of all test values as unsigned value
|
||||||
|
*/
|
||||||
|
uisum = i + ui + l + ul + ll + ull + i8 + ui8 + i16 + ui16 + i32 + ui32 + i64 + ui64 + imax + uimax;
|
||||||
|
if (c_flag == true) {
|
||||||
|
printf("zero valued uisum: %ju\n", uisum);
|
||||||
|
}
|
||||||
|
if (uisum != 0) {
|
||||||
|
fprintf(stderr, "failed to add all required integer types into an unsigned value\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* verify various 32, 64 and max PRI macros as well as MIN and MAX constants
|
||||||
|
*/
|
||||||
|
if (c_flag == true) {
|
||||||
|
printf("\nsigned integer MIN and MAX\n");
|
||||||
|
printf("INT32_MIN: %+"PRId32"\n", INT32_MIN);
|
||||||
|
printf("INT32_MAX: %+"PRId32"\n", INT32_MAX);
|
||||||
|
printf("INT64_MIN: %+"PRId64"\n", INT64_MIN);
|
||||||
|
printf("INT64_MAX: %+"PRId64"\n", INT64_MAX);
|
||||||
|
printf("INTMAX_MIN: %+"PRIdMAX"\n", INTMAX_MIN);
|
||||||
|
printf("INTMAX_MAX: %+"PRIdMAX"\n", INTMAX_MAX);
|
||||||
|
|
||||||
|
printf("\nunsigned integer MAX\n");
|
||||||
|
printf("UINT32_MAX: %"PRIu32"\n", UINT32_MAX);
|
||||||
|
printf("UINT64_MAX: %"PRIu64"\n", UINT64_MAX);
|
||||||
|
printf("UINTMAX_MAX: %"PRIuMAX"\n", UINTMAX_MAX);
|
||||||
|
|
||||||
|
printf("\ninteger MIN and MAX\n");
|
||||||
|
printf("INT32_MIN: %"PRIi32"\n", INT32_MIN);
|
||||||
|
printf("INT32_MAX: %"PRIi32"\n", INT32_MAX);
|
||||||
|
printf("INT64_MIN: %"PRIi64"\n", INT64_MIN);
|
||||||
|
printf("INT64_MAX: %"PRIi64"\n", INT64_MAX);
|
||||||
|
printf("INTMAX_MIN: %"PRIiMAX"\n", INTMAX_MIN);
|
||||||
|
printf("INTMAX_MAX: %"PRIiMAX"\n", INTMAX_MAX);
|
||||||
|
|
||||||
|
printf("\noctal MIN and MAX\n");
|
||||||
|
printf("INT32_MIN: %"PRIo32"\n", INT32_MIN);
|
||||||
|
printf("INT32_MAX: %"PRIo32"\n", INT32_MAX);
|
||||||
|
printf("INT64_MIN: %"PRIo64"\n", INT64_MIN);
|
||||||
|
printf("INT64_MAX: %"PRIo64"\n", INT64_MAX);
|
||||||
|
printf("INTMAX_MIN: %"PRIoMAX"\n", INTMAX_MIN);
|
||||||
|
printf("INTMAX_MAX: %"PRIoMAX"\n", INTMAX_MAX);
|
||||||
|
|
||||||
|
printf("\nhex MIN and MAX\n");
|
||||||
|
printf("INT32_MIN: %"PRIx32"\n", INT32_MIN);
|
||||||
|
printf("INT32_MAX: %"PRIx32"\n", INT32_MAX);
|
||||||
|
printf("INT64_MIN: %"PRIx64"\n", INT64_MIN);
|
||||||
|
printf("INT64_MAX: %"PRIx64"\n", INT64_MAX);
|
||||||
|
printf("INTMAX_MIN: %"PRIxMAX"\n", INTMAX_MIN);
|
||||||
|
printf("INTMAX_MAX: %"PRIxMAX"\n", INTMAX_MAX);
|
||||||
|
|
||||||
|
printf("\nHEX MIN and MAX\n");
|
||||||
|
printf("INT32_MIN: %"PRIX32"\n", INT32_MIN);
|
||||||
|
printf("INT32_MAX: %"PRIX32"\n", INT32_MAX);
|
||||||
|
printf("INT64_MIN: %"PRIX64"\n", INT64_MIN);
|
||||||
|
printf("INT64_MAX: %"PRIX64"\n", INT64_MAX);
|
||||||
|
printf("INTMAX_MIN: %"PRIXMAX"\n", INTMAX_MIN);
|
||||||
|
printf("INTMAX_MAX: %"PRIXMAX"\n", INTMAX_MAX);
|
||||||
|
|
||||||
|
printf("\nsizes\n");
|
||||||
|
printf("sizeof(int8_t): %lu\n", sizeof(int8_t));
|
||||||
|
printf("sizeof(uint8_t): %lu\n", sizeof(uint8_t));
|
||||||
|
printf("sizeof(int16_t): %lu\n", sizeof(int16_t));
|
||||||
|
printf("sizeof(uint16_t): %lu\n", sizeof(uint16_t));
|
||||||
|
printf("sizeof(int32_t): %lu\n", sizeof(int32_t));
|
||||||
|
printf("sizeof(uint32_t): %lu\n", sizeof(uint32_t));
|
||||||
|
printf("sizeof(int64_t): %lu\n", sizeof(int64_t));
|
||||||
|
printf("sizeof(uint64_t): %lu\n", sizeof(uint64_t));
|
||||||
|
printf("sizeof(intmax_t): %lu\n", sizeof(intmax_t));
|
||||||
|
printf("sizeof(uintmax_t): %lu\n", sizeof(uintmax_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* All Done!! -- Jessica Noll, age 2
|
||||||
|
*/
|
||||||
|
if (c_flag == true) {
|
||||||
|
printf("\nC compiler and C include appears to support calc\n");
|
||||||
|
}
|
||||||
|
exit(0);
|
||||||
|
#endif /* HAVE_INTTYPES_H */
|
||||||
|
#endif /* HAVE_STDINT_H */
|
||||||
|
}
|
Reference in New Issue
Block a user