aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@linux.intel.com>2016-10-04 17:01:59 -0700
committerH. Peter Anvin <hpa@linux.intel.com>2016-10-04 17:01:59 -0700
commit397c169736925214b495d841f00a9ccd9b329e66 (patch)
tree90ade77e8153dc2cb35666f710c66c0158066e81
parent9255b5136992c2c1dee2fd11b9d2a389b377162d (diff)
downloadnasm-397c169736925214b495d841f00a9ccd9b329e66.tar.gz
nasm-397c169736925214b495d841f00a9ccd9b329e66.tar.xz
nasm-397c169736925214b495d841f00a9ccd9b329e66.zip
Move config.h to a subdirectory, add MSVC-specific config file
Instead of trying to do hacks in the Makefiles, define header files for specific compilers if they can't use autoconf. Currently defined for Microsoft Visual Studio, based on MSDN documentation. It is currently untested. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
-rw-r--r--.gitignore4
-rw-r--r--Mkfiles/msvc.mak8
-rwxr-xr-xautogen.sh3
-rw-r--r--config/msvc.h189
-rw-r--r--configure.ac13
-rw-r--r--include/compiler.h26
-rw-r--r--nasmlib/file.c28
7 files changed, 244 insertions, 27 deletions
diff --git a/.gitignore b/.gitignore
index d9ac37be..a4d8ae27 100644
--- a/.gitignore
+++ b/.gitignore
@@ -34,8 +34,8 @@ TAGS
/asm/pptok.ph
/asm/tokens.h
/asm/tokhash.c
-/config.h
-/config.h.in
+/config/config.h
+/config/config.h.in
/config.log
/config.status
/configure
diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak
index 9e58a5ff..4b20b445 100644
--- a/Mkfiles/msvc.mak
+++ b/Mkfiles/msvc.mak
@@ -29,9 +29,13 @@ CC = cl
LD = link
AR = lib
CFLAGS = $(CFLAGS) /W2
-BUILD_CFLAGS = $(CFLAGS) /I$(srcdir)/inttypes
+BUILD_CFLAGS = $(CFLAGS)
INTERNAL_CFLAGS = /I$(srcdir) /I. \
- /DHAVE__SNPRINTF /DHAVE__VSNPRINTF /DHAVE__FULLPATH
+ /I$(srcdir)/include /I./include \
+ /I$(srcdir)/x86 /I./x86 \
+ /I$(srcdir)/asm /I./asm \
+ /I$(srcdir)/disasm /I./disasm \
+ /I$(srcdir)/output /I./output \
ALL_CFLAGS = $(BUILD_CFLAGS) $(INTERNAL_CFLAGS)
LDFLAGS = $(LDFLAGS) /SUBSYSTEM:CONSOLE /RELEASE
LIBS =
diff --git a/autogen.sh b/autogen.sh
index 1a8d21b5..d38e0ef7 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -5,4 +5,5 @@
autoheader
autoconf
rm -rf autom4te.cache config.log config.status
-rm -f Makefile rdoff/Makefile doc/Makefile config.h
+rm -f Makefile rdoff/Makefile doc/Makefile
+rm -f config.h.in config.h config/config.h
diff --git a/config/msvc.h b/config/msvc.h
new file mode 100644
index 00000000..b72cdceb
--- /dev/null
+++ b/config/msvc.h
@@ -0,0 +1,189 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2016 The NASM Authors - All Rights Reserved
+ * See the file AUTHORS included with the NASM distribution for
+ * the specific copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * config/msvc.h
+ *
+ * Compiler definitions for Microsoft Visual C++;
+ * instead of config.h.in. See config.h.in for the
+ * variables which can be defined here.
+ *
+ * MSDN seems to have information back to Visual Studio 2003, so aim
+ * for compatibility that far back.
+ *
+ * Relevant _MSC_VER values:
+ * 1310 - Visual Studio 2003
+ * 1400 - Visual Studio 2005
+ * 1500 - Visual Studio 2008
+ * 1600 - Visual Studio 2010
+ * 1700 - Visual Studio 2012
+ * 1800 - Visual Studio 2013
+ * 1900 - Visual Studio 2015
+ */
+
+#ifndef NASM_CONFIG_MSVC_H
+#define NASM_CONFIG_MSVC_H
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#define HAVE_FCNTL_H 1
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#if _MSC_VER >= 1900
+# define HAVE_INTTYPES_H 1
+#endif
+
+/* Define to 1 if you have the <io.h> header file. */
+#define HAVE_IO_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <types.h> header file. */
+#define HAVE_TYPES_H 1
+
+/* Define to 1 if you have the `access' function. */
+#define HAVE_ACCESS 1
+#if _MSC_VER < 1400
+# define access _access
+#endif
+
+/* Define to 1 if you have the `fileno' function. */
+#define HAVE_FILENO 1
+#if _MSC_VER < 1400
+# define fileno _fileno
+#endif
+
+/* Define to 1 if you have the `snprintf' function. */
+#define HAVE_SNPRINTF 1
+#if _MSC_VER < 1900
+# define snprintf _snprinf
+#endif
+
+/* Define to 1 if you have the `_chsize' function. */
+#define HAVE__CHSIZE 1
+
+/* Define to 1 if you have the `_chsize_s' function. */
+#if _MSC_VER >= 1400
+# define HAVE__CHSIZE_S 1
+#endif
+
+/* Define to 1 if you have the `_filelengthi64' function. */
+#define HAVE__FILELENGTHI64 1
+
+/* Define to 1 if you have the `_fseeki64' function. */
+#define HAVE__FSEEKI64 1
+
+/* Define to 1 if you have the `_fullpath' function. */
+#define HAVE__FULLPATH 1
+
+/* Define to 1 if you have the `stat' function. */
+#define HAVE_STAT 1
+#define stat _stati64
+
+/* Define to 1 if stdbool.h conforms to C99. */
+#if _MSC_VER >= 1900
+# define HAVE_STDBOOL_H 1
+#endif
+
+/* Define to 1 if you have the `stricmp' function. */
+#define HAVE_STRICMP 1
+/* Define to 1 if you have the declaration of `stricmp', and to 0 if you
+ don't. */
+#define HAVE_DECL_STRICMP 1
+#if _MSC_VER < 1400
+# define stricmp _stricmp
+#endif
+
+/* Define to 1 if you have the `strnicmp' function. */
+#define HAVE_STRNICMP 1
+/* Define to 1 if you have the declaration of `strnicmp', and to 0 if you
+ don't. */
+#define HAVE_DECL_STRNICMP 1
+#if _MSC_VER < 1400
+# define strnicmp _strnicmp
+#endif
+
+#if _MSC_VER >= 1400
+/* Define to 1 if you have the `strnlen' function. */
+# define HAVE_STRNLEN 1
+/* Define to 1 if you have the declaration of `strnlen', and to 0 if you
+ don't. */
+# define HAVE_DECL_STRNLEN 1
+#endif
+
+/* Define to 1 if the system has the type `uintptr_t'. */
+#if _MSC_VER >= 1900
+# define HAVE_UINTPTR_T 1
+#else
+/* Define to the type of an unsigned integer type wide enough to hold a
+ pointer, if such a type exists, and if the system does not define it. */
+# define uintptr_t size_t
+#endif
+
+/* Define to 1 if you have the `vsnprintf' function. */
+#define HAVE_VSNPRINTF 1
+#if _MSC_VER < 1400
+# define vsnprint _vsnprintf
+#endif
+
+/* Define to 1 if the system has the type `_Bool'. */
+#if _MSC_VER >= 1900
+# define HAVE__BOOL 1
+#endif
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Define to 1 if your processor stores words with the least significant byte
+ first (like Intel and VAX, unlike Motorola and SPARC). */
+#define WORDS_LITTLEENDIAN 1
+
+/* Define to `__inline__' or `__inline' if that's what the C compiler
+ calls it, or to nothing if 'inline' is not supported under any name. */
+#define inline __inline
+
+/* Define to the equivalent of the C99 'restrict' keyword, or to
+ nothing if this is not supported. Do not define if restrict is
+ supported directly. */
+#define restrict __restrict
+
+#endif /* NASM_CONFIG_MSVC_H */
diff --git a/configure.ac b/configure.ac
index febe1b26..537efe9c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,8 +1,8 @@
dnl Process this file with autoconf 2.63 or later to produce
dnl a configure script.
AC_PREREQ(2.63)
-AC_INIT(config.h.in)
-AC_CONFIG_HEADERS(config.h)
+AC_INIT(config/config.h.in)
+AC_CONFIG_HEADERS(config/config.h)
dnl Check for broken VPATH handling on older NetBSD makes.
AC_DEFUN(AC_PROG_MAKE_VPATHOK,
@@ -137,15 +137,16 @@ AC_CHECK_FUNCS(pathconf)
AC_FUNC_FSEEKO
AC_CHECK_FUNCS([_fseeki64])
AC_CHECK_FUNCS([ftruncate _chsize _chsize_s])
-AC_CHECK_FUNCS([fileno])
+AC_CHECK_FUNCS([fileno _fileno])
-AC_CHECK_FUNCS(stat)
+AC_CHECK_FUNCS(_filelengthi64)
+AC_CHECK_FUNCS([stat _stati64])
AC_CHECK_FUNCS(fstat)
AC_CHECK_FUNCS(mmap)
AC_CHECK_FUNCS(getpagesize)
AC_CHECK_FUNCS(sysconf)
-AC_CHECK_FUNCS([access faccessat])
+AC_CHECK_FUNCS([access _access faccessat])
PA_HAVE_FUNC(__builtin_ctz, (0U))
PA_HAVE_FUNC(__builtin_ctzl, (0UL))
@@ -216,5 +217,5 @@ PA_ADD_CFLAGS([-Werror=missing-declarations])
PA_ADD_CFLAGS([-Werror=comment])
PA_ADD_CFLAGS([-Werror=vla])])
-AC_OUTPUT_COMMANDS([mkdir -p nasmlib nsis output stdlib x86 asm disasm])
+AC_OUTPUT_COMMANDS([mkdir -p config nasmlib nsis output stdlib x86 asm disasm])
AC_OUTPUT(Makefile rdoff/Makefile doc/Makefile)
diff --git a/include/compiler.h b/include/compiler.h
index 6230f227..c5f4ac9e 100644
--- a/include/compiler.h
+++ b/include/compiler.h
@@ -55,18 +55,14 @@
#define _MBCS 1
#ifdef HAVE_CONFIG_H
-# include "config.h"
+# include "config/config.h"
/* autoconf doesn't define these if they are redundant, but we want to
be able to #ifdef them... */
+#elif defined(_MSC_VER) && (_MSC_VER >= 1310)
+# include "config/msvc.h"
#else
-/* Default these to unsupported unless we have config.h */
-# ifndef inline
-# define inline
-# endif
-# ifndef restrict
-# define restrict
-# endif
-#endif /* HAVE_CONFIG_H */
+/* Add more compiler-specific header files here */
+#endif /* Configuration file */
/* This is required to get the standard <inttypes.h> macros when compiling
with a C++ compiler. This must be defined *before* <inttypes.h> is
@@ -102,7 +98,7 @@ int vsnprintf(char *, size_t, const char *, va_list);
# endif
#endif
-#if !defined(HAVE_STRLCPY) || !HAVE_DECL_STRLCPY
+#if !defined(HAVE_STRLCPY) || !defined(HAVE_DECL_STRLCPY)
size_t strlcpy(char *, const char *, size_t);
#endif
@@ -134,23 +130,23 @@ typedef enum bool { false, true } bool;
#endif
/* Some misguided platforms hide the defs for these */
-#if defined(HAVE_STRCASECMP) && !HAVE_DECL_STRCASECMP
+#if defined(HAVE_STRCASECMP) && !defined(HAVE_DECL_STRCASECMP)
int strcasecmp(const char *, const char *);
#endif
-#if defined(HAVE_STRICMP) && !HAVE_DECL_STRICMP
+#if defined(HAVE_STRICMP) && !defined(HAVE_DECL_STRICMP)
int stricmp(const char *, const char *);
#endif
-#if defined(HAVE_STRNCASECMP) && !HAVE_DECL_STRNCASECMP
+#if defined(HAVE_STRNCASECMP) && !defined(HAVE_DECL_STRNCASECMP)
int strncasecmp(const char *, const char *, size_t);
#endif
-#if defined(HAVE_STRNICMP) && !HAVE_DECL_STRNICMP
+#if defined(HAVE_STRNICMP) && !defined(HAVE_DECL_STRNICMP)
int strnicmp(const char *, const char *, size_t);
#endif
-#if defined(HAVE_STRSEP) && !HAVE_DECL_STRSEP
+#if defined(HAVE_STRSEP) && !defined(HAVE_DECL_STRSEP)
char *strsep(char **, const char *);
#endif
diff --git a/nasmlib/file.c b/nasmlib/file.c
index d7f5f225..57cbc9cd 100644
--- a/nasmlib/file.c
+++ b/nasmlib/file.c
@@ -36,6 +36,12 @@
#include <errno.h>
+#ifdef HAVE_TYPES_H
+# include <types.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
#ifdef HAVE_FCNTL_H
# include <fcntl.h>
#endif
@@ -52,6 +58,19 @@
# include <sys/mman.h>
#endif
+#if !defined(HAVE_FILENO) && defined(HAVE__FILENO)
+# define HAVE_FILENO 1
+# define fileno _fileno
+#endif
+
+#if !defined(HAVE_ACCESS) && defined(HAVE__ACCESS)
+# define HAVE_ACCESS 1
+# define access _access
+#endif
+#ifndef R_OK
+# define R_OK 4 /* Classic Unix constant, same on Windows */
+#endif
+
/* Can we adjust the file size without actually writing all the bytes? */
#ifdef HAVE_FILENO /* Useless without fileno() */
# ifdef HAVE__CHSIZE_S
@@ -63,6 +82,11 @@
# endif
#endif
+#ifdef HAVE__STATI64
+# define HAVE_STAT 1
+# define stat _stati64
+#endif
+
void nasm_write(const void *ptr, size_t size, FILE *f)
{
size_t n = fwrite(ptr, 1, size, f);
@@ -216,7 +240,9 @@ bool nasm_file_exists(const char *filename)
*/
off_t nasm_file_size(FILE *f)
{
-#if defined(HAVE_FILENO) && defined(HAVE_FSTAT)
+#if defined(HAVE_FILENO) && defined(HAVE__FILELENGTHI64)
+ return _filelengthi64(fileno(f));
+#elif defined(HAVE_FILENO) && defined(HAVE_FSTAT)
struct stat st;
if (fstat(fileno(f), &st))