• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# GNU Makefile for nghttp2 / MSVC.
3#
4# By G. Vanem <gvanem@yahoo.no> 2013
5# Updated 3/2015 by Remo Eichenberger @remoe
6# The MIT License apply.
7#
8
9#
10# Choose your weapons:
11#  Set 'USE_CYTHON=1' to build and install the 'nghttp2.pyd' Python extension.
12#
13THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))
14
15USE_CYTHON := 0
16#USE_CYTHON := 1
17
18_VERSION	:= $(shell grep AC_INIT ../configure.ac | cut -d'[' -f3 | sed -e 's/-DEV//g' -e 's/], //g')
19_VERSION   	:= $(subst ., ,$(_VERSION))
20VER_MAJOR  	:= $(word 1,$(_VERSION))
21VER_MINOR  	:= $(word 2,$(_VERSION))
22VER_MICRO   := $(word 3,$(_VERSION))
23VERSION     := $(VER_MAJOR).$(VER_MINOR).$(VER_MICRO)
24VERSION_NUM := (($(VER_MAJOR) << 16) + ($(VER_MINOR) << 8) + $(VER_MICRO))
25
26GENERATED   := 'Generated by $(realpath Makefile.MSVC)'
27
28OBJ_DIR := MSVC_obj
29#SUFFIX :=-vc90-mt-x86
30
31#
32# Where to copy nghttp2.dll + lib + headers to.
33# Note: 'make install' is not in default targets. Do it explicitly.
34#
35TARGET_DIR  ?= ../_VC_ROOT
36VC_ROOT     := $(abspath $(TARGET_DIR))
37INSTALL_BIN := $(VC_ROOT)/bin
38INSTALL_LIB := $(VC_ROOT)/lib
39INSTALL_HDR := $(VC_ROOT)/include
40DLL_R	:= $(OBJ_DIR)/nghttp2$(SUFFIX).dll
41DLL_D	:= $(OBJ_DIR)/nghttp2d$(SUFFIX).dll
42LIB_R	:= $(OBJ_DIR)/nghttp2-static.lib
43LIB_D	:= $(OBJ_DIR)/nghttp2d-static.lib
44IMP_R	:= $(OBJ_DIR)/nghttp2.lib
45IMP_D	:= $(OBJ_DIR)/nghttp2d.lib
46
47#
48# Build for DEBUG-model and RELEASE at the same time.
49#
50TARGETS := $(LIB_R) $(DLL_R) $(IMP_R) \
51          $(LIB_D) $(DLL_D) $(IMP_D)
52
53EXT_LIBS =
54
55NGHTTP2_PDB_R := $(OBJ_DIR)/nghttp2.pdb
56NGHTTP2_PDB_D := $(OBJ_DIR)/nghttp2d.pdb
57
58CC       = cl
59LD		 := link
60AR		 := lib
61#CC       := icl
62#LD		 := xilink
63#AR		 := xilib
64RC		 := rc
65CFLAGS   := -I./includes -Dssize_t=long
66
67CFLAGS_R := -nologo -MD  -W3 -Z7 -DBUILDING_NGHTTP2
68CFLAGS_D := -nologo -MDd -W3 -Z7 -DBUILDING_NGHTTP2 \
69           -Ot -D_DEBUG -GF -RTCs -RTCu # -RTCc -GS
70
71LDFLAGS := -nologo -MAP -debug -incremental:no -opt:ref,icf -MANIFEST # -verbose
72
73
74NGHTTP2_SRC := nghttp2_pq.c \
75  nghttp2_map.c \
76  nghttp2_queue.c \
77  nghttp2_frame.c \
78  nghttp2_buf.c \
79  nghttp2_stream.c \
80  nghttp2_outbound_item.c \
81  nghttp2_session.c \
82  nghttp2_submit.c \
83  nghttp2_helper.c \
84  nghttp2_npn.c \
85  nghttp2_hd.c \
86  nghttp2_hd_huffman.c \
87  nghttp2_hd_huffman_data.c \
88  nghttp2_version.c \
89  nghttp2_priority_spec.c \
90  nghttp2_option.c \
91  nghttp2_callbacks.c \
92  nghttp2_mem.c \
93  nghttp2_http.c \
94  nghttp2_rcbuf.c
95
96NGHTTP2_OBJ_R := $(addprefix $(OBJ_DIR)/r_, $(notdir $(NGHTTP2_SRC:.c=.obj)))
97NGHTTP2_OBJ_D := $(addprefix $(OBJ_DIR)/d_, $(notdir $(NGHTTP2_SRC:.c=.obj)))
98
99.PHONY: all intro test_ver install copy_headers_and_libs \
100	install_nghttp2_pyd_0 install_nghttp2_pyd_1 \
101	build_nghttp2_pyd_0 build_nghttp2_pyd_1 \
102	clean_nghttp2_pyd_0 clean_nghttp2_pyd_1
103
104
105all: intro includes/nghttp2/nghttp2ver.h $(OBJ_DIR) $(TARGETS) build_nghttp2_pyd_$(USE_CYTHON)
106	@echo 'Welcome to NgHTTP2 (release + debug).'
107	@echo 'Do a "make -f Makefile.MSVC install" at own risk!'
108
109intro:
110	@echo 'Building NgHTTP (MSVC) ver. "$(VERSION)".'
111
112test_ver:
113	@echo '$$(VERSION):   "$(VERSION)".'
114	@echo '$$(_VERSION):  "$(_VERSION)".'
115	@echo '$$(VER_MAJOR): "$(VER_MAJOR)".'
116	@echo '$$(VER_MINOR): "$(VER_MINOR)".'
117	@echo '$$(VER_MICRO): "$(VER_MICRO)".'
118
119$(OBJ_DIR):
120	- mkdir $(OBJ_DIR)
121
122install: includes/nghttp2/nghttp2.h includes/nghttp2/nghttp2ver.h \
123         $(TARGETS) \
124         copy_headers_and_libs install_nghttp2_pyd_$(USE_CYTHON)
125
126#
127# This MUST be done before using the 'install_nghttp2_pyd_1' rule.
128#
129copy_headers_and_libs:
130	- mkdir -p $(INSTALL_HDR)/nghttp2 $(INSTALL_BIN) $(INSTALL_LIB)
131	cp --update $(addprefix includes/nghttp2/, nghttp2.h nghttp2ver.h)     $(INSTALL_HDR)/nghttp2
132	cp --update $(DLL_R) $(DLL_D) $(NGHTTP2_PDB_R) $(NGHTTP2_PDB_D) $(INSTALL_BIN)
133	cp --update $(IMP_R) $(IMP_D) $(LIB_R) $(LIB_D) $(INSTALL_LIB)
134	@echo
135
136$(LIB_R): $(NGHTTP2_OBJ_R)
137	$(AR) -nologo -out:$@ $^
138	@echo
139
140$(LIB_D): $(NGHTTP2_OBJ_D)
141	$(AR) -nologo -out:$@ $^
142	@echo
143
144
145$(IMP_R): $(DLL_R)
146
147$(DLL_R): $(NGHTTP2_OBJ_R) $(OBJ_DIR)/r_nghttp2.res
148	$(LD) $(LDFLAGS) -dll -out:$@ -implib:$(IMP_R) $(NGHTTP2_OBJ_R) -PDB:$(NGHTTP2_PDB_R) $(OBJ_DIR)/r_nghttp2.res $(EXT_LIBS)
149	mt -nologo -manifest $@.manifest -outputresource:$@\;2
150	@echo
151
152$(IMP_D): $(DLL_D)
153
154$(DLL_D): $(NGHTTP2_OBJ_D) $(OBJ_DIR)/d_nghttp2.res
155	$(LD) $(LDFLAGS) -dll -out:$@ -implib:$(IMP_D) $(NGHTTP2_OBJ_D) -PDB:$(NGHTTP2_PDB_D) $(OBJ_DIR)/d_nghttp2.res $(EXT_LIBS)
156	mt -nologo -manifest $@.manifest -outputresource:$@\;2
157	@echo
158
159
160WIN_OBJDIR:=$(shell cygpath -w $(abspath $(OBJ_DIR)))
161WIN_OBJDIR:=$(subst \,/,$(WIN_OBJDIR))
162
163../python/setup.py: ../python/setup.py.in $(THIS_MAKEFILE)
164	cd ../python ; \
165	echo '# $(GENERATED). DO NOT EDIT.' > setup.py ; \
166	sed -e 's/@top_srcdir@/../'   \
167	    -e 's%@top_builddir@%$(WIN_OBJDIR)%' \
168	    -e 's/@PACKAGE_VERSION@/$(VERSION)/' setup.py.in >> setup.py ;
169
170build_nghttp2_pyd_0: ;
171
172build_nghttp2_pyd_1: $(addprefix ../python/, setup.py nghttp2.pyx)
173	cd ../python ; \
174	python setup.py build_ext -i -f bdist_wininst
175
176install_nghttp2_pyd_0: ;
177
178install_nghttp2_pyd_1: $(addprefix ../python/, setup.py nghttp2.pyx)
179	cd ../python ; \
180	pip install .
181
182clean_nghttp2_pyd_0: ;
183
184clean_nghttp2_pyd_1:
185	cd ../python ; \
186	rm -fR build dist
187
188$(OBJ_DIR)/r_%.obj: %.c $(THIS_MAKEFILE)
189	$(CC) $(CFLAGS_R) $(CFLAGS) -Fo$@ -c $<
190	@echo
191
192$(OBJ_DIR)/d_%.obj: %.c $(THIS_MAKEFILE)
193	$(CC) $(CFLAGS_D) $(CFLAGS) -Fo$@ -c $<
194	@echo
195
196$(OBJ_DIR)/r_nghttp2.res: $(OBJ_DIR)/nghttp2.rc $(THIS_MAKEFILE)
197	$(RC) -D_RELEASE -Fo $@ $<
198	@echo
199
200$(OBJ_DIR)/d_nghttp2.res: $(OBJ_DIR)/nghttp2.rc $(THIS_MAKEFILE)
201	$(RC) -D_DEBUG -Fo $@ $<
202	@echo
203
204includes/nghttp2/nghttp2ver.h: includes/nghttp2/nghttp2ver.h.in $(THIS_MAKEFILE)
205	sed < includes/nghttp2/nghttp2ver.h.in     \
206	     -e 's/@PACKAGE_VERSION@/$(VERSION)/g' \
207	     -e 's/@PACKAGE_VERSION_NUM@/$(VERSION_NUM)/g' > $@
208	touch --reference=includes/nghttp2/nghttp2ver.h.in $@
209
210
211define RES_FILE
212  #include <winver.h>
213
214  VS_VERSION_INFO VERSIONINFO
215    FILEVERSION    $(VER_MAJOR), $(VER_MINOR), $(VER_MICRO), 0
216    PRODUCTVERSION $(VER_MAJOR), $(VER_MINOR), $(VER_MICRO), 0
217    FILEFLAGSMASK  0x3fL
218    FILEOS         0x40004L
219    FILETYPE       0x2L
220    FILESUBTYPE    0x0L
221  #ifdef _DEBUG
222    #define        VER_STR  "$(VERSION).0 (MSVC debug)"
223    #define        DBG      "d"
224    FILEFLAGS      0x1L
225  #else
226    #define        VER_STR  "$(VERSION).0 (MSVC release)"
227    #define        DBG      ""
228    FILEFLAGS      0x0L
229  #endif
230  BEGIN
231    BLOCK "StringFileInfo"
232    BEGIN
233      BLOCK "040904b0"
234      BEGIN
235        VALUE "CompanyName",      "http://tatsuhiro-t.github.io/nghttp2/"
236        VALUE "FileDescription",  "nghttp2; HTTP/2 C library"
237        VALUE "FileVersion",      VER_STR
238        VALUE "InternalName",     "nghttp2" DBG
239        VALUE "LegalCopyright",   "The MIT License"
240        VALUE "LegalTrademarks",  ""
241        VALUE "OriginalFilename", "nghttp2" DBG ".dll"
242        VALUE "ProductName",      "NGHTTP2."
243        VALUE "ProductVersion",   VER_STR
244      END
245    END
246  BLOCK "VarFileInfo"
247  BEGIN
248    VALUE "Translation", 0x409, 1200
249  END
250  END
251endef
252
253export RES_FILE
254
255$(OBJ_DIR)/nghttp2.rc: Makefile.MSVC
256	@echo 'Generating $@...'
257	@echo ' /* $(GENERATED). DO NOT EDIT.' > $@
258	@echo '  */'                          >> $@
259	@echo "$$RES_FILE"                    >> $@
260
261clean:
262	rm -f $(OBJ_DIR)/* includes/nghttp2/nghttp2ver.h
263	@echo
264
265vclean realclean: clean clean_nghttp2_pyd_$(USE_CYTHON)
266	- rm -rf $(OBJ_DIR)
267	- rm -f .depend.MSVC
268
269#
270# Use gcc to generated the dependencies. No MSVC specific args please!
271#
272REPLACE_R = 's/\(.*\)\.o: /\n$$(OBJ_DIR)\/r_\1.obj: /'
273REPLACE_D = 's/\(.*\)\.o: /\n$$(OBJ_DIR)\/d_\1.obj: /'
274
275depend: includes/nghttp2/nghttp2ver.h
276	@echo '# $(GENERATED). DO NOT EDIT.' > .depend.MSVC
277	gcc -MM $(CFLAGS) $(NGHTTP2_SRC)    >> .depend.tmp
278	@echo '#'                           >> .depend.MSVC
279	@echo '# Release lib objects:'      >> .depend.MSVC
280	sed -e $(REPLACE_R) .depend.tmp     >> .depend.MSVC
281	@echo '#'                           >> .depend.MSVC
282	@echo '# Debug lib objects:'        >> .depend.MSVC
283	sed -e $(REPLACE_D) .depend.tmp     >> .depend.MSVC
284	rm -f .depend.tmp
285
286-include .depend.MSVC
287