diff options
author | H. Peter Anvin <hpa@linux.intel.com> | 2016-02-18 00:54:30 -0800 |
---|---|---|
committer | H. Peter Anvin <hpa@linux.intel.com> | 2016-02-18 01:03:51 -0800 |
commit | d338b376df915dfa6eb1d9fa651fb02b7d6dbce2 (patch) | |
tree | ed58e12e50e41ab2cb39d1a7fa72aae3f3761ca1 | |
parent | 9e1d691e82ea702d79a0e44e8a2cbf2c31dde164 (diff) | |
download | nasm-d338b376df915dfa6eb1d9fa651fb02b7d6dbce2.tar.gz |
Portability improvements and autoconf modernization
Improve the portability of the code and modernize our use of
autoconf.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
-rw-r--r-- | Makefile.in | 76 | ||||
-rw-r--r-- | aclocal.m4 | 45 | ||||
-rw-r--r-- | compiler.h | 15 | ||||
-rw-r--r-- | configure.in | 46 | ||||
-rw-r--r-- | ilog2.c | 7 | ||||
-rw-r--r-- | lib/strlcpy.c | 2 |
6 files changed, 95 insertions, 96 deletions
diff --git a/Makefile.in b/Makefile.in index 6ee17b49..10c666c1 100644 --- a/Makefile.in +++ b/Makefile.in @@ -22,9 +22,13 @@ INTERNAL_CFLAGS = -I$(srcdir) -I. ALL_CFLAGS = $(BUILD_CFLAGS) $(INTERNAL_CFLAGS) LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ -PERL = perl -I$(srcdir)/perllib +PERL = perl +PERLFLAGS = -I$(srcdir)/perllib -XOBJS = @XOBJS@ +RUNPERL = $(PERL) $(PERLFLAGS) + +LIBOBJDIR = @LIBOBJDIR@ +LIBOBJS = @LIBOBJS@ INSTALL = @INSTALL@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ @@ -102,11 +106,11 @@ NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ver.$(O) \ all: nasm$(X) ndisasm$(X) manpages rdf -nasm$(X): $(NASM) $(XOBJS) - $(CC) $(LDFLAGS) -o nasm$(X) $(NASM) $(XOBJS) $(LIBS) +nasm$(X): $(NASM) $(LIBOBJS) + $(CC) $(LDFLAGS) -o nasm$(X) $(NASM) $(LIBOBJS) $(LIBS) -ndisasm$(X): $(NDISASM) $(XOBJS) - $(CC) $(LDFLAGS) -o ndisasm$(X) $(NDISASM) $(XOBJS) $(LIBS) +ndisasm$(X): $(NDISASM) $(LIBOBJS) + $(CC) $(LDFLAGS) -o ndisasm$(X) $(NDISASM) $(LIBOBJS) $(LIBS) # These source files are automagically generated from a single # instruction-table file by a Perl script. They're distributed, @@ -115,79 +119,79 @@ ndisasm$(X): $(NDISASM) $(XOBJS) INSDEP = insns.dat insns.pl insns-iflags.pl iflag.c: $(INSDEP) - $(PERL) $(srcdir)/insns.pl -fc $(srcdir)/insns.dat + $(RUNPERL) $(srcdir)/insns.pl -fc $(srcdir)/insns.dat iflaggen.h: $(INSDEP) - $(PERL) $(srcdir)/insns.pl -fh $(srcdir)/insns.dat + $(RUNPERL) $(srcdir)/insns.pl -fh $(srcdir)/insns.dat insnsb.c: $(INSDEP) - $(PERL) $(srcdir)/insns.pl -b $(srcdir)/insns.dat + $(RUNPERL) $(srcdir)/insns.pl -b $(srcdir)/insns.dat insnsa.c: $(INSDEP) - $(PERL) $(srcdir)/insns.pl -a $(srcdir)/insns.dat + $(RUNPERL) $(srcdir)/insns.pl -a $(srcdir)/insns.dat insnsd.c: $(INSDEP) - $(PERL) $(srcdir)/insns.pl -d $(srcdir)/insns.dat + $(RUNPERL) $(srcdir)/insns.pl -d $(srcdir)/insns.dat insnsi.h: $(INSDEP) - $(PERL) $(srcdir)/insns.pl -i $(srcdir)/insns.dat + $(RUNPERL) $(srcdir)/insns.pl -i $(srcdir)/insns.dat insnsn.c: $(INSDEP) - $(PERL) $(srcdir)/insns.pl -n $(srcdir)/insns.dat + $(RUNPERL) $(srcdir)/insns.pl -n $(srcdir)/insns.dat # These files contains all the standard macros that are derived from # the version number. version.h: version version.pl - $(PERL) $(srcdir)/version.pl h < $(srcdir)/version > version.h + $(RUNPERL) $(srcdir)/version.pl h < $(srcdir)/version > version.h version.mac: version version.pl - $(PERL) $(srcdir)/version.pl mac < $(srcdir)/version > version.mac + $(RUNPERL) $(srcdir)/version.pl mac < $(srcdir)/version > version.mac version.sed: version version.pl - $(PERL) $(srcdir)/version.pl sed < $(srcdir)/version > version.sed + $(RUNPERL) $(srcdir)/version.pl sed < $(srcdir)/version > version.sed version.mak: version version.pl - $(PERL) $(srcdir)/version.pl make < $(srcdir)/version > version.mak + $(RUNPERL) $(srcdir)/version.pl make < $(srcdir)/version > version.mak version.nsh: version version.pl - $(PERL) $(srcdir)/version.pl nsis < $(srcdir)/version > version.nsh + $(RUNPERL) $(srcdir)/version.pl nsis < $(srcdir)/version > version.nsh # This source file is generated from the standard macros file # `standard.mac' by another Perl script. Again, it's part of the # standard distribution. macros.c: macros.pl pptok.ph standard.mac version.mac \ $(srcdir)/macros/*.mac $(srcdir)/output/*.mac - $(PERL) $(srcdir)/macros.pl $(srcdir)/standard.mac version.mac \ + $(RUNPERL) $(srcdir)/macros.pl $(srcdir)/standard.mac version.mac \ $(srcdir)/macros/*.mac $(srcdir)/output/*.mac # These source files are generated from regs.dat by yet another # perl script. regs.c: regs.dat regs.pl - $(PERL) $(srcdir)/regs.pl c $(srcdir)/regs.dat > regs.c + $(RUNPERL) $(srcdir)/regs.pl c $(srcdir)/regs.dat > regs.c regflags.c: regs.dat regs.pl - $(PERL) $(srcdir)/regs.pl fc $(srcdir)/regs.dat > regflags.c + $(RUNPERL) $(srcdir)/regs.pl fc $(srcdir)/regs.dat > regflags.c regdis.c: regs.dat regs.pl - $(PERL) $(srcdir)/regs.pl dc $(srcdir)/regs.dat > regdis.c + $(RUNPERL) $(srcdir)/regs.pl dc $(srcdir)/regs.dat > regdis.c regdis.h: regs.dat regs.pl - $(PERL) $(srcdir)/regs.pl dh $(srcdir)/regs.dat > regdis.h + $(RUNPERL) $(srcdir)/regs.pl dh $(srcdir)/regs.dat > regdis.h regvals.c: regs.dat regs.pl - $(PERL) $(srcdir)/regs.pl vc $(srcdir)/regs.dat > regvals.c + $(RUNPERL) $(srcdir)/regs.pl vc $(srcdir)/regs.dat > regvals.c regs.h: regs.dat regs.pl - $(PERL) $(srcdir)/regs.pl h $(srcdir)/regs.dat > regs.h + $(RUNPERL) $(srcdir)/regs.pl h $(srcdir)/regs.dat > regs.h # Assembler token hash tokhash.c: insns.dat regs.dat tokens.dat tokhash.pl perllib/phash.ph - $(PERL) $(srcdir)/tokhash.pl c $(srcdir)/insns.dat $(srcdir)/regs.dat \ + $(RUNPERL) $(srcdir)/tokhash.pl c $(srcdir)/insns.dat $(srcdir)/regs.dat \ $(srcdir)/tokens.dat > tokhash.c # Assembler token metadata tokens.h: insns.dat regs.dat tokens.dat tokhash.pl perllib/phash.ph - $(PERL) $(srcdir)/tokhash.pl h $(srcdir)/insns.dat $(srcdir)/regs.dat \ + $(RUNPERL) $(srcdir)/tokhash.pl h $(srcdir)/insns.dat $(srcdir)/regs.dat \ $(srcdir)/tokens.dat > tokens.h # Preprocessor token hash pptok.h: pptok.dat pptok.pl perllib/phash.ph - $(PERL) $(srcdir)/pptok.pl h $(srcdir)/pptok.dat pptok.h + $(RUNPERL) $(srcdir)/pptok.pl h $(srcdir)/pptok.dat pptok.h pptok.c: pptok.dat pptok.pl perllib/phash.ph - $(PERL) $(srcdir)/pptok.pl c $(srcdir)/pptok.dat pptok.c + $(RUNPERL) $(srcdir)/pptok.pl c $(srcdir)/pptok.dat pptok.c pptok.ph: pptok.dat pptok.pl perllib/phash.ph - $(PERL) $(srcdir)/pptok.pl ph $(srcdir)/pptok.dat pptok.ph + $(RUNPERL) $(srcdir)/pptok.pl ph $(srcdir)/pptok.dat pptok.ph # Directives hash directiv.h: directiv.dat directiv.pl perllib/phash.ph - $(PERL) $(srcdir)/directiv.pl h $(srcdir)/directiv.dat directiv.h + $(RUNPERL) $(srcdir)/directiv.pl h $(srcdir)/directiv.dat directiv.h directiv.c: directiv.dat directiv.pl perllib/phash.ph - $(PERL) $(srcdir)/directiv.pl c $(srcdir)/directiv.dat directiv.c + $(RUNPERL) $(srcdir)/directiv.pl c $(srcdir)/directiv.dat directiv.c # This target generates all files that require perl. # This allows easier generation of distribution (see dist target). @@ -284,18 +288,18 @@ splint: splint -weak *.c test: nasm$(X) - cd test && $(PERL) performtest.pl --nasm=../nasm *.asm + cd test && $(RUNPERL) performtest.pl --nasm=../nasm *.asm golden: nasm$(X) - cd test && $(PERL) performtest.pl --golden --nasm=../nasm *.asm + cd test && $(RUNPERL) performtest.pl --golden --nasm=../nasm *.asm # # This build dependencies in *ALL* makefiles. Partially for that reason, # it's expected to be invoked manually. # alldeps: perlreq - $(PERL) syncfiles.pl Makefile.in Mkfiles/*.mak - $(PERL) mkdep.pl -M Makefile.in Mkfiles/*.mak -- \ + $(RUNPERL) syncfiles.pl Makefile.in Mkfiles/*.mak + $(RUNPERL) mkdep.pl -M Makefile.in Mkfiles/*.mak -- \ . output lib ./config.status @@ -14,25 +14,32 @@ AC_DEFUN(PA_ADD_CFLAGS, CFLAGS="$pa_add_cflags__old_cflags")]) dnl -------------------------------------------------------------------------- -dnl PA_WORKING_STDBOOL +dnl PA_HAVE_FUNC dnl -dnl See if we have a working <stdbool.h> and bool support; in particular, -dnl OpenWatcom 1.8 has a broken _Bool type that we don't want to use. +dnl Look for a function with the specified arguments which could be +dnl a builtin/intrinsic function. dnl -------------------------------------------------------------------------- -AC_DEFUN(PA_WORKING_BOOL, -[AC_MSG_CHECKING([if $CC has a working bool type]) - AC_COMPILE_IFELSE([AC_LANG_SOURCE([ -#ifndef __cplusplus -#include <stdbool.h> -#endif -int foo(bool x, int y) -{ - return x+y; -} - ])], - [AC_MSG_RESULT([yes]) - AC_DEFINE(HAVE_WORKING_BOOL, 1, - [Define to 1 if your compiler has a correct implementation of bool])], - [AC_MSG_RESULT([no])]) -]) +AC_DEFUN(PA_HAVE_FUNC, +[AC_MSG_CHECKING([for $1]) +AC_TRY_LINK([], [(void)$1$2;], +AC_MSG_RESULT([yes]) +AC_DEFINE(m4_toupper([HAVE_$1]), [1], + [Define to 1 if you have the `$1' intrinsic function.]), +AC_MSG_RESULT([no]))]) +dnl -------------------------------------------------------------------------- +dnl PA_REPLACE_FUNC +dnl +dnl Look for a function and possible alternatives, unlike AC_REPLACE_FUNCS +dnl this will only add *one* replacement to LIBOBJS if no alternative is +dnl found. +dnl -------------------------------------------------------------------------- +AC_DEFUN(PA_REPLACE_FUNC_WITH, +[pa_replace_func__$2_missing=true +AC_CHECK_FUNCS([$1], [pa_replace_func__$2_missing=false], []) +if $pa_replace_func__$2_missing; then + AC_LIBOBJ([$2]) +fi]) + +AC_DEFUN(PA_REPLACE_FUNC, +[PA_REPLACE_FUNC_WITH([$1], m4_car(m4_unquote(m4_split(m4_normalize[$1]))))]) @@ -70,15 +70,6 @@ #define __STDC_FORMAT_MACROS 1 #ifdef __GNUC__ -# if __GNUC__ >= 4 -# define HAVE_GNUC_4 -# endif -# if __GNUC__ >= 3 -# define HAVE_GNUC_3 -# endif -#endif - -#ifdef __GNUC__ # define _unused __attribute__((unused)) #else # define _unused @@ -110,8 +101,12 @@ size_t strlcpy(char *, const char *, size_t); #endif #ifndef __cplusplus /* C++ has false, true, bool as keywords */ -# if defined(HAVE_STDBOOL_H) && defined(HAVE_WORKING_BOOL) +# ifdef HAVE_STDBOOL_H # include <stdbool.h> +# elif defined(HAVE__BOOL) +# typedef _Bool bool +# define false 0 +# define true 1 # else /* This is sort of dangerous, since casts will behave different than casting to the standard boolean type. Always use !!, not (bool). */ diff --git a/configure.in b/configure.in index 023bd240..42eee15c 100644 --- a/configure.in +++ b/configure.in @@ -1,6 +1,6 @@ -dnl Process this file with autoconf 2.61 or later to produce +dnl Process this file with autoconf 2.63 or later to produce dnl a configure script. -AC_PREREQ(2.61) +AC_PREREQ(2.63) AC_INIT(config.h.in) AC_CONFIG_HEADERS(config.h) @@ -48,8 +48,9 @@ AC_PREFIX_PROGRAM(nasm) dnl Checks for programs. dnl Consider AC_USE_SYSTEM_EXTENSIONS if autoconf 2.61 is OK in the future -AC_USE_SYSTEM_EXTENSIONS AC_PROG_CC +AC_PROG_CC_STDC +AC_USE_SYSTEM_EXTENSIONS AC_PROG_LN_S AC_PROG_MAKE_SET if test -f nasm.c; then @@ -65,7 +66,6 @@ AC_C_CONST AC_C_INLINE AC_C_RESTRICT AC_TYPE_SIZE_T -PA_WORKING_BOOL AC_C_BIGENDIAN(AC_DEFINE(WORDS_BIGENDIAN),AC_DEFINE(WORDS_LITTLEENDIAN)) AH_TEMPLATE(WORDS_BIGENDIAN, [Define to 1 if your processor stores words with the most significant @@ -74,11 +74,6 @@ AH_TEMPLATE(WORDS_LITTLEENDIAN, [Define to 1 if your processor stores words with the least significant byte first (like Intel and VAX, unlike Motorola and SPARC).]) -dnl If we have gcc, add appropriate options -PA_ADD_CFLAGS([-W]) -PA_ADD_CFLAGS([-Wall]) -PA_ADD_CFLAGS([-std=c99]) - dnl Look for programs... AC_CHECK_PROGS(NROFF, nroff, false) AC_CHECK_PROGS(ASCIIDOC, asciidoc, false) @@ -113,7 +108,7 @@ dnl The standard header for str*casecmp is <strings.h> AC_CHECK_HEADERS(strings.h) dnl Look for <stdbool.h> -AC_CHECK_HEADERS(stdbool.h) +AC_HEADER_STDBOOL dnl Look for <unistd.h> AC_CHECK_HEADERS(unistd.h) @@ -122,30 +117,14 @@ dnl Look for <sys/param.h> AC_CHECK_HEADERS(sys/param.h) dnl Checks for library functions. -AC_SUBST(XOBJS) - AC_CHECK_FUNCS(strcspn, , AC_MSG_ERROR([NASM requires ANSI C (specifically, "strcspn")])) AC_CHECK_FUNCS(strspn, , AC_MSG_ERROR([NASM requires ANSI C (specifically, "strspn")])) -missing=true -AC_CHECK_FUNCS([vsnprintf _vsnprintf], missing=false) -if $missing; then - XOBJS="$XOBJS lib/vsnprintf.o" -fi - -missing=true -AC_CHECK_FUNCS([snprintf _snprintf], missing=false) -if $missing; then - XOBJS="$XOBJS lib/snprintf.o" -fi - AC_CHECK_FUNCS(strcasecmp stricmp) AC_CHECK_FUNCS(strncasecmp strnicmp) -AC_CHECK_FUNCS(strsep) -AC_CHECK_FUNCS(strlcpy) AC_CHECK_FUNCS(getuid) AC_CHECK_FUNCS(getgid) @@ -155,6 +134,18 @@ AC_CHECK_FUNCS(canonicalize_file_name) AC_CHECK_FUNCS(_fullpath) AC_CHECK_FUNCS(pathconf) +PA_HAVE_FUNC(__builtin_ctz, (0U)) +PA_HAVE_FUNC(__builtin_ctzl, (0UL)) +PA_HAVE_FUNC(__builtin_ctzll, (0ULL)) + +dnl Functions for which we have replacements available in lib/ +AC_CONFIG_LIBOBJ_DIR([lib]) +AC_SUBST([LIBOBJDIR], [lib/]) +PA_REPLACE_FUNC([vsnprintf _vsnprintf]) +PA_REPLACE_FUNC([snprintf _snprintf]) +PA_REPLACE_FUNC([strlcpy]) +PA_REPLACE_FUNC([strsep]) + dnl Check for functions that might not be declared in the headers for dnl various idiotic reasons (mostly because of library authors dnl abusing the meaning of __STRICT_ANSI__) @@ -181,6 +172,9 @@ AC_ARG_WITH([ccache], [CC="ccache $CC"], []) +dnl If we have gcc, add appropriate options +PA_ADD_CFLAGS([-W]) +PA_ADD_CFLAGS([-Wall]) PA_ADD_CFLAGS([-pedantic]) PA_ADD_CFLAGS([-Werror=implicit]) PA_ADD_CFLAGS([-Werror=missing-braces]) @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 1996-2010 The NASM Authors - All Rights Reserved + * Copyright 1996-2016 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. * @@ -42,6 +42,7 @@ } \ } while (0) + #if defined(__GNUC__) && defined(__x86_64__) int ilog2_32(uint32_t v) @@ -67,7 +68,7 @@ int ilog2_32(uint32_t v) return n; } -#elif defined(HAVE_GNUC_4) +#elif defined(HAVE___BUILTIN_CTZ) && INT_MAX >= 2147483647 int ilog2_32(uint32_t v) { @@ -106,7 +107,7 @@ int ilog2_64(uint64_t v) return n; } -#elif defined(HAVE_GNUC_4) +#elif defined(HAVE__BUILTIN_CTZLL) && LLONG_MAX >= 9223372036854775807L int ilog2_64(uint64_t v) { diff --git a/lib/strlcpy.c b/lib/strlcpy.c index 4335359c..22d9ccfb 100644 --- a/lib/strlcpy.c +++ b/lib/strlcpy.c @@ -14,8 +14,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <sys/types.h> -#include <string.h> #include "compiler.h" /* |