-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMakefile.mak
461 lines (395 loc) · 14.8 KB
/
Makefile.mak
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
# file: Makefile.mak
# authors: Andrea Vedaldi and Brian Fulkerson
# descrption: Microsoft NMake makefile
# --------------------------------------------------------------------
# Customization
# --------------------------------------------------------------------
#
# - MSVCR : the file name of msvcr__.dll for your compiler
# - MSVCRLOC : must point to the location of msvcr__.dll for your compiler
# - MATLABROOT : must point to MATLAB root directory (undef = no MEX support)
# Here is an example of how the variables might look with a different version
# of Visual Studio and an alternate location for Matlab
#MSVCR = msvcr80.dll
#MSVCP = msvcp80.dll
#MSVCM = msvcm80.dll
#MSMANIFEST = Microsoft.VC80.CRT.manifest
#MSVCRLOC = C:\Program Files\Microsoft Visual Studio 8\VC\redist\x86\Microsoft.VC80.CRT
#MATLABROOT = C:\Program Files\MATLAB08a
VER = 0.9.8
ARCH = w32
VCROOT = C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC
WINSDKROOT = C:\Program Files\Microsoft SDKs\Windows\v6.0
MATLABROOT = C:\Program Files (x86)\MATLAB\R2009b
CC = "$(VCROOT)\bin\cl.exe"
LINK = "$(VCROOT)\bin\link.exe"
MSVCRLOC = $(VCROOT)\redist\x86\Microsoft.VC90.CRT
MSVCR = msvcr90.dll
MSVCP = msvcp90.dll
MSVCM = msvcm90.dll
MSMANIFEST = Microsoft.VC90.CRT.manifest
MEX = "$(MATLABROOT)\bin\mex.bat"
MEXEXT = mexw32
MEXOPT = $(MATLABROOT)\bin\win32\mexopts\msvc90opts.bat
LFLAGS = /MACHINE:X86 \
/LIBPATH:"$(VCROOT)\lib" \
/LIBPATH:"$(WINSDKROOT)\lib"
!if "$(ARCH)" == "w64"
!message === COMPILING FOR 64-BIT ===
VCROOT = C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC
WINSDKROOT = C:\Program Files\Microsoft SDKs\Windows\v6.0A
MATLABROOT = C:\Program Files\MATLAB\R2009b
CC = "$(VCROOT)\bin\amd64\cl.exe"
LINK = "$(VCROOT)\bin\amd64\link.exe"
MSVCRLOC = $(VCROOT)\redist\amd64\Microsoft.VC90.CRT
MSVCR = msvcr90.dll
MSVCP = msvcp90.dll
MSVCM = msvcm90.dll
MSMANIFEST = Microsoft.VC90.CRT.manifest
MEX = "$(MATLABROOT)\bin\mex.bat"
MEXEXT = mexw64
MEXOPT = $(MATLABROOT)\bin\win64\mexopts\msvc90opts.bat
LFLAGS = /MACHINE:X64 \
/LIBPATH:"$(VCROOT)\lib\amd64" \
/LIBPATH:"$(WINSDKROOT)\lib\x64"
!endif
GIT = git
BRANCH = v$(VER)-$(ARCH)
# --------------------------------------------------------------------
# Flags
# --------------------------------------------------------------------
# Debug info is embedded in .obj and .lib files (CodeView /Z7 option)
# but in .pdb files for .exe and .dll (since the linker does not
# produce CodeView output anymore).
#
# CFLAGS
# /nologo : CL does not display splash
# _CRT_NO_DEPRECATE : Do not deprecate `insecure' fscanf, snprintf, ...
# __LITTLE_ENDIAN__ : Signal little endian architecture
# /I. : Add VLROOT to include search path
# /Z7 : Embedded CodeView debug info in .obj
# /MD : Multi-thread run-time library dynamically linked
# /TC : Source code is C (not C++)
# /W3 : Usa all warnings
# /Zp8 : Align structures to 8 bytes
# /Ox : Turn on optimizations
#
# LFLAGS
# /NOLOGO : LINK does not display splash
# /INCREMENTAL:NO : No incremental linking
# /MANIFEST : See DLL HELL below
# /DEBUG : Generate debug info (.pdb files)
#
# MEX_FLAGS
# -I : Include VLFeat
# -L : Add a library search path
# -l : Link a dll
#
# ======================= ABOUT THE DLL HELL =========================
#
# This makefile compiles VLFeat to make use of the side-by-side
# deployment model. In other words, the C runtime library is
# re-distributed with the application and the appropriate manifest
# file is embedded in the binaries.
#
# References:
# http://www.codeguru.com/forum/showthread.php?t=408061
#
bindir = bin\$(ARCH)
mexdir = toolbox\mex\$(MEXEXT)
objdir = $(bindir)\objs
CFLAGS = /nologo /TC /MD \
/D"_CRT_SECURE_NO_DEPRECATE" \
/D"__LITTLE_ENDIAN__" \
/D"VL_ENABLE_SSE2" \
/D"VL_ENABLE_THREADS" \
/I. \
/W1 /Z7 /Zp8 /Ox
LFLAGS = $(LFLAGS) /NOLOGO \
/INCREMENTAL:NO \
/MANIFEST \
/DEBUG
DLL_CFLAGS = /D"VL_BUILD_DLL"
EXE_LFLAGS = $(LFLAGS) /LIBPATH:"$(bindir)" vl.lib
MEX_FLAGS = -v -f "$(MEXOPT)" -I. -Itoolbox -L"$(bindir)" -lvl \
-DVL_ENABLE_THREADS -DVL_ENABLE_SSE2
libsrc = \
vl\aib.c \
vl\dsift.c \
vl\generic.c \
vl\getopt_long.c \
vl\hikmeans.c \
vl\homkermap.c \
vl\host.c \
vl\ikmeans.c \
vl\imopv.c \
vl\imopv_sse2.c \
vl\kdtree.c \
vl\kmeans.c \
vl\mathop.c \
vl\mathop_sse2.c \
vl\mser.c \
vl\pegasos.c \
vl\pgm.c \
vl\quickshift.c \
vl\random.c \
vl\rodrigues.c \
vl\sift.c \
vl\stringop.c
cmdsrc = \
src\aib.c \
src\mser.c \
src\sift.c \
src\test_getopt_long.c \
src\test_heap-def.c \
src\test_host.c \
src\test_imopv.c \
src\test_mathop.c \
src\test_mathop_abs.c \
src\test_nan.c \
src\test_qsort-def.c \
src\test_rand.c \
src\test_stringop.c \
src\test_threads.c \
src\test_vec_comp.c
mexsrc = \
toolbox\aib\vl_aib.c \
toolbox\aib\vl_aibhist.c \
toolbox\geometry\vl_irodr.c \
toolbox\geometry\vl_rodr.c \
toolbox\imop\vl_imdisttf.c \
toolbox\imop\vl_imintegral.c \
toolbox\imop\vl_imsmooth.c \
toolbox\imop\vl_imwbackwardmx.c \
toolbox\imop\vl_tpsumx.c \
toolbox\kmeans\vl_hikmeans.c \
toolbox\kmeans\vl_hikmeanspush.c \
toolbox\kmeans\vl_ikmeans.c \
toolbox\kmeans\vl_ikmeanspush.c \
toolbox\kmeans\vl_kmeans.c \
toolbox\misc\vl_alldist.c \
toolbox\misc\vl_alldist2.c \
toolbox\misc\vl_binsearch.c \
toolbox\misc\vl_binsum.c \
toolbox\misc\vl_getpid.c \
toolbox\misc\vl_homkermap.c \
toolbox\misc\vl_ihashfind.c \
toolbox\misc\vl_ihashsum.c \
toolbox\misc\vl_inthist.c \
toolbox\misc\vl_kdtreebuild.c \
toolbox\misc\vl_kdtreequery.c \
toolbox\misc\vl_localmax.c \
toolbox\misc\vl_pegasos.c \
toolbox\misc\vl_samplinthist.c \
toolbox\misc\vl_simdctrl.c \
toolbox\misc\vl_twister.c \
toolbox\misc\vl_version.c \
toolbox\mser\vl_erfill.c \
toolbox\mser\vl_mser.c \
toolbox\quickshift\vl_quickshift.c \
toolbox\sift\vl_dsift.c \
toolbox\sift\vl_sift.c \
toolbox\sift\vl_siftdescriptor.c \
toolbox\sift\vl_ubcmatch.c
# horrible Make program, horrible code:
libobj = $(libsrc:vl\=bin\w32\objs\)
cmdexe = $(cmdsrc:src\=bin\w32\)
mexdll = $(mexsrc:.c=.mexw32)
mexdll = $(mexdll:toolbox\sift=toolbox\mex\mexw32)
mexdll = $(mexdll:toolbox\mser=toolbox\mex\mexw32)
mexdll = $(mexdll:toolbox\imop=toolbox\mex\mexw32)
mexdll = $(mexdll:toolbox\geometry=toolbox\mex\mexw32)
mexdll = $(mexdll:toolbox\kmeans=toolbox\mex\mexw32)
mexdll = $(mexdll:toolbox\misc=toolbox\mex\mexw32)
mexdll = $(mexdll:toolbox\aib=toolbox\mex\mexw32)
mexdll = $(mexdll:toolbox\quickshift=toolbox\mex\mexw32)
mexpdb = $(mexdll:.dll=.pdb)
!if "$(ARCH)" == "w64"
libobj = $(libsrc:vl\=bin\w64\objs\)
cmdexe = $(cmdsrc:src\=bin\w64\)
mexdll = $(mexsrc:.c=.mexw64)
mexdll = $(mexdll:toolbox\sift=toolbox\mex\mexw64)
mexdll = $(mexdll:toolbox\mser=toolbox\mex\mexw64)
mexdll = $(mexdll:toolbox\imop=toolbox\mex\mexw64)
mexdll = $(mexdll:toolbox\geometry=toolbox\mex\mexw64)
mexdll = $(mexdll:toolbox\kmeans=toolbox\mex\mexw64)
mexdll = $(mexdll:toolbox\misc=toolbox\mex\mexw64)
mexdll = $(mexdll:toolbox\aib=toolbox\mex\mexw64)
mexdll = $(mexdll:toolbox\quickshift=toolbox\mex\mexw64)
mexpdb = $(mexdll:.mexw64=.pdb)
!endif
libobj = $(libobj:.c=.obj)
cmdexe = $(cmdexe:.c=.exe)
cmdpdb = $(cmdexe:.exe=.pdb)
!IFDEF MATLABROOT
all: $(bindir) $(objdir) $(mexdir) $(bindir)\vl.lib $(bindir)\vl.dll $(mexdir)\vl.dll $(cmdexe) $(mexdll) $(mexdir)\$(MSMANIFEST) $(mexdir)\$(MSVCR) $(mexdir)\$(MSVCP) $(mexdir)\$(MSVCM) $(bindir)\$(MSMANIFEST) $(bindir)\$(MSVCR) $(bindir)\$(MSVCP) $(bindir)\$(MSVCM)
!ELSE
all: $(bindir) $(objdir) $(bindir)\vl.lib $(bindir)\vl.dll $(cmdexe) $(bindir)\$(MSMANIFEST) $(bindir)\$(MSVCR) $(bindir)\$(MSVCP) $(bindir)\$(MSVCM)
!ENDIF
BUILD_MEX=@echo .... CC [MEX] $(@R).dll && \
$(MEX) $(MEX_FLAGS) "$(<)" -output $(@)
# --------------------------------------------------------------------
# Maintenance rules
# --------------------------------------------------------------------
clean:
del /f /Q $(libobj)
del /f /Q $(objdir)
del /f /Q $(cmdpdb)
del /f /Q $(mexpdb)
archclean:
if exist bin\$(ARCH) rmdir /S /Q bin\$(ARCH)
if exist toolbox\mex$(ARCH) rmdir /S /Q toolbox\mex$(ARCH)
distclean:
if exist bin\w32 rmdir /S /Q bin\w32
if exist bin\w64 rmdir /S /Q bin\w64
if exist toolbox\mexw32 rmdir /S /Q toolbox\mexw32
if exist toolbox\mexw64 rmdir /S /Q toolbox\mexw64
info:
@echo $(mexx)
@echo ** bindir = $(bindir)
@echo ** mexdir = $(mexdir)
@echo ** objdir = $(objdir)
@echo ** libsrc = $(libsrc)
@echo ** libobj = $(libobj)
@echo ** cmdsrc = $(cmdsrc)
@echo ** cmdexe = $(cmdexe)
@echo ** mexsrc = $(mexsrc)
@echo ** mexdll = $(mexdll)
@echo ** CC = $(CC)
@echo ** CFLAGS = $(CFLAGS)
@echo ** DLL_CFLAGS = $(DLL_CFLAGS)
@echo ** MEX_CFLAGS = $(MEX_CFLAGS)
@echo ** BUILD_MEX = "$(BUILD_MEX)"
@echo ** MATLABROOT = $(MATLABROOT)
@echo ** MEX_LFLAGS = $(MEX_LFLAGS)
@echo ** MEX = $(MEX)
# --------------------------------------------------------------------
# Build rules
# --------------------------------------------------------------------
# create directory if missing
$(bindir) :
mkdir $(bindir)
$(objdir) :
mkdir $(objdir)
$(mexdir) :
mkdir $(mexdir)
# --------------------------------------------------------------------
# Rules to compile VLFeat DLL
# --------------------------------------------------------------------
# special sources with SSE2 support
$(objdir)\mathop_sse2.obj : vl\mathop_sse2.c
@echo .... CC [+SSE2] $(@)
@$(CC) $(CFLAGS) $(DLL_CFLAGS) /arch:SSE2 /D"__SSE2__" /c /Fo"$(@)" "vl\$(@B).c"
$(objdir)\imopv_sse2.obj : vl\imopv_sse2.c
@echo .... CC [+SSE2] $(@)
@$(CC) $(CFLAGS) $(DLL_CFLAGS) /arch:SSE2 /D"__SSE2__" /c /Fo"$(@)" "vl\$(@B).c"
# vl\*.c -> $objdir\*.obj
{vl}.c{$(objdir)}.obj:
@echo .... CC $(@)
@$(CC) $(CFLAGS) $(DLL_CFLAGS) /c /Fo"$(@)" "$(<)"
# Link VLFeat DLL
$(bindir)\vl.dll : $(libobj)
@echo .. LINK [DLL] $(@R).dll
$(LINK) /DLL $(LFLAGS) $(**) /OUT:"$(@)"
@mt /nologo /outputresource:"$(@);#2" /manifest "$(@R).dll.manifest"
@-del "$(@R).dll.manifest"
# *.obj -> *.lib
$(bindir)\vl.lib : $(libobj)
@echo ... LIB $(@R).lib
@lib $(**) /OUT:"$(@)" /NOLOGO
# --------------------------------------------------------------------
# Rules to compile EXE
# --------------------------------------------------------------------
# src\*.c -> $bindir\*.exe
{src}.c{$(bindir)}.exe:
@echo .... CC [EXE] $(@)
@$(CC) $(CFLAGS) /Fe"$(@)" /Fo"$(@R).obj" "$(<)" /link $(EXE_LFLAGS)
@MT /nologo /outputresource:"$(@);#1" /manifest "$(@).manifest"
@-del "$(@).manifest"
@-del "$(@R).obj"
# --------------------------------------------------------------------
# Rules to compile MEX
# --------------------------------------------------------------------
startmatlab:
"$(MATLABROOT)/bin/matlab.exe" -nodesktop
# toolbox\*.c -> toolbox\*.dll
{toolbox\sift}.c{$(mexdir)}.$(MEXEXT):
$(BUILD_MEX)
{toolbox\mser}.c{$(mexdir)}.$(MEXEXT):
$(BUILD_MEX)
{toolbox\imop}.c{$(mexdir)}.$(MEXEXT):
$(BUILD_MEX)
{toolbox\geometry}.c{$(mexdir)}.$(MEXEXT):
$(BUILD_MEX)
{toolbox\kmeans}.c{$(mexdir)}.$(MEXEXT):
$(BUILD_MEX)
{toolbox\aib}.c{$(mexdir)}.$(MEXEXT):
$(BUILD_MEX)
{toolbox\quickshift}.c{$(mexdir)}.$(MEXEXT):
$(BUILD_MEX)
{toolbox\misc}.c{$(mexdir)}.$(MEXEXT):
$(BUILD_MEX)
# vl.dll => mexw{32,64}/vl.dll
$(mexdir)\vl.dll : $(bindir)\vl.dll
copy "$(**)" "$(@)"
# --------------------------------------------------------------------
# Rules to copy redistributable libraries
# --------------------------------------------------------------------
# msvcr__.dll => bin/win{32,64}/msvcr__.dll
$(bindir)\$(MSMANIFEST): "$(MSVCRLOC)\$(MSMANIFEST)"
copy $(**) "$(@)"
$(bindir)\$(MSVCR): "$(MSVCRLOC)\$(MSVCR)"
copy $(**) "$(@)"
$(bindir)\$(MSVCP): "$(MSVCRLOC)\$(MSVCP)"
copy $(**) "$(@)"
$(bindir)\$(MSVCM): "$(MSVCRLOC)\$(MSVCM)"
copy $(**) "$(@)"
# msvcr__.dll => toolbox/mexw32/msvcr__.dll
$(mexdir)\$(MSMANIFEST): "$(MSVCRLOC)\$(MSMANIFEST)"
copy $(**) "$(@)"
$(mexdir)\$(MSVCR): "$(MSVCRLOC)\$(MSVCR)"
copy $(**) "$(@)"
$(mexdir)\$(MSVCP): "$(MSVCRLOC)\$(MSVCP)"
copy $(**) "$(@)"
$(mexdir)\$(MSVCM): "$(MSVCRLOC)\$(MSVCM)"
copy $(**) "$(@)"
# --------------------------------------------------------------------
# Rules to post the binary files
# --------------------------------------------------------------------
bin-release:
echo Fetching remote tags && \
git fetch --tags && \
echo Checking out v$(VER) && \
$(GIT) checkout v$(VER)
echo Rebuilding binaries for release
if exist "bin\$(ARCH)" del /f /Q "bin\$(ARCH)"
if exist "bin\mex\$(ARCH)" del /f /Q "toolbox\mex$(ARCH)"
nmake /f Makefile.mak ARCH=$(ARCH)
bin-commit: bin-release
@echo Fetching remote tags && \
git fetch --tags
@echo Crearing/resetting and checking out branch $(BRANCH) to v$(VER) && \
$(GIT) branch -f $(BRANCH) v$(VER) && \
$(GIT) checkout $(BRANCH)
@echo Adding binaries && \
$(GIT) add -f $(bindir)\vl.lib && \
$(GIT) add -f $(bindir)\vl.dll && \
$(GIT) add -f $(cmdexe) && \
$(GIT) add -f $(bindir)\$(MSANIFEST) && \
$(GIT) add -f $(bindir)\$(MSVCP) && \
$(GIT) add -f $(bindir)\$(MSVCR) && \
$(GIT) add -f $(bindir)\$(MSVCM)
@echo Adding MEX files && \
$(GIT) add -f $(mexdll) && \
$(GIT) add -f $(mexdir)\$(MSANIFEST) && \
$(GIT) add -f $(mexdir)\$(MSVCP) && \
$(GIT) add -f $(mexdir)\$(MSVCR) && \
$(GIT) add -f $(mexdir)\$(MSVCM) && \
$(GIT) add -f $(mexdir)\$(MSVCP) && \
$(GIT) add -f $(mexdir)\$(MSVCR)
@echo Commiting changes && \
$(GIT) commit -m "$(ARCH) binaries for version $(VER)"
@echo Commiting and pushing to server the binaries && \
$(GIT) push -v --force bin $(BRANCH):refs/heads/$(BRANCH) && \
$(GIT) checkout v$(VER) && \
$(GIT) branch -D $(BRANCH)