Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.09 KB | None | 0 0
  1. ### Establish OS name
  2. KERNEL = $(shell uname -s)
  3. ifeq ($(KERNEL),Linux)
  4. OS = $(shell uname -o)
  5. endif
  6.  
  7. ### Executable name
  8. EXE = stockfish
  9.  
  10. ### Installation dir definitions
  11. PREFIX = /usr/local
  12. BINDIR = $(PREFIX)/bin
  13.  
  14. ### Built-in benchmark for pgo-builds
  15. PGOBENCH = ./$(EXE) bench
  16.  
  17. ### Object files
  18. OBJS = benchmark.o bitbase.o bitboard.o endgame.o evaluate.o main.o
  19. material.o misc.o movegen.o movepick.o pawns.o position.o psqt.o
  20. search.o thread.o timeman.o tt.o uci.o ucioption.o syzygy/tbprobe.o
  21.  
  22. ### 2.1. General and architecture defaults
  23. optimize = yes
  24. debug = no
  25. sanitize = no
  26. bits = 32
  27. prefetch = no
  28. popcnt = no
  29. sse = no
  30. pext = no
  31.  
  32. ### 2.2 Architecture specific
  33.  
  34. ifeq ($(ARCH),general-32)
  35. arch = any
  36. endif
  37.  
  38. ifeq ($(ARCH),x86-32-old)
  39. arch = i386
  40. endif
  41.  
  42. ifeq ($(ARCH),x86-32)
  43. arch = i386
  44. prefetch = yes
  45. sse = yes
  46. endif
  47.  
  48. ifeq ($(ARCH),general-64)
  49. arch = any
  50. bits = 64
  51. endif
  52.  
  53. ifeq ($(ARCH),x86-64)
  54. arch = x86_64
  55. bits = 64
  56. prefetch = yes
  57. sse = yes
  58. endif
  59.  
  60. ifeq ($(ARCH),x86-64-modern)
  61. arch = x86_64
  62. bits = 64
  63. prefetch = yes
  64. popcnt = yes
  65. sse = yes
  66. endif
  67.  
  68. ifeq ($(ARCH),x86-64-bmi2)
  69. arch = x86_64
  70. bits = 64
  71. prefetch = yes
  72. popcnt = yes
  73. sse = yes
  74. pext = yes
  75. endif
  76.  
  77. ifeq ($(ARCH),armv7)
  78. arch = armv7
  79. prefetch = yes
  80. endif
  81.  
  82. ifeq ($(ARCH),ppc-32)
  83. arch = ppc
  84. endif
  85.  
  86. ifeq ($(ARCH),ppc-64)
  87. arch = ppc64
  88. bits = 64
  89. endif
  90.  
  91. ### 3.1 Selecting compiler (default = gcc)
  92.  
  93. CXXFLAGS += -Wall -Wcast-qual -fno-exceptions -fno-rtti -std=c++11 $(EXTRACXXFLAGS)
  94. DEPENDFLAGS += -std=c++11
  95. LDFLAGS += $(EXTRALDFLAGS)
  96.  
  97. ifeq ($(COMP),)
  98. COMP=gcc
  99. endif
  100.  
  101. ifeq ($(COMP),gcc)
  102. comp=gcc
  103. CXX=g++
  104. CXXFLAGS += -pedantic -Wextra -Wshadow
  105.  
  106. ifeq ($(ARCH),armv7)
  107. ifeq ($(OS),Android)
  108. CXXFLAGS += -m$(bits)
  109. LDFLAGS += -m$(bits)
  110. endif
  111. else
  112. CXXFLAGS += -m$(bits)
  113. LDFLAGS += -m$(bits)
  114. endif
  115.  
  116. ifneq ($(KERNEL),Darwin)
  117. LDFLAGS += -Wl,--no-as-needed
  118. endif
  119. endif
  120.  
  121. ifeq ($(COMP),mingw)
  122. comp=mingw
  123.  
  124. ifeq ($(KERNEL),Linux)
  125. ifeq ($(bits),64)
  126. ifeq ($(shell which x86_64-w64-mingw32-c++-posix),)
  127. CXX=x86_64-w64-mingw32-c++
  128. else
  129. CXX=x86_64-w64-mingw32-c++-posix
  130. endif
  131. else
  132. ifeq ($(shell which i686-w64-mingw32-c++-posix),)
  133. CXX=i686-w64-mingw32-c++
  134. else
  135. CXX=i686-w64-mingw32-c++-posix
  136. endif
  137. endif
  138. else
  139. CXX=g++
  140. endif
  141.  
  142. CXXFLAGS += -Wextra -Wshadow
  143. LDFLAGS += -static
  144. endif
  145.  
  146. ifeq ($(COMP),icc)
  147. comp=icc
  148. CXX=icpc
  149. CXXFLAGS += -diag-disable 1476,10120 -Wcheck -Wabi -Wdeprecated -strict-ansi
  150. endif
  151.  
  152. ifeq ($(COMP),clang)
  153. comp=clang
  154. CXX=clang++
  155. CXXFLAGS += -pedantic -Wextra -Wshadow
  156.  
  157. ifeq ($(ARCH),armv7)
  158. ifeq ($(OS),Android)
  159. CXXFLAGS += -m$(bits)
  160. LDFLAGS += -m$(bits)
  161. endif
  162. else
  163. CXXFLAGS += -m$(bits)
  164. LDFLAGS += -m$(bits)
  165. endif
  166. endif
  167.  
  168. ifeq ($(comp),icc)
  169. profile_make = icc-profile-make
  170. profile_use = icc-profile-use
  171. else
  172. ifeq ($(comp),clang)
  173. profile_make = clang-profile-make
  174. profile_use = clang-profile-use
  175. else
  176. profile_make = gcc-profile-make
  177. profile_use = gcc-profile-use
  178. endif
  179. endif
  180.  
  181. ifeq ($(KERNEL),Darwin)
  182. CXXFLAGS += -arch $(arch) -mmacosx-version-min=10.9
  183. LDFLAGS += -arch $(arch) -mmacosx-version-min=10.9
  184. endif
  185.  
  186. ### Travis CI script uses COMPILER to overwrite CXX
  187. ifdef COMPILER
  188. COMPCXX=$(COMPILER)
  189. endif
  190.  
  191. ### Allow overwriting CXX from command line
  192. ifdef COMPCXX
  193. CXX=$(COMPCXX)
  194. endif
  195.  
  196. ### On mingw use Windows threads, otherwise POSIX
  197. ifneq ($(comp),mingw)
  198. # On Android Bionic's C library comes with its own pthread implementation bundled in
  199. ifneq ($(OS),Android)
  200. # Haiku has pthreads in its libroot, so only link it in on other platforms
  201. ifneq ($(KERNEL),Haiku)
  202. LDFLAGS += -lpthread
  203. endif
  204. endif
  205. endif
  206.  
  207. ### 3.2.1 Debugging
  208. ifeq ($(debug),no)
  209. CXXFLAGS += -DNDEBUG
  210. else
  211. CXXFLAGS += -g
  212. endif
  213.  
  214. ### 3.2.2 Debugging with undefined behavior sanitizers
  215. ifeq ($(sanitize),yes)
  216. CXXFLAGS += -g3 -fsanitize=undefined
  217. LDFLAGS += -fsanitize=undefined
  218. endif
  219.  
  220. ### 3.3 Optimization
  221. ifeq ($(optimize),yes)
  222.  
  223. CXXFLAGS += -O3
  224.  
  225. ifeq ($(comp),gcc)
  226.  
  227. ifeq ($(KERNEL),Darwin)
  228. ifeq ($(arch),i386)
  229. CXXFLAGS += -mdynamic-no-pic
  230. endif
  231. ifeq ($(arch),x86_64)
  232. CXXFLAGS += -mdynamic-no-pic
  233. endif
  234. endif
  235.  
  236. ifeq ($(OS), Android)
  237. CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
  238. endif
  239. endif
  240.  
  241. ifeq ($(comp),icc)
  242. ifeq ($(KERNEL),Darwin)
  243. CXXFLAGS += -mdynamic-no-pic
  244. endif
  245. endif
  246.  
  247. ifeq ($(comp),clang)
  248. ifeq ($(KERNEL),Darwin)
  249. CXXFLAGS += -flto
  250. LDFLAGS += $(CXXFLAGS)
  251. ifeq ($(arch),i386)
  252. CXXFLAGS += -mdynamic-no-pic
  253. endif
  254. ifeq ($(arch),x86_64)
  255. CXXFLAGS += -mdynamic-no-pic
  256. endif
  257. endif
  258. endif
  259. endif
  260.  
  261. ### 3.4 Bits
  262. ifeq ($(bits),64)
  263. CXXFLAGS += -DIS_64BIT
  264. endif
  265.  
  266. ### 3.5 prefetch
  267. ifeq ($(prefetch),yes)
  268. ifeq ($(sse),yes)
  269. CXXFLAGS += -msse
  270. DEPENDFLAGS += -msse
  271. endif
  272. else
  273. CXXFLAGS += -DNO_PREFETCH
  274. endif
  275.  
  276. ### 3.6 popcnt
  277. ifeq ($(popcnt),yes)
  278. ifeq ($(comp),icc)
  279. CXXFLAGS += -msse3 -DUSE_POPCNT
  280. else
  281. CXXFLAGS += -msse3 -mpopcnt -DUSE_POPCNT
  282. endif
  283. endif
  284.  
  285. ### 3.7 pext
  286. ifeq ($(pext),yes)
  287. CXXFLAGS += -DUSE_PEXT
  288. ifeq ($(comp),$(filter $(comp),gcc clang mingw))
  289. CXXFLAGS += -mbmi2
  290. endif
  291. endif
  292.  
  293. ### 3.8 Link Time Optimization, it works since gcc 4.5 but not on mingw under Windows.
  294. ### This is a mix of compile and link time options because the lto link phase
  295. ### needs access to the optimization flags.
  296. ifeq ($(comp),gcc)
  297. ifeq ($(optimize),yes)
  298. ifeq ($(debug),no)
  299. CXXFLAGS += -flto
  300. LDFLAGS += $(CXXFLAGS)
  301. endif
  302. endif
  303. endif
  304.  
  305. ifeq ($(comp),mingw)
  306. ifeq ($(KERNEL),Linux)
  307. ifeq ($(optimize),yes)
  308. ifeq ($(debug),no)
  309. CXXFLAGS += -flto
  310. LDFLAGS += $(CXXFLAGS)
  311. endif
  312. endif
  313. endif
  314. endif
  315.  
  316. ### 3.9 Android 5 can only run position independent executables. Note that this
  317. ### breaks Android 4.0 and earlier.
  318. ifeq ($(OS), Android)
  319. CXXFLAGS += -fPIE
  320. LDFLAGS += -fPIE -pie
  321. endif
  322.  
  323. .PHONY: help build profile-build strip install clean objclean profileclean help
  324. config-sanity icc-profile-use icc-profile-make gcc-profile-use gcc-profile-make
  325. clang-profile-use clang-profile-make
  326.  
  327. build: config-sanity
  328. $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
  329.  
  330. profile-build: config-sanity objclean profileclean
  331. @echo ""
  332. @echo "Step 1/4. Building instrumented executable ..."
  333. $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
  334. @echo ""
  335. @echo "Step 2/4. Running benchmark for pgo-build ..."
  336. $(PGOBENCH) > /dev/null
  337. @echo ""
  338. @echo "Step 3/4. Building optimized executable ..."
  339. $(MAKE) ARCH=$(ARCH) COMP=$(COMP) objclean
  340. $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
  341. @echo ""
  342. @echo "Step 4/4. Deleting profile data ..."
  343. $(MAKE) ARCH=$(ARCH) COMP=$(COMP) profileclean
  344.  
  345. strip:
  346. strip $(EXE)
  347.  
  348. install:
  349. -mkdir -p -m 755 $(BINDIR)
  350. -cp $(EXE) $(BINDIR)
  351. -strip $(BINDIR)/$(EXE)
  352.  
  353. #clean all
  354. clean: objclean profileclean
  355. @rm -f .depend *~ core
  356.  
  357. # clean binaries and objects
  358. objclean:
  359. @rm -f $(EXE) $(EXE).exe *.o ./syzygy/*.o
  360.  
  361. # clean auxiliary profiling files
  362. profileclean:
  363. @rm -rf profdir
  364. @rm -f bench.txt *.gcda ./syzygy/*.gcda *.gcno ./syzygy/*.gcno
  365. @rm -f stockfish.profdata *.profraw
  366.  
  367. default:
  368. help
  369. ### Section 5. Private targets
  370.  
  371. all: $(EXE) .depend
  372.  
  373. config-sanity:
  374. @echo ""
  375. @echo "Config:"
  376. @echo "debug: '$(debug)'"
  377. @echo "sanitize: '$(sanitize)'"
  378. @echo "optimize: '$(optimize)'"
  379. @echo "arch: '$(arch)'"
  380. @echo "bits: '$(bits)'"
  381. @echo "kernel: '$(KERNEL)'"
  382. @echo "os: '$(OS)'"
  383. @echo "prefetch: '$(prefetch)'"
  384. @echo "popcnt: '$(popcnt)'"
  385. @echo "sse: '$(sse)'"
  386. @echo "pext: '$(pext)'"
  387. @echo ""
  388. @echo "Flags:"
  389. @echo "CXX: $(CXX)"
  390. @echo "CXXFLAGS: $(CXXFLAGS)"
  391. @echo "LDFLAGS: $(LDFLAGS)"
  392. @echo ""
  393. @echo "Testing config sanity. If this fails, try 'make help' ..."
  394. @echo ""
  395. @test "$(debug)" = "yes" || test "$(debug)" = "no"
  396. @test "$(sanitize)" = "yes" || test "$(sanitize)" = "no"
  397. @test "$(optimize)" = "yes" || test "$(optimize)" = "no"
  398. @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" ||
  399. test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "armv7"
  400. @test "$(bits)" = "32" || test "$(bits)" = "64"
  401. @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
  402. @test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
  403. @test "$(sse)" = "yes" || test "$(sse)" = "no"
  404. @test "$(pext)" = "yes" || test "$(pext)" = "no"
  405. @test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw" || test "$(comp)" = "clang"
  406.  
  407. $(EXE): $(OBJS)
  408. $(CXX) -o $@ $(OBJS) $(LDFLAGS)
  409.  
  410. clang-profile-make:
  411. $(MAKE) ARCH=$(ARCH) COMP=$(COMP)
  412. EXTRACXXFLAGS='-fprofile-instr-generate '
  413. EXTRALDFLAGS=' -fprofile-instr-generate'
  414. all
  415.  
  416. clang-profile-use:
  417. llvm-profdata merge -output=stockfish.profdata *.profraw
  418. $(MAKE) ARCH=$(ARCH) COMP=$(COMP)
  419. EXTRACXXFLAGS='-fprofile-instr-use=stockfish.profdata'
  420. EXTRALDFLAGS='-fprofile-use '
  421. all
  422.  
  423. gcc-profile-make:
  424. $(MAKE) ARCH=$(ARCH) COMP=$(COMP)
  425. EXTRACXXFLAGS='-fprofile-generate'
  426. EXTRALDFLAGS='-lgcov'
  427. all
  428.  
  429. gcc-profile-use:
  430. $(MAKE) ARCH=$(ARCH) COMP=$(COMP)
  431. EXTRACXXFLAGS='-fprofile-use -fno-peel-loops -fno-tracer'
  432. EXTRALDFLAGS='-lgcov'
  433. all
  434.  
  435. icc-profile-make:
  436. @mkdir -p profdir
  437. $(MAKE) ARCH=$(ARCH) COMP=$(COMP)
  438. EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir'
  439. all
  440.  
  441. icc-profile-use:
  442. $(MAKE) ARCH=$(ARCH) COMP=$(COMP)
  443. EXTRACXXFLAGS='-prof_use -prof_dir ./profdir'
  444. all
  445.  
  446. .depend:
  447. -@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
  448.  
  449. -include .depend
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement