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