Makefile.gcc 5 KB
Newer Older
Tom Tromey committed
1 2 3
# Makefile for zlib, derived from Makefile.dj2.
# Modified for mingw32 by C. Spieler, 6/16/98.
# Updated for zlib 1.2.x by Christian Spieler and Cosmin Truta, Mar-2003.
4
# Last updated: Mar 2012.
Tom Tromey committed
5 6 7 8 9
# Tested under Cygwin and MinGW.

# Copyright (C) 1995-2003 Jean-loup Gailly.
# For conditions of distribution and use, see copyright notice in zlib.h

10
# To compile, or to compile and test, type from the top level zlib directory:
Tom Tromey committed
11
#
12
#   make -fwin32/Makefile.gcc;  make test testdll -fwin32/Makefile.gcc
Tom Tromey committed
13 14 15
#
# To use the asm code, type:
#   cp contrib/asm?86/match.S ./match.S
16
#   make LOC=-DASMV OBJA=match.o -fwin32/Makefile.gcc
Tom Tromey committed
17 18 19
#
# To install libz.a, zconf.h and zlib.h in the system directories, type:
#
20 21 22 23 24 25 26
#   make install -fwin32/Makefile.gcc
#
# BINARY_PATH, INCLUDE_PATH and LIBRARY_PATH must be set.
#
# To install the shared lib, append SHARED_MODE=1 to the make command :
#
#   make install -fwin32/Makefile.gcc SHARED_MODE=1
Tom Tromey committed
27 28 29 30 31 32 33

# Note:
# If the platform is *not* MinGW (e.g. it is Cygwin or UWIN),
# the DLL name should be changed from "zlib1.dll".

STATICLIB = libz.a
SHAREDLIB = zlib1.dll
34
IMPLIB    = libz.dll.a
Tom Tromey committed
35

36 37 38 39 40
#
# Set to 1 if shared object needs to be installed
#
SHARED_MODE=0

Tom Tromey committed
41
#LOC = -DASMV
42
#LOC = -DZLIB_DEBUG -g
Tom Tromey committed
43

44 45
PREFIX =
CC = $(PREFIX)gcc
Tom Tromey committed
46 47 48 49 50 51
CFLAGS = $(LOC) -O3 -Wall

AS = $(CC)
ASFLAGS = $(LOC) -Wall

LD = $(CC)
52
LDFLAGS = $(LOC)
Tom Tromey committed
53

54
AR = $(PREFIX)ar
Tom Tromey committed
55 56
ARFLAGS = rcs

57
RC = $(PREFIX)windres
Tom Tromey committed
58 59
RCFLAGS = --define GCC_WINDRES

60 61
STRIP = $(PREFIX)strip

Tom Tromey committed
62 63 64 65 66
CP = cp -fp
# If GNU install is available, replace $(CP) with install.
INSTALL = $(CP)
RM = rm -f

67
prefix ?= /usr/local
Tom Tromey committed
68 69
exec_prefix = $(prefix)

70 71
OBJS = adler32.o compress.o crc32.o deflate.o gzclose.o gzlib.o gzread.o \
       gzwrite.o infback.o inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o
Tom Tromey committed
72 73
OBJA =

74
all: $(STATICLIB) $(SHAREDLIB) $(IMPLIB) example.exe minigzip.exe example_d.exe minigzip_d.exe
Tom Tromey committed
75

76
test: example.exe minigzip.exe
Tom Tromey committed
77 78 79
	./example
	echo hello world | ./minigzip | ./minigzip -d

80
testdll: example_d.exe minigzip_d.exe
Tom Tromey committed
81 82 83 84
	./example_d
	echo hello world | ./minigzip_d | ./minigzip_d -d

.c.o:
85
	$(CC) $(CFLAGS) -c -o $@ $<
Tom Tromey committed
86 87 88 89 90 91 92 93 94 95

.S.o:
	$(AS) $(ASFLAGS) -c -o $@ $<

$(STATICLIB): $(OBJS) $(OBJA)
	$(AR) $(ARFLAGS) $@ $(OBJS) $(OBJA)

$(IMPLIB): $(SHAREDLIB)

$(SHAREDLIB): win32/zlib.def $(OBJS) $(OBJA) zlibrc.o
96 97 98
	$(CC) -shared -Wl,--out-implib,$(IMPLIB) $(LDFLAGS) \
	-o $@ win32/zlib.def $(OBJS) $(OBJA) zlibrc.o
	$(STRIP) $@
Tom Tromey committed
99

100
example.exe: example.o $(STATICLIB)
Tom Tromey committed
101
	$(LD) $(LDFLAGS) -o $@ example.o $(STATICLIB)
102
	$(STRIP) $@
Tom Tromey committed
103

104
minigzip.exe: minigzip.o $(STATICLIB)
Tom Tromey committed
105
	$(LD) $(LDFLAGS) -o $@ minigzip.o $(STATICLIB)
106
	$(STRIP) $@
Tom Tromey committed
107

108
example_d.exe: example.o $(IMPLIB)
Tom Tromey committed
109
	$(LD) $(LDFLAGS) -o $@ example.o $(IMPLIB)
110
	$(STRIP) $@
Tom Tromey committed
111

112
minigzip_d.exe: minigzip.o $(IMPLIB)
Tom Tromey committed
113
	$(LD) $(LDFLAGS) -o $@ minigzip.o $(IMPLIB)
114
	$(STRIP) $@
Tom Tromey committed
115

116 117
example.o: test/example.c zlib.h zconf.h
	$(CC) $(CFLAGS) -I. -c -o $@ test/example.c
Tom Tromey committed
118

119 120
minigzip.o: test/minigzip.c zlib.h zconf.h
	$(CC) $(CFLAGS) -I. -c -o $@ test/minigzip.c
Tom Tromey committed
121

122 123
zlibrc.o: win32/zlib1.rc
	$(RC) $(RCFLAGS) -o $@ win32/zlib1.rc
Tom Tromey committed
124 125 126

.PHONY: install uninstall clean

127
install: zlib.h zconf.h $(STATICLIB) $(IMPLIB)
128 129 130 131 132 133
	@if test -z "$(DESTDIR)$(INCLUDE_PATH)" -o -z "$(DESTDIR)$(LIBRARY_PATH)" -o -z "$(DESTDIR)$(BINARY_PATH)"; then \
		echo INCLUDE_PATH, LIBRARY_PATH, and BINARY_PATH must be specified; \
		exit 1; \
	fi
	-@mkdir -p '$(DESTDIR)$(INCLUDE_PATH)'
	-@mkdir -p '$(DESTDIR)$(LIBRARY_PATH)' '$(DESTDIR)$(LIBRARY_PATH)'/pkgconfig
134
	-if [ "$(SHARED_MODE)" = "1" ]; then \
135 136 137
		mkdir -p '$(DESTDIR)$(BINARY_PATH)'; \
		$(INSTALL) $(SHAREDLIB) '$(DESTDIR)$(BINARY_PATH)'; \
		$(INSTALL) $(IMPLIB) '$(DESTDIR)$(LIBRARY_PATH)'; \
138
	fi
139 140 141 142 143 144 145 146 147 148 149
	-$(INSTALL) zlib.h '$(DESTDIR)$(INCLUDE_PATH)'
	-$(INSTALL) zconf.h '$(DESTDIR)$(INCLUDE_PATH)'
	-$(INSTALL) $(STATICLIB) '$(DESTDIR)$(LIBRARY_PATH)'
	sed \
		-e 's|@prefix@|${prefix}|g' \
		-e 's|@exec_prefix@|${exec_prefix}|g' \
		-e 's|@libdir@|$(LIBRARY_PATH)|g' \
		-e 's|@sharedlibdir@|$(LIBRARY_PATH)|g' \
		-e 's|@includedir@|$(INCLUDE_PATH)|g' \
		-e 's|@VERSION@|'`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' zlib.h`'|g' \
		zlib.pc.in > '$(DESTDIR)$(LIBRARY_PATH)'/pkgconfig/zlib.pc
Tom Tromey committed
150 151

uninstall:
152
	-if [ "$(SHARED_MODE)" = "1" ]; then \
153 154
		$(RM) '$(DESTDIR)$(BINARY_PATH)'/$(SHAREDLIB); \
		$(RM) '$(DESTDIR)$(LIBRARY_PATH)'/$(IMPLIB); \
155
	fi
156 157 158
	-$(RM) '$(DESTDIR)$(INCLUDE_PATH)'/zlib.h
	-$(RM) '$(DESTDIR)$(INCLUDE_PATH)'/zconf.h
	-$(RM) '$(DESTDIR)$(LIBRARY_PATH)'/$(STATICLIB)
Tom Tromey committed
159 160 161 162 163 164 165 166 167 168 169 170 171

clean:
	-$(RM) $(STATICLIB)
	-$(RM) $(SHAREDLIB)
	-$(RM) $(IMPLIB)
	-$(RM) *.o
	-$(RM) *.exe
	-$(RM) foo.gz

adler32.o: zlib.h zconf.h
compress.o: zlib.h zconf.h
crc32.o: crc32.h zlib.h zconf.h
deflate.o: deflate.h zutil.h zlib.h zconf.h
172 173 174 175
gzclose.o: zlib.h zconf.h gzguts.h
gzlib.o: zlib.h zconf.h gzguts.h
gzread.o: zlib.h zconf.h gzguts.h
gzwrite.o: zlib.h zconf.h gzguts.h
Tom Tromey committed
176 177 178 179 180 181 182
inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
inftrees.o: zutil.h zlib.h zconf.h inftrees.h
trees.o: deflate.h zutil.h zlib.h zconf.h trees.h
uncompr.o: zlib.h zconf.h
zutil.o: zutil.h zlib.h zconf.h