forked from kimwalisch/primesieve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.msvc
196 lines (160 loc) · 7.01 KB
/
Makefile.msvc
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
######################################################################
# Microsoft Visual C++ Makefile for the primesieve console
# application and the primesieve C++ library
######################################################################
TARGET = primesieve
CXX = cl /nologo
CXXFLAGS = /W2 /O2 /EHsc
INCPATH = /I"include" /I"src\msvc_compat"
LINK = link /nologo
OBJDIR = obj
PRIMESIEVE_OBJECTS = \
$(OBJDIR)\EratBig.obj \
$(OBJDIR)\EratMedium.obj \
$(OBJDIR)\EratSmall.obj \
$(OBJDIR)\ParallelPrimeSieve.obj \
$(OBJDIR)\popcount.obj \
$(OBJDIR)\PreSieve.obj \
$(OBJDIR)\PrimeFinder.obj \
$(OBJDIR)\PrimeGenerator.obj \
$(OBJDIR)\primesieve_iterator.obj \
$(OBJDIR)\primesieve-api.obj \
$(OBJDIR)\primesieve-api-c.obj \
$(OBJDIR)\PrimeSieve-nthPrime.obj \
$(OBJDIR)\PrimeSieve.obj \
$(OBJDIR)\iterator.obj \
$(OBJDIR)\SieveOfEratosthenes.obj \
$(OBJDIR)\WheelFactorization.obj \
$(OBJDIR)\test.obj
PRIMESIEVE_HEADERS = \
include\primesieve.hpp \
include\primesieve.h \
include\primesieve\bits.hpp \
include\primesieve\Callback.hpp \
include\primesieve\callback_t.hpp \
include\primesieve\config.hpp \
include\primesieve\EratBig.hpp \
include\primesieve\EratMedium.hpp \
include\primesieve\EratSmall.hpp \
include\primesieve\pmath.hpp \
include\primesieve\littleendian_cast.hpp \
include\primesieve\ParallelPrimeSieve.hpp \
include\primesieve\ParallelPrimeSieve-lock.hpp \
include\primesieve\PreSieve.hpp \
include\primesieve\PrimeFinder.hpp \
include\primesieve\PrimeGenerator.hpp \
include\primesieve\PrimeSieve-lock.hpp \
include\primesieve\PrimeSieve.hpp \
include\primesieve\primesieve_error.hpp \
include\primesieve\primesieve_iterator.h \
include\primesieve\iterator.hpp \
include\primesieve\PushBackPrimes.hpp \
include\primesieve\SieveOfEratosthenes-inline.hpp \
include\primesieve\SieveOfEratosthenes.hpp \
include\primesieve\cancel_callback.hpp \
include\primesieve\toString.hpp \
include\primesieve\WheelFactorization.hpp
APP_OBJECTS = \
$(OBJDIR)\cmdoptions.obj \
$(OBJDIR)\help.obj \
$(OBJDIR)\main.obj
EXAMPLE_OBJECTS = \
$(OBJDIR)\examples\callback_cancel.obj \
$(OBJDIR)\examples\callback_primes.obj \
$(OBJDIR)\examples\callback_primes_oop.obj \
$(OBJDIR)\examples\count_primes.obj \
$(OBJDIR)\examples\primesieve_iterator.obj \
$(OBJDIR)\examples\nth_prime.obj \
$(OBJDIR)\examples\previous_prime.obj \
$(OBJDIR)\examples\store_primes_in_vector.obj
#-----------------------------------------------------------------------------
# Add /openmp if MSVC supports OpenMP
#-----------------------------------------------------------------------------
!IF ([$(CXX) /openmp /c src\msvc_compat\has_openmp.cpp /Fonul > nul] == 0)
CXXFLAGS = $(CXXFLAGS) /openmp
!ELSE
NO_OPENMP = true
!ENDIF
#-----------------------------------------------------------------------------
# Add L1_DCACHE_SIZE to CXXFLAGS
#-----------------------------------------------------------------------------
!IFDEF L1_DCACHE_SIZE
CXXFLAGS = $(CXXFLAGS) /DL1_DCACHE_SIZE=$(L1_DCACHE_SIZE)
!ENDIF
#-----------------------------------------------------------------------------
# Add SIEVESIZE to CXXFLAGS
#-----------------------------------------------------------------------------
!IFDEF SIEVESIZE
CXXFLAGS = $(CXXFLAGS) /DSIEVESIZE=$(SIEVESIZE)
!ENDIF
#-----------------------------------------------------------------------------
# Add include path to CXXFLAGS
#-----------------------------------------------------------------------------
!IFDEF INCPATH
CXXFLAGS = $(CXXFLAGS) $(INCPATH)
!ENDIF
#-----------------------------------------------------------------------------
# Default targets
#-----------------------------------------------------------------------------
all: lib bin
#-----------------------------------------------------------------------------
# Create and clean output directories
#-----------------------------------------------------------------------------
make_dir:
@if not exist $(OBJDIR) mkdir $(OBJDIR)
@if not exist $(OBJDIR)\examples mkdir $(OBJDIR)\examples
clean:
-del *.exe primesieve.lib
-rd /Q /S $(OBJDIR) 2> /nul
#-----------------------------------------------------------------------------
# Compilation rules
#-----------------------------------------------------------------------------
$(PRIMESIEVE_OBJECTS): src\primesieve\$(@B).cpp $(PRIMESIEVE_HEADERS)
$(CXX) $(CXXFLAGS) /c src\primesieve\$(@B).cpp /Fo$@
$(APP_OBJECTS): src\apps\console\$(@B).cpp $(PRIMESIEVE_HEADERS)
$(CXX) $(CXXFLAGS) /c src\apps\console\$(@B).cpp /Fo$@
$(EXAMPLE_OBJECTS): examples\$(@B).cpp
$(CXX) $(CXXFLAGS) $** /Fo$@ /Fe$(@B).exe /link $(TARGET).lib
#-----------------------------------------------------------------------------
# Build the primesieve console application
#-----------------------------------------------------------------------------
bin: make_dir bin_obj openmp_note
bin_obj: lib $(APP_OBJECTS)
$(LINK) /OUT:$(TARGET).exe $(APP_OBJECTS) $(TARGET).lib
#-----------------------------------------------------------------------------
# Build a static primesieve.lib
#-----------------------------------------------------------------------------
lib: make_dir lib_obj openmp_note
lib_obj: $(PRIMESIEVE_OBJECTS)
lib.exe /nologo /OUT:$(TARGET).lib $**
#-----------------------------------------------------------------------------
# Build the example programs
#-----------------------------------------------------------------------------
examples: make_dir $(EXAMPLE_OBJECTS) openmp_note
#-----------------------------------------------------------------------------
# `nmake -f Makefile.msvc check` runs correctness tests
#-----------------------------------------------------------------------------
check test: bin
$(TARGET).exe --test
#-----------------------------------------------------------------------------
# OpenMP requires Microsoft Visual C++ Professional or higher
#-----------------------------------------------------------------------------
openmp_note:
!IF DEFINED(NO_OPENMP)
@echo " "
@echo " NOTE: Your MSVC version does not support OpenMP. For OpenMP you "
@echo " need Microsoft Visual C++ Professional or higher. "
!ENDIF
#-----------------------------------------------------------------------------
# Makefile help menu
#-----------------------------------------------------------------------------
help:
@echo ------------------------------------------------------
@echo -------------- primesieve build options --------------
@echo ------------------------------------------------------
@echo "nmake -f Makefile.msvc Build primesieve and primesieve.lib"
@echo "nmake -f Makefile.msvc L1_DCACHE_SIZE=64 Set CPU L1 data cache, here 64 KB"
@echo "nmake -f Makefile.msvc check Run integration tests"
@echo "nmake -f Makefile.msvc clean Clean the output directories"
@echo "nmake -f Makefile.msvc examples Build the example programs"
@echo "nmake -f Makefile.msvc help Print this help menu"