Initial add. Ways to go.
This commit is contained in:
parent
bfee0cebb2
commit
60e6014f3c
|
@ -0,0 +1,241 @@
|
|||
#-----------------------------------------------------------------------------#
|
||||
# PhysicsFS -- A filesystem abstraction.
|
||||
#
|
||||
# Please see the file LICENSE in the source's root directory.
|
||||
# This file written by Ryan C. Gordon.
|
||||
#-----------------------------------------------------------------------------#
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------#
|
||||
# Makefile for building PhysicsFS on Unix-like systems. Follow the
|
||||
# instructions for editing this file, then run "make" on the command line.
|
||||
#-----------------------------------------------------------------------------#
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------#
|
||||
# Set to your liking.
|
||||
#-----------------------------------------------------------------------------#
|
||||
CC = gcc
|
||||
LINKER = gcc
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------#
|
||||
# If this makefile fails to detect Cygwin correctly, or you want to force
|
||||
# the build process's behaviour, set it to "true" or "false" (w/o quotes).
|
||||
#-----------------------------------------------------------------------------#
|
||||
#cygwin := true
|
||||
#cygwin := false
|
||||
cygwin := autodetect
|
||||
|
||||
#-----------------------------------------------------------------------------#
|
||||
# Set this to true if you want to create a debug build.
|
||||
#-----------------------------------------------------------------------------#
|
||||
#debugging := false
|
||||
debugging := true
|
||||
|
||||
#-----------------------------------------------------------------------------#
|
||||
# Set the archive types you'd like to support.
|
||||
# Note that various archives may need external libraries.
|
||||
#-----------------------------------------------------------------------------#
|
||||
use_archive_zip := false
|
||||
|
||||
#-----------------------------------------------------------------------------#
|
||||
# Set to "true" if you'd like to build a DLL. Set to "false" otherwise.
|
||||
#-----------------------------------------------------------------------------#
|
||||
#build_dll := false
|
||||
build_dll := true
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------#
|
||||
# Set one of the below. Currently, none of these are used.
|
||||
#-----------------------------------------------------------------------------#
|
||||
#use_asm = -DUSE_I386_ASM
|
||||
use_asm = -DUSE_PORTABLE_C
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------#
|
||||
#-----------------------------------------------------------------------------#
|
||||
#-----------------------------------------------------------------------------#
|
||||
#-----------------------------------------------------------------------------#
|
||||
# Everything below this line is probably okay.
|
||||
#-----------------------------------------------------------------------------#
|
||||
#-----------------------------------------------------------------------------#
|
||||
#-----------------------------------------------------------------------------#
|
||||
#-----------------------------------------------------------------------------#
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------#
|
||||
# CygWin autodetect.
|
||||
#-----------------------------------------------------------------------------#
|
||||
|
||||
ifeq ($(strip $(cygwin)),autodetect)
|
||||
ifneq ($(strip $(shell gcc -v 2>&1 |grep "cygwin")),)
|
||||
cygwin := true
|
||||
else
|
||||
cygwin := false
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------#
|
||||
# Platform-specific binary stuff.
|
||||
#-----------------------------------------------------------------------------#
|
||||
|
||||
ifeq ($(strip $(cygwin)),true)
|
||||
# !!! FIXME
|
||||
build_dll := false
|
||||
# !!! FIXME
|
||||
|
||||
ASM = nasmw
|
||||
EXE_EXT = .exe
|
||||
DLL_EXT = .dll
|
||||
STATICLIB_EXT = .a
|
||||
ASMOBJFMT = win32
|
||||
ASMDEFS = -dC_IDENTIFIERS_UNDERSCORED
|
||||
CFLAGS += -DC_IDENTIFIERS_UNDERSCORED
|
||||
else
|
||||
ASM = nasm
|
||||
EXE_EXT =
|
||||
DLL_EXT = .so
|
||||
STATICLIB_EXT = .a
|
||||
ASMOBJFMT = elf
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(build_dll)),true)
|
||||
LIB_EXT := $(DLL_EXT)
|
||||
LDFLAGS += -shared
|
||||
else
|
||||
LIB_EXT := $(STATICLIB_EXT)
|
||||
endif
|
||||
|
||||
#-----------------------------------------------------------------------------#
|
||||
# General compiler, assembler, and linker flags.
|
||||
#-----------------------------------------------------------------------------#
|
||||
|
||||
BINDIR := bin
|
||||
SRCDIR := .
|
||||
|
||||
CFLAGS += $(use_asm) -I$(SRCDIR) -D_REENTRANT -fsigned-char -DPLATFORM_UNIX
|
||||
CFLAGS += -Wall -Werror -fno-exceptions -fno-rtti -ansi -pendantic
|
||||
|
||||
LDFLAGS += -lm
|
||||
|
||||
ifeq ($(strip $(debugging)),true)
|
||||
CFLAGS += -DDEBUG -g -fno-omit-frame-pointer
|
||||
LDFLAGS += -g -fno-omit-frame-pointer
|
||||
else
|
||||
CFLAGS += -DNDEBUG -O2 -fomit-frame-pointer
|
||||
LDFLAGS += -O2 -fomit-frame-pointer
|
||||
endif
|
||||
|
||||
ASMFLAGS := -f $(ASMOBJFMT) $(ASMDEFS)
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------#
|
||||
# Source and target names.
|
||||
#-----------------------------------------------------------------------------#
|
||||
|
||||
BASELIBNAME := physfs
|
||||
MAINLIB := $(BINDIR)/$(strip $(BASELIBNAME))$(strip $(LIB_EXT))
|
||||
|
||||
MAINSRCS := physfs.c unix.c dir.c
|
||||
|
||||
ifeq ($(strip $(use_archive_zip)),true)
|
||||
MAINSRCS += zip.c
|
||||
CFLAGS += -DPHYSFS_SUPPORTS_ZIP
|
||||
endif
|
||||
|
||||
# Rule for getting list of objects from source
|
||||
MAINOBJS1 := $(MAINSRCS:.c=.o)
|
||||
MAINOBJS2 := $(MAINOBJS1:.cpp=.o)
|
||||
MAINOBJS3 := $(MAINOBJS2:.asm=.o)
|
||||
|
||||
MAINOBJS := $(foreach f,$(MAINOBJS3),$(BINDIR)/$(f))
|
||||
MAINSRCS := $(foreach f,$(MAINSRCS),$(SRCDIR)/$(f))
|
||||
|
||||
CLEANUP = $(wildcard *.exe) $(wildcard *.obj) \
|
||||
$(wildcard $(BINDIR)/*.exe) $(wildcard $(BINDIR)/*.obj) \
|
||||
$(wildcard *~) $(wildcard *.err) \
|
||||
$(wildcard .\#*) core
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------#
|
||||
# Rules.
|
||||
#-----------------------------------------------------------------------------#
|
||||
|
||||
# Rules for turning source files into .o files
|
||||
$(BINDIR)/%.o: $(SRCDIR)/%.cpp
|
||||
$(CC) -c -o $@ $< $(CFLAGS)
|
||||
|
||||
$(BINDIR)/%.o: $(SRCDIR)/%.c
|
||||
$(CC) -c -o $@ $< $(CFLAGS)
|
||||
|
||||
$(BINDIR)/%.o: $(SRCDIR)/%.asm
|
||||
$(ASM) $(ASMFLAGS) -o $@ $<
|
||||
|
||||
.PHONY: all clean listobjs
|
||||
|
||||
all: $(BINDIR) $(MAINLIB)
|
||||
|
||||
$(MAINLIB) : $(BINDIR) $(MAINOBJS)
|
||||
$(LINKER) -o $(MAINLIB) $(LDFLAGS) $(MAINOBJS)
|
||||
|
||||
$(BINDIR):
|
||||
mkdir -p $(BINDIR)
|
||||
|
||||
clean:
|
||||
rm -f $(CLEANUP)
|
||||
rm -rf $(BINDIR)
|
||||
|
||||
listobjs:
|
||||
@echo SOURCES:
|
||||
@echo $(MAINSRCS)
|
||||
@echo
|
||||
@echo OBJECTS:
|
||||
@echo $(MAINOBJS)
|
||||
@echo
|
||||
@echo BINARIES:
|
||||
@echo $(MAINLIB)
|
||||
|
||||
showcfg:
|
||||
@echo "Using CygWin : $(cygwin)"
|
||||
@echo "Debugging : $(debugging)"
|
||||
@echo "ASM flag : $(use_asm)"
|
||||
@echo "Building DLLs : $(build_dll)"
|
||||
@echo "Supports .ZIP : $(use_archive_zip)"
|
||||
|
||||
#-----------------------------------------------------------------------------#
|
||||
# This section is pretty much just for Ryan's use to make distributions.
|
||||
# You Probably Should Not Touch.
|
||||
#-----------------------------------------------------------------------------#
|
||||
|
||||
# These are the files needed in a binary distribution, regardless of what
|
||||
# platform is being used.
|
||||
BINSCOMMON := LICENSE.TXT physfs.h
|
||||
|
||||
.PHONY: package msbins win32bins nocygwin
|
||||
package: clean
|
||||
cd .. ; zip -9rz ./physfs-src-$(shell date +%m%d%Y).zip physfs -x "*CVS*" < physfs/FILEID.DIZ
|
||||
|
||||
|
||||
ifeq ($(strip $(cygwin)),true)
|
||||
msbins: win32bins
|
||||
|
||||
win32bins: clean all
|
||||
echo -e "\r\n\r\n\r\nHEY YOU.\r\n\r\n\r\nTake a look at README-win32bins.txt FIRST.\r\n\r\n\r\n--ryan. (icculus@linuxgames.com)\r\n\r\n" |zip -9rz ../physfs-win32bins-$(shell date +%m%d%Y).zip $(MAINLIB) $(EXTRAPACKAGELIBS) README-win32bins.txt
|
||||
|
||||
else
|
||||
|
||||
msbins: nocygwin
|
||||
win32bins: nocygwin
|
||||
|
||||
nocygwin:
|
||||
@echo This must be done on a Windows box in the Cygwin environment.
|
||||
|
||||
endif
|
||||
|
||||
#-----------------------------------------------------------------------------#
|
||||
# That's all, folks.
|
||||
#-----------------------------------------------------------------------------#
|
||||
|
||||
# end of Makefile ...
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Standard directory I/O support routines for PhysicsFS.
|
||||
*
|
||||
* Please see the file LICENSE in the source's root directory.
|
||||
*
|
||||
* This file written by Ryan C. Gordon.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define __PHYSICSFS_INTERNAL__
|
||||
#include "physfs_internal.h"
|
||||
|
||||
/* template for filehandles. */
|
||||
const FileHandle __PHYSFS_FileHandle_DIR =
|
||||
{
|
||||
NULL, /* opaque */
|
||||
NULL, /* dirReader */
|
||||
DIR_read, /* read() method */
|
||||
NULL, /* write() method */
|
||||
DIR_eof, /* eof() method */
|
||||
DIR_tell, /* tell() method */
|
||||
DIR_seek, /* seek() method */
|
||||
DIR_close, /* close() method */
|
||||
};
|
||||
|
||||
/* template for directories. */
|
||||
const DirReader __PHYSFS_DirReader_DIR =
|
||||
{
|
||||
NULL, /* opaque */
|
||||
DIR_enumerate, /* enumerateFiles() method */
|
||||
DIR_isDirectory, /* isDirectory() method */
|
||||
DIR_isSymLink, /* isSymLink() method */
|
||||
DIR_isOpenable, /* isOpenable() method */
|
||||
DIR_openRead, /* openRead() method */
|
||||
DIR_dirClose, /* close() method */
|
||||
};
|
||||
|
||||
|
||||
/* This doesn't get listed, since it's technically not an archive... */
|
||||
#if 0
|
||||
const __PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_DIR =
|
||||
{
|
||||
"DIR",
|
||||
"non-archive directory I/O"
|
||||
};
|
||||
#endif
|
||||
|
||||
/* end of dir.c ... */
|
||||
|
|
@ -0,0 +1,204 @@
|
|||
/*
|
||||
* Internal function/structure declaration. Do NOT include in your
|
||||
* application.
|
||||
*
|
||||
* Please see the file LICENSE in the source's root directory.
|
||||
*
|
||||
* This file written by Ryan C. Gordon.
|
||||
*/
|
||||
|
||||
#ifndef _INCLUDE_PHYSFS_INTERNAL_H_
|
||||
#define _INCLUDE_PHYSFS_INTERNAL_H_
|
||||
|
||||
#ifndef __PHYSICSFS_INTERNAL__
|
||||
#error Do not include this header from your applications.
|
||||
#endif
|
||||
|
||||
struct __PHYSFS_DIRREADER__;
|
||||
|
||||
typedef struct __PHYSFS_FILEHANDLE__
|
||||
{
|
||||
/*
|
||||
* This is reserved for the driver to store information.
|
||||
*/
|
||||
void *opaque;
|
||||
|
||||
/*
|
||||
* This should be the DirReader that created this FileHandle.
|
||||
*/
|
||||
struct __PHYSFS_DIRREADER__ *dirReader;
|
||||
|
||||
/*
|
||||
* Read more from the file.
|
||||
*/
|
||||
int (*read)(struct __PHYSFS_FILEHANDLE__ *handle, void *buffer,
|
||||
unsigned int objSize, unsigned int objCount);
|
||||
|
||||
/*
|
||||
* Write more to the file. Archives don't have to implement this.
|
||||
* (Set it to NULL if not implemented).
|
||||
*/
|
||||
int (*write)(struct __PHYSFS_FILEHANDLE__ *handle, void *buffer,
|
||||
unsigned int objSize, unsigned int objCount);
|
||||
|
||||
/*
|
||||
* Returns non-zero if at end of file.
|
||||
*/
|
||||
int (*eof)(struct __PHYSFS_FILEHANDLE__ *handle);
|
||||
|
||||
/*
|
||||
* Returns byte offset from start of file.
|
||||
*/
|
||||
int (*tell)(struct __PHYSFS_FILEHANDLE__ *handle);
|
||||
|
||||
/*
|
||||
* Move read/write pointer to byte offset from start of file.
|
||||
* Returns non-zero on success, zero on error.
|
||||
*/
|
||||
int (*seek)(struct __PHYSFS_FILEHANDLE__ *handle, int offset);
|
||||
|
||||
/*
|
||||
* Close the file, and free this structure (including "opaque").
|
||||
*/
|
||||
int (*close)(void);
|
||||
} FileHandle;
|
||||
|
||||
|
||||
typedef struct __PHYSFS_DIRREADER__
|
||||
{
|
||||
/*
|
||||
* This is reserved for the driver to store information.
|
||||
*/
|
||||
void *opaque;
|
||||
|
||||
/*
|
||||
* Returns a list (freeable via PHYSFS_freeList()) of
|
||||
* all files in dirname.
|
||||
* Symlinks should be followed.
|
||||
*/
|
||||
char **(*enumerateFiles)(struct __PHYSFS_DIRREADER__ *r, const char *dirname);
|
||||
|
||||
/*
|
||||
* Returns non-zero if filename is really a directory.
|
||||
* Symlinks should be followed.
|
||||
*/
|
||||
int (*isDirectory)(struct __PHYSFS_DIRREADER__ *r, const char *name);
|
||||
|
||||
/*
|
||||
* Returns non-zero if filename is really a symlink.
|
||||
*/
|
||||
int (*isSymLink)(struct __PHYSFS_DIRREADER__ *r, const char *name);
|
||||
|
||||
/*
|
||||
* Returns non-zero if filename can be opened for reading.
|
||||
* Symlinks should be followed.
|
||||
*/
|
||||
int (*isOpenable)(struct __PHYSFS_DIRREADER__ *r, const char *name);
|
||||
|
||||
/*
|
||||
* Open file for reading, and return a FileHandle.
|
||||
* Symlinks should be followed.
|
||||
*/
|
||||
FileHandle *(*openRead)(struct __PHYSFS_DIRREADER__ *r, const char *filename);
|
||||
|
||||
/*
|
||||
* Close directories/archives, and free this structure, including
|
||||
* the "opaque" entry. This should assume that it won't be called if
|
||||
* there are still files open from this DirReader.
|
||||
*/
|
||||
void (*close)(struct __PHYSFS_DIRREADER__ *r);
|
||||
} DirReader;
|
||||
|
||||
|
||||
/* error messages... */
|
||||
#define ERR_IS_INITIALIZED "Already initialized"
|
||||
#define ERR_NOT_INITIALIZED "Not initialized"
|
||||
#define ERR_INVALID_ARGUMENT "Invalid argument"
|
||||
#define ERR_FILES_OPEN_WRITE "Files still open for writing"
|
||||
#define ERR_NO_DIR_CREATE "Failed to create directories"
|
||||
#define ERR_OUT_OF_MEMORY "Out of memory"
|
||||
#define ERR_NOT_IN_SEARCH_PATH "No such entry in search path"
|
||||
#define ERR_NOT_SUPPORTED "Operation not supported"
|
||||
|
||||
|
||||
/*
|
||||
* Call this to set the message returned by PHYSFS_getLastError().
|
||||
* Please only use the ERR_* constants above, or add new constants to the
|
||||
* above group, but I want these all in one place.
|
||||
*/
|
||||
void __PHYSFS_setError(const char *err);
|
||||
|
||||
|
||||
/* This gets used all over for lessening code clutter. */
|
||||
#define BAIL_IF_MACRO(c, e, r) if (c) { __PHYSFS_setError(e); return(r); }
|
||||
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/*------------ ----------------*/
|
||||
/*------------ You MUST implement the following functions ----------------*/
|
||||
/*------------ if porting to a new platform. ----------------*/
|
||||
/*------------ (see unix.c for an example) ----------------*/
|
||||
/*------------ ----------------*/
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*
|
||||
* The dir separator; "/" on unix, "\\" on win32, ":" on MacOS, etc...
|
||||
* Obviously, this isn't a function, but it IS a null-terminated string.
|
||||
*/
|
||||
extern const char *__PHYSFS_PlatformDirSeparator;
|
||||
|
||||
/*
|
||||
* Platform implementation of PHYSFS_getCdRomDirs()...
|
||||
* See physfs.h. The retval should be freeable via PHYSFS_freeList().
|
||||
*/
|
||||
char **__PHYSFS_platformDetectAvailableCDs(void);
|
||||
|
||||
/*
|
||||
* Calculate the base dir, if your platform needs special consideration.
|
||||
* Just return NULL if the standard routines will suffice. (see
|
||||
* calculateBaseDir() in physfs.c ...)
|
||||
* Caller will free() the retval if it's not NULL.
|
||||
*/
|
||||
char *__PHYSFS_platformCalcBaseDir(char *argv0);
|
||||
|
||||
/*
|
||||
* Get the platform-specific user name.
|
||||
* Caller will free() the retval if it's not NULL. If it's NULL, the username
|
||||
* will default to "default".
|
||||
*/
|
||||
char *__PHYSFS_platformGetUserName(void);
|
||||
|
||||
/*
|
||||
* Get the platform-specific user dir.
|
||||
* Caller will free() the retval if it's not NULL. If it's NULL, the userdir
|
||||
* will default to basedir/username.
|
||||
*/
|
||||
char *__PHYSFS_platformGetUserDir(void);
|
||||
|
||||
/*
|
||||
* Return a number that uniquely identifies the current thread.
|
||||
* On a platform without threading, (1) will suffice. These numbers are
|
||||
* arbitrary; the only requirement is that no two threads have the same
|
||||
* number.
|
||||
*/
|
||||
int __PHYSFS_platformGetThreadID(void);
|
||||
|
||||
/*
|
||||
* This is a pass-through to whatever stricmp() is called on your platform.
|
||||
*/
|
||||
int __PHYSFS_platformStricmp(const char *str1, const char *str2);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* end of physfs_internal.h ... */
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* ZIP support routines for PhysicsFS.
|
||||
*
|
||||
* Please see the file LICENSE in the source's root directory.
|
||||
*
|
||||
* This file written by Ryan C. Gordon.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define __PHYSICSFS_INTERNAL__
|
||||
#include "physfs_internal.h"
|
||||
|
||||
/* template for filehandles. */
|
||||
const FileHandle __PHYSFS_FileHandle_ZIP =
|
||||
{
|
||||
NULL, /* opaque */
|
||||
NULL, /* dirReader */
|
||||
ZIP_read, /* read() method */
|
||||
NULL, /* write() method */
|
||||
ZIP_eof, /* eof() method */
|
||||
ZIP_tell, /* tell() method */
|
||||
ZIP_seek, /* seek() method */
|
||||
ZIP_close, /* close() method */
|
||||
};
|
||||
|
||||
/* template for directories. */
|
||||
const DirReader __PHYSFS_DirReader_ZIP =
|
||||
{
|
||||
NULL, /* opaque */
|
||||
ZIP_enumerate, /* enumerateFiles() method */
|
||||
ZIP_isDirectory, /* isDirectory() method */
|
||||
ZIP_isSymLink, /* isSymLink() method */
|
||||
ZIP_isOpenable, /* isOpenable() method */
|
||||
ZIP_openRead, /* openRead() method */
|
||||
ZIP_dirClose, /* close() method */
|
||||
};
|
||||
|
||||
const __PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_ZIP =
|
||||
{
|
||||
"ZIP",
|
||||
"PkZip/WinZip/Info-Zip compatible"
|
||||
};
|
||||
|
||||
/* end of zip.c ... */
|
||||
|
Loading…
Reference in New Issue