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 nghttp2_ksl.c 96 97NGHTTP2_OBJ_R := $(addprefix $(OBJ_DIR)/r_, $(notdir $(NGHTTP2_SRC:.c=.obj))) 98NGHTTP2_OBJ_D := $(addprefix $(OBJ_DIR)/d_, $(notdir $(NGHTTP2_SRC:.c=.obj))) 99 100.PHONY: all intro test_ver install copy_headers_and_libs \ 101 install_nghttp2_pyd_0 install_nghttp2_pyd_1 \ 102 build_nghttp2_pyd_0 build_nghttp2_pyd_1 \ 103 clean_nghttp2_pyd_0 clean_nghttp2_pyd_1 104 105 106all: intro includes/nghttp2/nghttp2ver.h $(OBJ_DIR) $(TARGETS) build_nghttp2_pyd_$(USE_CYTHON) 107 @echo 'Welcome to NgHTTP2 (release + debug).' 108 @echo 'Do a "make -f Makefile.MSVC install" at own risk!' 109 110intro: 111 @echo 'Building NgHTTP (MSVC) ver. "$(VERSION)".' 112 113test_ver: 114 @echo '$$(VERSION): "$(VERSION)".' 115 @echo '$$(_VERSION): "$(_VERSION)".' 116 @echo '$$(VER_MAJOR): "$(VER_MAJOR)".' 117 @echo '$$(VER_MINOR): "$(VER_MINOR)".' 118 @echo '$$(VER_MICRO): "$(VER_MICRO)".' 119 120$(OBJ_DIR): 121 - mkdir $(OBJ_DIR) 122 123install: includes/nghttp2/nghttp2.h includes/nghttp2/nghttp2ver.h \ 124 $(TARGETS) \ 125 copy_headers_and_libs install_nghttp2_pyd_$(USE_CYTHON) 126 127# 128# This MUST be done before using the 'install_nghttp2_pyd_1' rule. 129# 130copy_headers_and_libs: 131 - mkdir -p $(INSTALL_HDR)/nghttp2 $(INSTALL_BIN) $(INSTALL_LIB) 132 cp --update $(addprefix includes/nghttp2/, nghttp2.h nghttp2ver.h) $(INSTALL_HDR)/nghttp2 133 cp --update $(DLL_R) $(DLL_D) $(NGHTTP2_PDB_R) $(NGHTTP2_PDB_D) $(INSTALL_BIN) 134 cp --update $(IMP_R) $(IMP_D) $(LIB_R) $(LIB_D) $(INSTALL_LIB) 135 @echo 136 137$(LIB_R): $(NGHTTP2_OBJ_R) 138 $(AR) -nologo -out:$@ $^ 139 @echo 140 141$(LIB_D): $(NGHTTP2_OBJ_D) 142 $(AR) -nologo -out:$@ $^ 143 @echo 144 145 146$(IMP_R): $(DLL_R) 147 148$(DLL_R): $(NGHTTP2_OBJ_R) $(OBJ_DIR)/r_nghttp2.res 149 $(LD) $(LDFLAGS) -dll -out:$@ -implib:$(IMP_R) $(NGHTTP2_OBJ_R) -PDB:$(NGHTTP2_PDB_R) $(OBJ_DIR)/r_nghttp2.res $(EXT_LIBS) 150 mt -nologo -manifest $@.manifest -outputresource:$@\;2 151 @echo 152 153$(IMP_D): $(DLL_D) 154 155$(DLL_D): $(NGHTTP2_OBJ_D) $(OBJ_DIR)/d_nghttp2.res 156 $(LD) $(LDFLAGS) -dll -out:$@ -implib:$(IMP_D) $(NGHTTP2_OBJ_D) -PDB:$(NGHTTP2_PDB_D) $(OBJ_DIR)/d_nghttp2.res $(EXT_LIBS) 157 mt -nologo -manifest $@.manifest -outputresource:$@\;2 158 @echo 159 160 161WIN_OBJDIR:=$(shell cygpath -w $(abspath $(OBJ_DIR))) 162WIN_OBJDIR:=$(subst \,/,$(WIN_OBJDIR)) 163 164../python/setup.py: ../python/setup.py.in $(THIS_MAKEFILE) 165 cd ../python ; \ 166 echo '# $(GENERATED). DO NOT EDIT.' > setup.py ; \ 167 sed -e 's/@top_srcdir@/../' \ 168 -e 's%@top_builddir@%$(WIN_OBJDIR)%' \ 169 -e 's/@PACKAGE_VERSION@/$(VERSION)/' setup.py.in >> setup.py ; 170 171build_nghttp2_pyd_0: ; 172 173build_nghttp2_pyd_1: $(addprefix ../python/, setup.py nghttp2.pyx) 174 cd ../python ; \ 175 python setup.py build_ext -i -f bdist_wininst 176 177install_nghttp2_pyd_0: ; 178 179install_nghttp2_pyd_1: $(addprefix ../python/, setup.py nghttp2.pyx) 180 cd ../python ; \ 181 pip install . 182 183clean_nghttp2_pyd_0: ; 184 185clean_nghttp2_pyd_1: 186 cd ../python ; \ 187 rm -fR build dist 188 189$(OBJ_DIR)/r_%.obj: %.c $(THIS_MAKEFILE) 190 $(CC) $(CFLAGS_R) $(CFLAGS) -Fo$@ -c $< 191 @echo 192 193$(OBJ_DIR)/d_%.obj: %.c $(THIS_MAKEFILE) 194 $(CC) $(CFLAGS_D) $(CFLAGS) -Fo$@ -c $< 195 @echo 196 197$(OBJ_DIR)/r_nghttp2.res: $(OBJ_DIR)/nghttp2.rc $(THIS_MAKEFILE) 198 $(RC) -D_RELEASE -Fo $@ $< 199 @echo 200 201$(OBJ_DIR)/d_nghttp2.res: $(OBJ_DIR)/nghttp2.rc $(THIS_MAKEFILE) 202 $(RC) -D_DEBUG -Fo $@ $< 203 @echo 204 205includes/nghttp2/nghttp2ver.h: includes/nghttp2/nghttp2ver.h.in $(THIS_MAKEFILE) 206 sed < includes/nghttp2/nghttp2ver.h.in \ 207 -e 's/@PACKAGE_VERSION@/$(VERSION)/g' \ 208 -e 's/@PACKAGE_VERSION_NUM@/$(VERSION_NUM)/g' > $@ 209 touch --reference=includes/nghttp2/nghttp2ver.h.in $@ 210 211 212define RES_FILE 213 #include <winver.h> 214 215 VS_VERSION_INFO VERSIONINFO 216 FILEVERSION $(VER_MAJOR), $(VER_MINOR), $(VER_MICRO), 0 217 PRODUCTVERSION $(VER_MAJOR), $(VER_MINOR), $(VER_MICRO), 0 218 FILEFLAGSMASK 0x3fL 219 FILEOS 0x40004L 220 FILETYPE 0x2L 221 FILESUBTYPE 0x0L 222 #ifdef _DEBUG 223 #define VER_STR "$(VERSION).0 (MSVC debug)" 224 #define DBG "d" 225 FILEFLAGS 0x1L 226 #else 227 #define VER_STR "$(VERSION).0 (MSVC release)" 228 #define DBG "" 229 FILEFLAGS 0x0L 230 #endif 231 BEGIN 232 BLOCK "StringFileInfo" 233 BEGIN 234 BLOCK "040904b0" 235 BEGIN 236 VALUE "CompanyName", "http://tatsuhiro-t.github.io/nghttp2/" 237 VALUE "FileDescription", "nghttp2; HTTP/2 C library" 238 VALUE "FileVersion", VER_STR 239 VALUE "InternalName", "nghttp2" DBG 240 VALUE "LegalCopyright", "The MIT License" 241 VALUE "LegalTrademarks", "" 242 VALUE "OriginalFilename", "nghttp2" DBG ".dll" 243 VALUE "ProductName", "NGHTTP2." 244 VALUE "ProductVersion", VER_STR 245 END 246 END 247 BLOCK "VarFileInfo" 248 BEGIN 249 VALUE "Translation", 0x409, 1200 250 END 251 END 252endef 253 254export RES_FILE 255 256$(OBJ_DIR)/nghttp2.rc: Makefile.MSVC 257 @echo 'Generating $@...' 258 @echo ' /* $(GENERATED). DO NOT EDIT.' > $@ 259 @echo ' */' >> $@ 260 @echo "$$RES_FILE" >> $@ 261 262clean: 263 rm -f $(OBJ_DIR)/* includes/nghttp2/nghttp2ver.h 264 @echo 265 266vclean realclean: clean clean_nghttp2_pyd_$(USE_CYTHON) 267 - rm -rf $(OBJ_DIR) 268 - rm -f .depend.MSVC 269 270# 271# Use gcc to generated the dependencies. No MSVC specific args please! 272# 273REPLACE_R = 's/\(.*\)\.o: /\n$$(OBJ_DIR)\/r_\1.obj: /' 274REPLACE_D = 's/\(.*\)\.o: /\n$$(OBJ_DIR)\/d_\1.obj: /' 275 276depend: includes/nghttp2/nghttp2ver.h 277 @echo '# $(GENERATED). DO NOT EDIT.' > .depend.MSVC 278 gcc -MM $(CFLAGS) $(NGHTTP2_SRC) >> .depend.tmp 279 @echo '#' >> .depend.MSVC 280 @echo '# Release lib objects:' >> .depend.MSVC 281 sed -e $(REPLACE_R) .depend.tmp >> .depend.MSVC 282 @echo '#' >> .depend.MSVC 283 @echo '# Debug lib objects:' >> .depend.MSVC 284 sed -e $(REPLACE_D) .depend.tmp >> .depend.MSVC 285 rm -f .depend.tmp 286 287-include .depend.MSVC 288