expose WebPFree function for DLL builds

This allows managed code (e.g., C#) to free buffers returned by the API
instead of relying on free().
Based on suggestion from Steven (grokys at googlemail dot com).
Fixes issue #109.

Change-Id: I94826a77f6f4cb6e331c454f994c964e2e448cae
This commit is contained in:
James Zern 2012-02-21 13:44:39 -08:00
parent 4be52f4a65
commit 45feb55dec

View File

@ -82,6 +82,7 @@ STATICLIBBUILD = TRUE
!ELSE IF "$(CFG)" == "debug-static" !ELSE IF "$(CFG)" == "debug-static"
TARGET = $(LIB_NAME_DEBUG).lib TARGET = $(LIB_NAME_DEBUG).lib
CC = $(CCDEBUG) CC = $(CCDEBUG)
RTLIB = $(RTLIBD)
STATICLIBBUILD = TRUE STATICLIBBUILD = TRUE
!ELSE IF "$(CFG)" == "release-dynamic" !ELSE IF "$(CFG)" == "release-dynamic"
TARGETDLL = $(LIB_NAME).dll TARGETDLL = $(LIB_NAME).dll
@ -92,6 +93,7 @@ DLLBUILD = TRUE
TARGETDLL = $(LIB_NAME_DEBUG).dll TARGETDLL = $(LIB_NAME_DEBUG).dll
TARGET = $(IMPLIB_NAME_DEBUG).lib TARGET = $(IMPLIB_NAME_DEBUG).lib
CC = $(CCDEBUG) CC = $(CCDEBUG)
RTLIB = $(RTLIBD)
DLLBUILD = TRUE DLLBUILD = TRUE
!ENDIF !ENDIF
@ -100,9 +102,11 @@ CC = $(CC) $(RTLIB)
LNK = $(LNKLIB) /out:$(DIRLIB)\$(TARGET) LNK = $(LNKLIB) /out:$(DIRLIB)\$(TARGET)
CFGSET = TRUE CFGSET = TRUE
!ELSE IF "$(DLLBUILD)" == "TRUE" !ELSE IF "$(DLLBUILD)" == "TRUE"
DLLC = webp_dll.c
DLLINC = webp_dll.h DLLINC = webp_dll.h
CC = $(CC) /I$(DIROBJ) /FI$(DLLINC) $(RTLIB) /DWEBP_DLL CC = $(CC) /I$(DIROBJ) /FI$(DLLINC) $(RTLIB) /DWEBP_DLL
LNK = $(LNKDLL) /out:$(DIRBIN)\$(TARGETDLL) /implib:$(DIRLIB)\$(TARGET) LNK = $(LNKDLL) /out:$(DIRBIN)\$(TARGETDLL) /implib:$(DIRLIB)\$(TARGET)
X_OBJS = $(DIROBJ)\$(DLLC:.c=.obj)
CFGSET = TRUE CFGSET = TRUE
!ENDIF !ENDIF
@ -184,7 +188,7 @@ X_OBJS= \
$(DIROBJ)\utils\quant_levels.obj \ $(DIROBJ)\utils\quant_levels.obj \
$(DIROBJ)\utils\tcoder.obj \ $(DIROBJ)\utils\tcoder.obj \
$(DIROBJ)\utils\thread.obj \ $(DIROBJ)\utils\thread.obj \
$(RESOURCE) \ $(X_OBJS) \
EXAMPLES_OBJS = \ EXAMPLES_OBJS = \
$(DIROBJ)\examples\cwebp.obj \ $(DIROBJ)\examples\cwebp.obj \
@ -211,9 +215,12 @@ $(DIRLIB)\$(TARGET): $(X_OBJS)
$(X_OBJS): $(OUTPUT_DIRS) $(X_OBJS): $(OUTPUT_DIRS)
!IF "$(DLLBUILD)" == "TRUE" !IF "$(DLLBUILD)" == "TRUE"
$(X_OBJS): $(DIROBJ)\$(DLLINC) $(X_OBJS): $(DIROBJ)\$(DLLINC) $(DIROBJ)\$(DLLC)
{$(DIROBJ)}.c{$(DIROBJ)}.obj:
$(CC) $(CFLAGS) /Fo"$@" $<
clean:: clean::
@-erase /s $(DIROBJ)\$(DLLINC) 2> NUL @-erase /s $(DIROBJ)\$(DLLC) $(DIROBJ)\$(DLLINC) 2> NUL
!ENDIF !ENDIF
$(EXAMPLES_OBJS): $(DIRLIB)\$(TARGET) $(EXAMPLES_OBJS): $(DIRLIB)\$(TARGET)
@ -228,6 +235,16 @@ $(DIROBJ)\$(DLLINC):
@echo #define WEBP_EXTERN(type) __declspec(dllexport) type >> $@ @echo #define WEBP_EXTERN(type) __declspec(dllexport) type >> $@
@echo #endif /* WEBP_DLL_H_ */ >> $@ @echo #endif /* WEBP_DLL_H_ */ >> $@
# expose a WebPFree() function for use in managed code
$(DIROBJ)\$(DLLC): $(DIROBJ)\$(DLLINC)
@echo #include ^<stdlib.h^> > $@
@echo #include "webp_dll.h" >> $@
@echo // This function should be used in place of free() for memory >> $@
@echo // returned by the WebP API. >> $@
@echo WEBP_EXTERN(void) WebPFree(void* ptr) { >> $@
@echo free(ptr); >> $@
@echo } >> $@
.SUFFIXES: .c .obj .res .exe .SUFFIXES: .c .obj .res .exe
{examples}.c{$(DIROBJ)\examples}.obj: {examples}.c{$(DIROBJ)\examples}.obj:
$(CC) $(CFLAGS) /Fo"$@" $< $(CC) $(CFLAGS) /Fo"$@" $<