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