Merge pull request #114 from lpsantil/djgpp

Djgpp
This commit is contained in:
Yann Collet 2015-05-28 03:04:17 +02:00
commit 7f3d82def8
5 changed files with 190 additions and 5 deletions

24
contrib/djgpp/LICENSE Normal file
View File

@ -0,0 +1,24 @@
Copyright (c) 2014, lpsantil
All rights reserved.
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 HOLDER 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.

130
contrib/djgpp/Makefile Normal file
View File

@ -0,0 +1,130 @@
# Copyright (c) 2015, Louis P. Santillan <lpsantil@gmail.com>
# All rights reserved.
# See LICENSE for licensing details.
DESTDIR ?= /opt/local
# Pulled the code below from lib/Makefile. Might be nicer to derive this somehow without sed
# Version numbers
VERSION ?= 129
RELEASE ?= r$(VERSION)
LIBVER_MAJOR=$(shell sed -n '/define LZ4_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < lib/lz4.h)
LIBVER_MINOR=$(shell sed -n '/define LZ4_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < lib/lz4.h)
LIBVER_PATCH=$(shell sed -n '/define LZ4_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < lib/lz4.h)
LIBVER=$(LIBVER_MAJOR).$(LIBVER_MINOR).$(LIBVER_PATCH)
######################################################################
CROSS ?= i586-pc-msdosdjgpp
CC = $(CROSS)-gcc
AR = $(CROSS)-ar
LD = $(CROSS)-gcc
CFLAGS ?= -O3 -std=gnu99 -Wall -Wextra -Wundef -Wshadow -Wcast-qual -Wcast-align -Wstrict-prototypes -pedantic -DLZ4_VERSION=\"$(RELEASE)\"
LDFLAGS ?= -s
SRC = programs/bench.c programs/lz4io.c programs/lz4cli.c
OBJ = $(SRC:.c=.o)
SDEPS = $(SRC:.c=.d)
IDIR = lib
EDIR = .
EXE = lz4.exe
LNK = lz4
LDIR = lib
LSRC = lib/lz4.c lib/lz4hc.c lib/lz4frame.c lib/xxhash.c
INC = $(LSRC:.c=.h)
LOBJ = $(LSRC:.c=.o)
LSDEPS = $(LSRC:.c=.d)
LIB = $(LDIR)/lib$(LNK).a
# Since LDFLAGS defaults to "-s", probably better to override unless
# you have a default you would like to maintain
ifeq ($(WITH_DEBUG), 1)
CFLAGS += -g
LDFLAGS += -g
endif
# Since LDFLAGS defaults to "-s", probably better to override unless
# you have a default you would like to maintain
ifeq ($(WITH_PROFILING), 1)
CFLAGS += -pg
LDFLAGS += -pg
endif
%.o: %.c $(INC) Makefile
$(CC) $(CFLAGS) -MMD -MP -I$(IDIR) -c $< -o $@
%.exe: %.o $(LIB) Makefile
$(LD) $< -L$(LDIR) -l$(LNK) $(LDFLAGS) $(LIBDEP) -o $@
######################################################################
######################## DO NOT MODIFY BELOW #########################
######################################################################
.PHONY: all install uninstall showconfig gstat gpush
all: $(LIB) $(EXE)
$(LIB): $(LOBJ)
$(AR) -rcs $@ $^
$(EXE): $(LOBJ) $(OBJ)
$(LD) $(LDFLAGS) $(LOBJ) $(OBJ) -o $(EDIR)/$@
clean:
rm -f $(OBJ) $(EXE) $(LOBJ) $(LIB) *.tmp $(SDEPS) $(LSDEPS) $(TSDEPS)
install: $(INC) $(LIB) $(EXE)
mkdir -p $(DESTDIR)/bin $(DESTDIR)/include $(DESTDIR)/lib
rm -f .footprint
echo $(DESTDIR)/bin/$(EXE) >> .footprint
cp -v $(EXE) $(DESTDIR)/bin/
@for T in $(LIB); \
do ( \
echo $(DESTDIR)/$$T >> .footprint; \
cp -v --parents $$T $(DESTDIR) \
); done
@for T in $(INC); \
do ( \
echo $(DESTDIR)/include/`basename -a $$T` >> .footprint; \
cp -v $$T $(DESTDIR)/include/ \
); done
uninstall: .footprint
@for T in $(shell cat .footprint); do rm -v $$T; done
-include $(SDEPS) $(LSDEPS)
showconfig:
@echo "PWD="$(PWD)
@echo "VERSION="$(VERSION)
@echo "RELEASE="$(RELEASE)
@echo "LIBVER_MAJOR="$(LIBVER_MAJOR)
@echo "LIBVER_MINOR="$(LIBVER_MINOR)
@echo "LIBVER_PATCH="$(LIBVER_PATCH)
@echo "LIBVER="$(LIBVER)
@echo "CROSS="$(CROSS)
@echo "CC="$(CC)
@echo "AR="$(AR)
@echo "LD="$(LD)
@echo "DESTDIR="$(DESTDIR)
@echo "CFLAGS="$(CFLAGS)
@echo "LDFLAGS="$(LDFLAGS)
@echo "SRC="$(SRC)
@echo "OBJ="$(OBJ)
@echo "IDIR="$(IDIR)
@echo "INC="$(INC)
@echo "EDIR="$(EDIR)
@echo "EXE="$(EXE)
@echo "LDIR="$(LDIR)
@echo "LSRC="$(LSRC)
@echo "LOBJ="$(LOBJ)
@echo "LNK="$(LNK)
@echo "LIB="$(LIB)
@echo "SDEPS="$(SDEPS)
@echo "LSDEPS="$(LSDEPS)
gstat:
git status
gpush:
git commit
git push

21
contrib/djgpp/README.MD Normal file
View File

@ -0,0 +1,21 @@
# lz4 for DOS/djgpp
This file details on how to compile lz4.exe, and liblz4.a for use on DOS/djgpp using
Andrew Wu's build-djgpp cross compilers ([GH][0], [Binaries][1]) on OSX, Linux.
## Setup
* Download a djgpp tarball [binaries][1] for your platform.
* Extract and install it (`tar jxvf djgpp-linux64-gcc492.tar.bz2`). Note the path. We'll assume `/home/user/djgpp`.
* Add the `bin` folder to your `PATH`. In bash, do `export PATH=/home/user/djgpp/bin:$PATH`.
* The `Makefile` in `contrib/djgpp/` sets up `CC`, `AR`, `LD` for you. So, `CC=i586-pc-msdosdjgpp-gcc`, `AR=i586-pc-msdosdjgpp-ar`, `LD=i586-pc-msdosdjgpp-gcc`.
## Building LZ4 for DOS
In the base dir of lz4 and with `contrib/djgpp/Makefile`, try:
Try:
* `make -f contrib/djgpp/Makefile`
* `make -f contrib/djgpp/Makefile liblz4.a`
* `make -f contrib/djgpp/Makefile lz4.exe`
* `make -f contrib/djgpp/Makefile DESTDIR=/home/user/dos install`, however it doesn't make much sense on a \*nix.
* You can also do `make -f contrib/djgpp/Makefile uninstall`
[0]: https://github.com/andrewwutw/build-djgpp
[1]: https://github.com/andrewwutw/build-djgpp/releases

View File

@ -67,6 +67,11 @@
*****************************/
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32)
# include <io.h> /* _isatty */
# if defined(__DJGPP__)
# include <unistd.h>
# define _isatty isatty
# define _fileno fileno
# endif
# ifdef __MINGW32__
int _fileno(FILE *stream); /* MINGW somehow forgets to include this prototype into <stdio.h> */
# endif

View File

@ -64,11 +64,16 @@
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32)
# include <fcntl.h> /* _O_BINARY */
# include <io.h> /* _setmode, _fileno, _get_osfhandle */
# define SET_BINARY_MODE(file) _setmode(_fileno(file), _O_BINARY)
# include <Windows.h> /* DeviceIoControl, HANDLE, FSCTL_SET_SPARSE */
# define SET_SPARSE_FILE_MODE(file) { DWORD dw; DeviceIoControl((HANDLE) _get_osfhandle(_fileno(file)), FSCTL_SET_SPARSE, 0, 0, 0, 0, &dw, 0); }
# if defined(_MSC_VER) && (_MSC_VER >= 1400) /* Avoid MSVC fseek()'s 2GiB barrier */
# define fseek _fseeki64
# if !defined(__DJGPP__)
# define SET_BINARY_MODE(file) _setmode(_fileno(file), _O_BINARY)
# include <Windows.h> /* DeviceIoControl, HANDLE, FSCTL_SET_SPARSE */
# define SET_SPARSE_FILE_MODE(file) { DWORD dw; DeviceIoControl((HANDLE) _get_osfhandle(_fileno(file)), FSCTL_SET_SPARSE, 0, 0, 0, 0, &dw, 0); }
# if defined(_MSC_VER) && (_MSC_VER >= 1400) /* Avoid MSVC fseek()'s 2GiB barrier */
# define fseek _fseeki64
# endif
# else
# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
# define SET_SPARSE_FILE_MODE(file)
# endif
#else
# define SET_BINARY_MODE(file)