From fad8558eb5ecbd62e2032a48c537bfecfad3dfc4 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Thu, 13 Mar 2014 12:48:10 +0100 Subject: [PATCH] Merged OSX fixes from Siesh1oo with some modifications --- Makefile | 23 ++++- backends/ilang/ilang_backend.cc | 1 + frontends/verilog/verilog_frontend.cc | 1 + kernel/compatibility.cc | 135 ++++++++++++++++++++++++++ kernel/compatibility.h | 36 +++++++ kernel/log.cc | 1 + kernel/register.cc | 5 +- kernel/rtlil.cc | 1 + libs/svgviewer/.gitignore | 1 + passes/techmap/techmap.cc | 1 + 10 files changed, 198 insertions(+), 7 deletions(-) create mode 100644 kernel/compatibility.cc create mode 100644 kernel/compatibility.h diff --git a/Makefile b/Makefile index 73051e524..325f25a17 100644 --- a/Makefile +++ b/Makefile @@ -22,12 +22,23 @@ TARGETS = yosys yosys-config all: top-all -CXXFLAGS = -Wall -Wextra -ggdb -I"$(shell pwd)" -MD -D_YOSYS_ -fPIC -LDFLAGS = -rdynamic -LDLIBS = -lstdc++ -lreadline -lm -ldl -lrt +CXXFLAGS = -Wall -Wextra -ggdb -I"$(shell pwd)" -MD -D_YOSYS_ -fPIC -I${DESTDIR}/include +LDFLAGS = -L${DESTDIR}/lib +LDLIBS = -lstdc++ -lreadline -lm -ldl QMAKE = qmake-qt4 SED = sed +ifeq (Darwin,$(findstring Darwin,$(shell uname))) + # add macports include and library path to search directories, don't use '-rdynamic' and '-lrt': + CXXFLAGS += -I/opt/local/include + LDFLAGS += -L/opt/local/lib + QMAKE = qmake + SED = gsed +else + LDFLAGS += -rdynamic + LDLIBS += -lrt +endif + YOSYS_VER := 0.2.0+ GIT_REV := $(shell git rev-parse --short HEAD || echo UNKOWN) OBJS = kernel/version_$(GIT_REV).o @@ -86,15 +97,17 @@ LDLIBS += $(patsubst %,$(VERIFIC_DIR)/%/*-linux.a,$(VERIFIC_COMPONENTS)) endif OBJS += kernel/driver.o kernel/register.o kernel/rtlil.o kernel/log.o kernel/calc.o +OBJS += kernel/compatibility.o OBJS += libs/bigint/BigIntegerAlgorithms.o libs/bigint/BigInteger.o libs/bigint/BigIntegerUtils.o OBJS += libs/bigint/BigUnsigned.o libs/bigint/BigUnsignedInABase.o OBJS += libs/sha1/sha1.o OBJS += libs/subcircuit/subcircuit.o -OBJS += libs/ezsat/ezsat.o +OBJS += libs/ezsat/ezsat.o OBJS += libs/ezsat/ezminisat.o + OBJS += libs/minisat/Options.o OBJS += libs/minisat/SimpSolver.o OBJS += libs/minisat/Solver.o @@ -121,7 +134,7 @@ yosys-config: yosys-config.in yosys-svgviewer: libs/svgviewer/*.h libs/svgviewer/*.cpp cd libs/svgviewer && $(QMAKE) && make - cp libs/svgviewer/svgviewer yosys-svgviewer + cp `find libs/svgviewer -name svgviewer -type f` yosys-svgviewer abc/abc-$(ABCREV): ifneq ($(ABCREV),default) diff --git a/backends/ilang/ilang_backend.cc b/backends/ilang/ilang_backend.cc index c585d40c5..b3d96b28e 100644 --- a/backends/ilang/ilang_backend.cc +++ b/backends/ilang/ilang_backend.cc @@ -23,6 +23,7 @@ */ #include "ilang_backend.h" +#include "kernel/compatibility.h" #include "kernel/register.h" #include "kernel/log.h" #include diff --git a/frontends/verilog/verilog_frontend.cc b/frontends/verilog/verilog_frontend.cc index 13c2676db..8e9efa173 100644 --- a/frontends/verilog/verilog_frontend.cc +++ b/frontends/verilog/verilog_frontend.cc @@ -27,6 +27,7 @@ */ #include "verilog_frontend.h" +#include "kernel/compatibility.h" #include "kernel/register.h" #include "kernel/log.h" #include "libs/sha1/sha1.h" diff --git a/kernel/compatibility.cc b/kernel/compatibility.cc new file mode 100644 index 000000000..2ef023eb3 --- /dev/null +++ b/kernel/compatibility.cc @@ -0,0 +1,135 @@ +/* + * yosys -- Yosys Open SYnthesis Suite + * + * Copyright (C) 2012 Clifford Wolf + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + +/** + * POSIX.2008 fake implementation for pre-POSIX.2008 systems. (OSX, BSD, MINGW, CYGWIN, older Linux &c.) + */ + +#include +#include +#include +#include + +#if !(_XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L) + +typedef struct memstream { + off_t pos; + off_t size; + char * buffer; + char ** bufp; + size_t * sizep; + bool realloc; +} memstream_t; + +static int memstream_read (void * cookie, char * buf, int size) +{ + memstream_t * mem = (memstream_t *) cookie; + off_t available = mem->size - mem->pos; + if (available < 0) + available = 0; + if (size > available) + size = available; + memcpy(buf, mem->buffer + mem->pos, size); + mem->pos += size; + return size; +} + +static int memstream_write (void * cookie, const char * buf, int size) +{ + memstream_t * mem = (memstream_t *) cookie; + off_t available = mem->size - mem->pos; + if (size > available) { + if (mem->realloc) { + mem->buffer = (char *) realloc(mem->buffer, mem->pos + size + 1); + memset(mem->buffer + mem->size, 0, mem->pos + size + 1 - mem->size); + mem->size = mem->pos + size; + if (mem->bufp) + *(mem->bufp) = mem->buffer; + if (mem->sizep) + *(mem->sizep) = mem->size; + } else { + size = available; + } + } + memcpy(mem->buffer + mem->pos, buf, sizeof(char) * size); + mem->pos += size; + return size; +} + +static fpos_t memstream_seek (void * cookie, fpos_t offset, int whence) +{ + memstream_t * mem = (memstream_t *) cookie; + switch (whence) { + case SEEK_SET: + if (offset < 0) + goto error_inval; + mem->pos = offset; + return 0; + case SEEK_CUR: + if (mem->pos + offset < 0) + goto error_inval; + mem->pos += offset; + return 0; + case SEEK_END: + if (mem->size + offset < 0) + goto error_inval; + mem->pos = mem->size + offset; + break; + default: + goto error_inval; + } + return mem->pos; +error_inval: + errno = EINVAL; + return -1; +} + +static int memstream_close (void * cookie) +{ + memstream_t * mem = (memstream_t *) cookie; + if (mem->bufp) + *(mem->bufp) = mem->buffer; + if (mem->sizep) + *(mem->sizep) = mem->size; + free(cookie); + return 0; +} + +FILE * compat_fmemopen (void * buf, size_t size, const char * mode) +{ + memstream_t * mem = (memstream_t *) malloc(sizeof(memstream_t)); + memset(mem, 0, sizeof(memstream_t)); + mem->size = size; + mem->buffer = (char *) buf; + (void) mode; + return funopen(mem, memstream_read, memstream_write, memstream_seek, memstream_close); +} + +FILE * compat_open_memstream (char ** bufp, size_t * sizep) +{ + memstream_t * mem = (memstream_t *) malloc(sizeof(memstream_t)); + memset(mem, 0, sizeof(memstream_t)); + mem->bufp = bufp; + mem->sizep = sizep; + mem->realloc = true; + return funopen(mem, memstream_read, memstream_write, memstream_seek, memstream_close); +} + +#endif /* !(_XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L) */ + diff --git a/kernel/compatibility.h b/kernel/compatibility.h new file mode 100644 index 000000000..58e0b52e9 --- /dev/null +++ b/kernel/compatibility.h @@ -0,0 +1,36 @@ +/* + * yosys -- Yosys Open SYnthesis Suite + * + * Copyright (C) 2012 Clifford Wolf + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + +#ifndef COMPATIBILITY_H +#define COMPATIBILITY_H + +#if !(_XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L) +#include +#include + +#define open_memstream compat_open_memstream +#define fmemopen compat_fmemopen + +FILE * compat_open_memstream (char ** bufp, size_t * sizep); +FILE * compat_fmemopen (void * buf, size_t size, const char * mode); + +#endif /* !(_XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L) */ + +#endif /* COMPATIBILITY_H */ + diff --git a/kernel/log.cc b/kernel/log.cc index 779f93737..b2c92e4e1 100644 --- a/kernel/log.cc +++ b/kernel/log.cc @@ -18,6 +18,7 @@ */ #include "kernel/log.h" +#include "kernel/compatibility.h" #include "backends/ilang/ilang_backend.h" #include diff --git a/kernel/register.cc b/kernel/register.cc index ab5cba11b..511afaac0 100644 --- a/kernel/register.cc +++ b/kernel/register.cc @@ -17,8 +17,9 @@ * */ -#include "register.h" -#include "log.h" +#include "kernel/compatibility.h" +#include "kernel/register.h" +#include "kernel/log.h" #include #include #include diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index 21fcae2b5..7259845a0 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -17,6 +17,7 @@ * */ +#include "kernel/compatibility.h" #include "kernel/rtlil.h" #include "kernel/log.h" #include "frontends/verilog/verilog_frontend.h" diff --git a/libs/svgviewer/.gitignore b/libs/svgviewer/.gitignore index b92d91f8b..b46f84a66 100644 --- a/libs/svgviewer/.gitignore +++ b/libs/svgviewer/.gitignore @@ -3,3 +3,4 @@ moc_mainwindow.cpp moc_svgview.cpp qrc_svgviewer.cpp svgviewer +svgviewer.app diff --git a/passes/techmap/techmap.cc b/passes/techmap/techmap.cc index 0ca601e3b..69ffb9230 100644 --- a/passes/techmap/techmap.cc +++ b/passes/techmap/techmap.cc @@ -17,6 +17,7 @@ * */ +#include "kernel/compatibility.h" #include "kernel/register.h" #include "kernel/sigtools.h" #include "kernel/log.h" -- 2.30.2