Makefile.gcc 4.9 KB
Newer Older
M
Mark Adler 已提交
1 2
# Makefile for zlib, derived from Makefile.dj2.
# Modified for mingw32 by C. Spieler, 6/16/98.
M
Mark Adler 已提交
3
# Updated for zlib 1.2.x by Christian Spieler and Cosmin Truta, Mar-2003.
4
# Last updated: Mar 2012.
M
Mark Adler 已提交
5 6
# Tested under Cygwin and MinGW.

M
Mark Adler 已提交
7 8
# Copyright (C) 1995-2003 Jean-loup Gailly.
# For conditions of distribution and use, see copyright notice in zlib.h
M
Mark Adler 已提交
9

10
# To compile, or to compile and test, type from the top level zlib directory:
M
Mark Adler 已提交
11
#
12
#   make -fwin32/Makefile.gcc;  make test testdll -fwin32/Makefile.gcc
M
Mark Adler 已提交
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
M
Mark Adler 已提交
17
#
M
Mark Adler 已提交
18
# To install libz.a, zconf.h and zlib.h in the system directories, type:
M
Mark Adler 已提交
19
#
20 21 22
#   make install -fwin32/Makefile.gcc
#
# BINARY_PATH, INCLUDE_PATH and LIBRARY_PATH must be set.
M
Mark Adler 已提交
23

M
Mark Adler 已提交
24 25 26 27 28 29
# 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
M
Mark Adler 已提交
30
IMPLIB    = libz.dll.a
M
Mark Adler 已提交
31

M
Mark Adler 已提交
32 33 34 35 36
#
# Set to 1 if shared object needs to be installed
#
SHARED_MODE=0

M
Mark Adler 已提交
37 38
#LOC = -DASMV
#LOC = -DDEBUG -g
M
Mark Adler 已提交
39

M
Mark Adler 已提交
40 41
PREFIX =
CC = $(PREFIX)gcc
M
Mark Adler 已提交
42
CFLAGS = $(LOC) -O3 -Wall
M
Mark Adler 已提交
43
EXTRA_CFLAGS = -DNO_VIZ
M
Mark Adler 已提交
44 45 46 47 48

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

LD = $(CC)
M
Mark Adler 已提交
49
LDFLAGS = $(LOC)
M
Mark Adler 已提交
50

M
Mark Adler 已提交
51
AR = $(PREFIX)ar
M
Mark Adler 已提交
52 53
ARFLAGS = rcs

M
Mark Adler 已提交
54
RC = $(PREFIX)windres
M
Mark Adler 已提交
55
RCFLAGS = --define GCC_WINDRES
M
Mark Adler 已提交
56

M
Mark Adler 已提交
57
STRIP = $(PREFIX)strip
M
Mark Adler 已提交
58

M
Mark Adler 已提交
59 60 61 62 63
CP = cp -fp
# If GNU install is available, replace $(CP) with install.
INSTALL = $(CP)
RM = rm -f

M
Mark Adler 已提交
64
prefix ?= /usr/local
M
Mark Adler 已提交
65 66
exec_prefix = $(prefix)

M
Mark Adler 已提交
67
OBJS = adler32.o compress.o crc32.o deflate.o gzclose.o gzlib.o gzread.o \
M
Mark Adler 已提交
68
       gzwrite.o infback.o inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o
M
Mark Adler 已提交
69 70
OBJA =

M
Mark Adler 已提交
71
all: $(STATICLIB) $(SHAREDLIB) $(IMPLIB) example.exe minigzip.exe example_d.exe minigzip_d.exe
M
Mark Adler 已提交
72

M
Mark Adler 已提交
73
test: example.exe minigzip.exe
M
Mark Adler 已提交
74
	./example
M
Mark Adler 已提交
75 76
	echo hello world | ./minigzip | ./minigzip -d

M
Mark Adler 已提交
77
testdll: example_d.exe minigzip_d.exe
M
Mark Adler 已提交
78 79
	./example_d
	echo hello world | ./minigzip_d | ./minigzip_d -d
M
Mark Adler 已提交
80 81

.c.o:
M
Mark Adler 已提交
82
	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
M
Mark Adler 已提交
83

M
Mark Adler 已提交
84 85 86 87 88 89 90 91 92
.S.o:
	$(AS) $(ASFLAGS) -c -o $@ $<

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

$(IMPLIB): $(SHAREDLIB)

$(SHAREDLIB): win32/zlib.def $(OBJS) $(OBJA) zlibrc.o
M
Mark Adler 已提交
93
	$(CC) -shared -Wl,--out-implib,$(IMPLIB) $(LDFLAGS) \
M
Mark Adler 已提交
94 95
	-o $@ win32/zlib.def $(OBJS) $(OBJA) zlibrc.o
	$(STRIP) $@
M
Mark Adler 已提交
96

M
Mark Adler 已提交
97
example.exe: example.o $(STATICLIB)
M
Mark Adler 已提交
98
	$(LD) $(LDFLAGS) -o $@ example.o $(STATICLIB)
M
Mark Adler 已提交
99
	$(STRIP) $@
M
Mark Adler 已提交
100

M
Mark Adler 已提交
101
minigzip.exe: minigzip.o $(STATICLIB)
M
Mark Adler 已提交
102
	$(LD) $(LDFLAGS) -o $@ minigzip.o $(STATICLIB)
M
Mark Adler 已提交
103
	$(STRIP) $@
M
Mark Adler 已提交
104

M
Mark Adler 已提交
105
example_d.exe: example.o $(IMPLIB)
M
Mark Adler 已提交
106
	$(LD) $(LDFLAGS) -o $@ example.o $(IMPLIB)
M
Mark Adler 已提交
107
	$(STRIP) $@
M
Mark Adler 已提交
108

M
Mark Adler 已提交
109
minigzip_d.exe: minigzip.o $(IMPLIB)
M
Mark Adler 已提交
110
	$(LD) $(LDFLAGS) -o $@ minigzip.o $(IMPLIB)
M
Mark Adler 已提交
111
	$(STRIP) $@
M
Mark Adler 已提交
112

113 114 115 116 117 118
example.o: test/example.c zlib.h zconf.h
	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -I. -c -o $@ test/example.c

minigzip.o: test/minigzip.c zlib.h zconf.h
	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -I. -c -o $@ test/minigzip.c

M
Mark Adler 已提交
119 120
zlibrc.o: win32/zlib1.rc
	$(RC) $(RCFLAGS) -o $@ win32/zlib1.rc
M
Mark Adler 已提交
121

M
Mark Adler 已提交
122
.PHONY: install uninstall clean
M
Mark Adler 已提交
123

M
Mark Adler 已提交
124
install: zlib.h zconf.h $(STATICLIB) $(IMPLIB)
125
	@if test -z "$(DESTDIR)$(INCLUDE_PATH)" -o -z "$(DESTDIR)$(LIBRARY_PATH)" -o -z "$(DESTDIR)$(BINARY_PATH)"; then \
126 127 128
		echo INCLUDE_PATH, LIBRARY_PATH, and BINARY_PATH must be specified; \
		exit 1; \
	fi
129 130
	-@mkdir -p '$(DESTDIR)$(INCLUDE_PATH)'
	-@mkdir -p '$(DESTDIR)$(LIBRARY_PATH)' '$(DESTDIR)$(LIBRARY_PATH)'/pkgconfig
M
Mark Adler 已提交
131
	-if [ "$(SHARED_MODE)" = "1" ]; then \
132 133 134
		mkdir -p '$(DESTDIR)$(BINARY_PATH)'; \
		$(INSTALL) $(SHAREDLIB) '$(DESTDIR)$(BINARY_PATH)'; \
		$(INSTALL) $(IMPLIB) '$(DESTDIR)$(LIBRARY_PATH)'; \
M
Mark Adler 已提交
135
	fi
136 137 138
	-$(INSTALL) zlib.h '$(DESTDIR)$(INCLUDE_PATH)'
	-$(INSTALL) zconf.h '$(DESTDIR)$(INCLUDE_PATH)'
	-$(INSTALL) $(STATICLIB) '$(DESTDIR)$(LIBRARY_PATH)'
M
Mark Adler 已提交
139 140 141 142 143 144 145
	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' \
146
		zlib.pc.in > '$(DESTDIR)$(LIBRARY_PATH)'/pkgconfig/zlib.pc
M
Mark Adler 已提交
147 148

uninstall:
M
Mark Adler 已提交
149
	-if [ "$(SHARED_MODE)" = "1" ]; then \
150 151
		$(RM) '$(DESTDIR)$(BINARY_PATH)'/$(SHAREDLIB); \
		$(RM) '$(DESTDIR)$(LIBRARY_PATH)'/$(IMPLIB); \
M
Mark Adler 已提交
152
	fi
153 154 155
	-$(RM) '$(DESTDIR)$(INCLUDE_PATH)'/zlib.h
	-$(RM) '$(DESTDIR)$(INCLUDE_PATH)'/zconf.h
	-$(RM) '$(DESTDIR)$(LIBRARY_PATH)'/$(STATICLIB)
M
Mark Adler 已提交
156 157

clean:
M
Mark Adler 已提交
158 159 160 161 162 163
	-$(RM) $(STATICLIB)
	-$(RM) $(SHAREDLIB)
	-$(RM) $(IMPLIB)
	-$(RM) *.o
	-$(RM) *.exe
	-$(RM) foo.gz
M
Mark Adler 已提交
164 165 166 167 168

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
M
Mark Adler 已提交
169 170 171 172
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
M
Mark Adler 已提交
173 174 175 176 177 178
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
M
Mark Adler 已提交
179
zutil.o: zutil.h zlib.h zconf.h