Guest User

Makefile

a guest
Mar 21st, 2020
794
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ### 1. General Configuration
  2. ### ==========================================================================
  3.  
  4. ### Establish the operating system name
  5. UNAME = $(shell uname)
  6.  
  7. ### Executable name
  8. EXE = h.exe
  9.  
  10. ### Installation dir definitions
  11. PREFIX = /usr/local
  12. BINDIR = $(PREFIX)/bin
  13.  
  14. ### Built-in benchmark for pgo-builds
  15. ifeq ($(PTIME),)
  16. PTIME=1000
  17. endif
  18. PGOBENCH = ./$(EXE) bench 32 6 $(PTIME) default time
  19.  
  20. ### Object files
  21. OBJS =
  22.  
  23. ifneq ($(VERSION),Dev)
  24. OBJS += egtb_nalimov.o egtb_nalimovprobe.o
  25. endif
  26.  
  27. versmelt = yes
  28.  
  29. ifeq ($(versmelt),yes)
  30. OBJS += versmelting.o
  31. else
  32. OBJS += zoeken.o evaluatie.o \
  33. bord.o egtb_kpk.o eval_eindspel.o eval_materiaal.o eval_pionstruct.o \
  34. eval_pst.o main.o stelling.o uci.o uci_opties.o uci_tijd.o \
  35. util_bench.o util_tools.o zet_generatie.o zet_hash.o \
  36. zet_keuze.o zoek_smp.o syzygy/tbprobe.o \
  37. egtb_syzygyprobe.o licentie.o
  38. endif
  39.  
  40. COBJS = zlib/adler32.o zlib/crc32.o zlib/inffast.o zlib/inflate.o \
  41. zlib/inftrees.o zlib/uncompr.o zlib/zutil.o \
  42. polarssl/aes.o polarssl/md5.o polarssl/padlock.o
  43.  
  44. ### 2.1. General and architecture defaults
  45. ### ==========================================================================
  46.  
  47. optimize = yes
  48. debug = no
  49. bits = 32
  50. prefetch = no
  51. popcnt = no
  52. sse = no
  53. pext = no
  54.  
  55. ### 2.2 Architecture specific
  56. ### ==========================================================================
  57.  
  58. ifeq ($(ARCH),general-32)
  59. arch = any
  60. endif
  61.  
  62. ifeq ($(ARCH),x86-32-old)
  63. arch = i386
  64. endif
  65.  
  66. ifeq ($(ARCH),x86-32)
  67. arch = i386
  68. prefetch = yes
  69. sse = yes
  70. endif
  71.  
  72. ifeq ($(ARCH),x86-32-modern)
  73. arch = i386
  74. prefetch = yes
  75. popcnt = yes
  76. sse = yes
  77. endif
  78.  
  79. ifeq ($(ARCH),general-64)
  80. arch = any
  81. bits = 64
  82. endif
  83.  
  84. ifeq ($(ARCH),x86-64)
  85. arch = x86_64
  86. bits = 64
  87. prefetch = yes
  88. sse = yes
  89. endif
  90.  
  91. ifeq ($(ARCH),x86-64-modern)
  92. arch = x86_64
  93. bits = 64
  94. prefetch = yes
  95. popcnt = yes
  96. sse = yes
  97. endif
  98.  
  99. ifeq ($(ARCH),native)
  100. arch = native
  101. bits = 64
  102. prefetch = yes
  103. popcnt = yes
  104. sse = yes
  105. endif
  106.  
  107. ifeq ($(ARCH),x86-64-bmi2)
  108. arch = x86_64
  109. bits = 64
  110. prefetch = yes
  111. popcnt = yes
  112. sse = yes
  113. pext = yes
  114. endif
  115.  
  116. ifeq ($(ARCH),armv7)
  117. arch = armv7
  118. prefetch = yes
  119. endif
  120.  
  121. ifeq ($(ARCH),ppc-32)
  122. arch = ppc
  123. endif
  124.  
  125. ifeq ($(ARCH),ppc-64)
  126. arch = ppc64
  127. bits = 64
  128. endif
  129.  
  130. ### 2.3 Compile versions
  131. ### ==========================================================================
  132.  
  133. ifneq ($(VERSION),Dev)
  134. CXXFLAGS += -DUSE_LICENSE
  135. endif
  136.  
  137. ifeq ($(VERSION),Pro)
  138. CXXFLAGS += -DPREMIUM
  139. endif
  140.  
  141. ifeq ($(VERSION),Std)
  142. CXXFLAGS += -DPRO_LICENSE
  143. endif
  144.  
  145. family = none
  146.  
  147. ifeq ($(FAMILY),ChessBase)
  148. family = ChessBase
  149. CXXFLAGS += -DCHESSBASE
  150. ifeq ($(bits),64)
  151. LDFLAGS += -L. -l:libprot64.a -lole32
  152. else
  153. LDFLAGS += -L. -l:libprot32.a -lole32
  154. endif
  155. endif
  156.  
  157. ifeq ($(FAMILY),Aquarium)
  158. family = ChessOK
  159. CXXFLAGS += -DAQUARIUM
  160. endif
  161.  
  162. ifeq ($(FAMILY),ChessKing)
  163. family = ChessOK
  164. CXXFLAGS += -DCHESSKING
  165. endif
  166.  
  167. ifeq ($(FAMILY),ChessAssistant)
  168. family = ChessOK
  169. CXXFLAGS += -DCHESS_ASSISTANT
  170. endif
  171.  
  172.  
  173. ### 3.1 Selecting compiler (default = gcc)
  174. ### ==========================================================================
  175.  
  176. CXXFLAGS += -Wall -Wcast-qual -fno-exceptions $(EXTRACXXFLAGS)
  177. DEPENDFLAGS += -std=c++11
  178. LDFLAGS += $(EXTRALDFLAGS)
  179. CC = gcc
  180.  
  181. ifeq ($(COMP),)
  182. COMP=gcc
  183. endif
  184.  
  185. ifeq ($(COMP),gcc)
  186. comp=gcc
  187. CXX=g++
  188. CXXFLAGS += -pedantic -Wextra -Wshadow -m$(bits)
  189. ifneq ($(UNAME),Darwin)
  190. LDFLAGS += -Wl,--no-as-needed
  191. endif
  192. endif
  193.  
  194. ifeq ($(COMP),mingw)
  195. comp=mingw
  196.  
  197. ifeq ($(UNAME),Linux)
  198. ifeq ($(bits),64)
  199. ifeq ($(shell which x86_64-w64-mingw32-c++-posix),)
  200. CXX=x86_64-w64-mingw32-c++
  201. else
  202. CXX=x86_64-w64-mingw32-c++-posix
  203. endif
  204. else
  205. ifeq ($(shell which i686-w64-mingw32-c++-posix),)
  206. CXX=i686-w64-mingw32-c++
  207. else
  208. CXX=i686-w64-mingw32-c++-posix
  209. endif
  210. endif
  211. else
  212. CXX=g++
  213. endif
  214.  
  215. CXXFLAGS += -Wextra -Wshadow
  216. LDFLAGS += -static
  217. endif
  218.  
  219. ifeq ($(COMP),icc)
  220. comp=icc
  221. CXX=icpc
  222. CXXFLAGS += -diag-disable 1476,10120 -Wcheck -Wabi -Wdeprecated -strict-ansi
  223. endif
  224.  
  225. ifeq ($(COMP),clang)
  226. comp=clang
  227. CXX=clang++
  228. CXXFLAGS += -pedantic -Wextra -Wshadow -m$(bits)
  229. LDFLAGS += -m$(bits)
  230. ifeq ($(UNAME),Darwin)
  231. CXXFLAGS += -stdlib=libc++
  232. DEPENDFLAGS += -stdlib=libc++
  233. endif
  234. endif
  235.  
  236. ifeq ($(comp),icc)
  237. profile_prepare = icc-profile-prepare
  238. profile_make = icc-profile-make
  239. profile_use = icc-profile-use
  240. profile_clean = icc-profile-clean
  241. else
  242. profile_prepare = gcc-profile-prepare
  243. profile_make = gcc-profile-make
  244. profile_use = gcc-profile-use
  245. profile_clean = gcc-profile-clean
  246. endif
  247.  
  248. ifeq ($(UNAME),Darwin)
  249. CXXFLAGS += -arch $(arch) -mmacosx-version-min=10.9
  250. LDFLAGS += -arch $(arch) -mmacosx-version-min=10.9
  251. endif
  252.  
  253. ### Travis CI script uses COMPILER to overwrite CXX
  254. ifdef COMPILER
  255. COMPCXX=$(COMPILER)
  256. endif
  257.  
  258. ### Allow overwriting CXX from command line
  259. ifdef COMPCXX
  260. CXX=$(COMPCXX)
  261. endif
  262.  
  263. ### On mingw use Windows threads, otherwise POSIX
  264. ifneq ($(comp),mingw)
  265. # On Android Bionic's C library comes with its own pthread implementation bundled in
  266. ifneq ($(arch),armv7)
  267. # Haiku has pthreads in its libroot, so only link it in on other platforms
  268. ifneq ($(UNAME),Haiku)
  269. LDFLAGS += -lpthread
  270. endif
  271. endif
  272. endif
  273.  
  274. ### 3.2 Debugging
  275. ### ==========================================================================
  276. ifeq ($(debug),no)
  277. CXXFLAGS += -DNDEBUG
  278. else
  279. CXXFLAGS += -g
  280. endif
  281.  
  282. ### 3.3 Optimization
  283. ### ==========================================================================
  284. ifeq ($(optimize),yes)
  285. CXXFLAGS += -O3
  286.  
  287. ifeq ($(comp),gcc)
  288. ifeq ($(UNAME),Darwin)
  289. ifeq ($(arch),i386)
  290. CXXFLAGS += -mdynamic-no-pic
  291. endif
  292. ifeq ($(arch),x86_64)
  293. CXXFLAGS += -mdynamic-no-pic
  294. endif
  295. endif
  296.  
  297. ifeq ($(arch),armv7)
  298. CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
  299. endif
  300. endif
  301.  
  302. ifeq ($(arch),native)
  303. CXXFLAGS += -march=native -mtune=native
  304. endif
  305.  
  306. ifeq ($(comp),icc)
  307. ifeq ($(UNAME),Darwin)
  308. CXXFLAGS += -mdynamic-no-pic
  309. endif
  310. endif
  311.  
  312. ifeq ($(comp),clang)
  313. ifeq ($(UNAME),Darwin)
  314. ifeq ($(pext),no)
  315. CXXFLAGS += -flto
  316. LDFLAGS += $(CXXFLAGS)
  317. endif
  318. ifeq ($(arch),i386)
  319. CXXFLAGS += -mdynamic-no-pic
  320. endif
  321. ifeq ($(arch),x86_64)
  322. CXXFLAGS += -mdynamic-no-pic
  323. endif
  324. endif
  325. endif
  326. endif
  327.  
  328. ### 3.4 Bits
  329. ### ==========================================================================
  330. ifeq ($(bits),64)
  331. CXXFLAGS += -DIS_64BIT
  332. endif
  333.  
  334. ### 3.5 prefetch
  335. ### ==========================================================================
  336. ifeq ($(prefetch),yes)
  337. ifeq ($(sse),yes)
  338. CXXFLAGS += -msse
  339. DEPENDFLAGS += -msse
  340. endif
  341. else
  342. CXXFLAGS += -DNO_PREFETCH
  343. endif
  344.  
  345. ### 3.6 popcnt
  346. ### ==========================================================================
  347. ifeq ($(popcnt),yes)
  348. ifeq ($(comp),icc)
  349. CXXFLAGS += -msse3 -DUSE_POPCNT
  350. else
  351. ifeq ($(bits),64)
  352. CXXFLAGS += -msse3 -mpopcnt -DUSE_POPCNT
  353. else
  354. CXXFLAGS += -mpopcnt -DUSE_POPCNT
  355. endif
  356. endif
  357. endif
  358.  
  359. ### 3.7 pext
  360. ### ==========================================================================
  361. ifeq ($(pext),yes)
  362. CXXFLAGS += -DUSE_PEXT
  363. ifeq ($(comp),$(filter $(comp),gcc clang mingw))
  364. CXXFLAGS += -mbmi -mbmi2
  365. endif
  366. endif
  367.  
  368. ### 3.8 Link Time Optimization, it works since gcc 4.5 but not on mingw under Windows.
  369. ### This is a mix of compile and link time options because the lto link phase
  370. ### needs access to the optimization flags.
  371. ### ==========================================================================
  372. ifeq ($(comp),gcc)
  373. ifeq ($(optimize),yes)
  374. ifeq ($(debug),no)
  375. CXXFLAGS += -flto
  376. LDFLAGS += $(CXXFLAGS)
  377. endif
  378. endif
  379. endif
  380.  
  381. ifeq ($(comp),mingw)
  382. ifeq ($(UNAME),Linux)
  383. ifeq ($(optimize),yes)
  384. ifeq ($(debug),no)
  385. CXXFLAGS += -flto
  386. LDFLAGS += $(CXXFLAGS)
  387. endif
  388. endif
  389. endif
  390. endif
  391.  
  392. ### 3.9 Android 5 can only run position independent executables. Note that this
  393. ### breaks Android 4.0 and earlier.
  394. ### ==========================================================================
  395. ifeq ($(arch),armv7)
  396. CXXFLAGS += -fPIE
  397. LDFLAGS += -fPIE -pie
  398. endif
  399.  
  400. ### 3.10 Differentiate c++ and c compiles
  401. ### ==========================================================================
  402. CFLAGS := $(CXXFLAGS)
  403. CXXFLAGS += -fno-rtti -std=c++11
  404.  
  405. ### 4. Public targets
  406. ### ==========================================================================
  407.  
  408. help:
  409. @echo ""
  410. @echo "To compile stockfish, type: "
  411. @echo ""
  412. @echo "make target ARCH=arch [COMP=compiler] [COMPCXX=cxx]"
  413. @echo ""
  414. @echo "Supported targets:"
  415. @echo ""
  416. @echo "build > Standard build"
  417. @echo "profile-build > PGO build"
  418. @echo "strip > Strip executable"
  419. @echo "install > Install executable"
  420. @echo "clean > Clean up"
  421. @echo ""
  422. @echo "Supported archs:"
  423. @echo ""
  424. @echo "x86-64 > x86 64-bit"
  425. @echo "x86-64-modern > x86 64-bit with popcnt support"
  426. @echo "x86-64-bmi2 > x86 64-bit with pext support"
  427. @echo "x86-32 > x86 32-bit with SSE support"
  428. @echo "x86-32-old > x86 32-bit fall back for old hardware"
  429. @echo "ppc-64 > PPC 64-bit"
  430. @echo "ppc-32 > PPC 32-bit"
  431. @echo "armv7 > ARMv7 32-bit"
  432. @echo "general-64 > unspecified 64-bit"
  433. @echo "general-32 > unspecified 32-bit"
  434. @echo ""
  435. @echo "Supported compilers:"
  436. @echo ""
  437. @echo "gcc > Gnu compiler (default)"
  438. @echo "mingw > Gnu compiler with MinGW under Windows"
  439. @echo "clang > LLVM Clang compiler"
  440. @echo "icc > Intel compiler"
  441. @echo ""
  442. @echo "Simple examples. If you don't know what to do, you likely want to run: "
  443. @echo ""
  444. @echo "make build ARCH=x86-64 (This is for 64-bit systems)"
  445. @echo "make build ARCH=x86-32 (This is for 32-bit systems)"
  446. @echo ""
  447. @echo "Advanced examples, for experienced users: "
  448. @echo ""
  449. @echo "make build ARCH=x86-64 COMP=clang"
  450. @echo "make profile-build ARCH=x86-64-modern COMP=gcc COMPCXX=g++-4.8"
  451. @echo ""
  452.  
  453.  
  454. .PHONY: build profile-build
  455. build:
  456. $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
  457. $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
  458.  
  459. profile-build:
  460. $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
  461. @echo ""
  462. @echo "Step 0/4. Preparing for profile build."
  463. $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
  464. @echo ""
  465. @echo "Step 1/4. Building executable for benchmark ..."
  466. $(MAKE) -B ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
  467. @echo ""
  468. @echo "Step 2a/4. Inject Tables and FileSize ..."
  469. ifeq ($(family),ChessBase)
  470. ./InjectTables-H6-ChessBase.exe $(EXE)
  471. else ifeq ($(family)$(VERSION),ChessOKPro)
  472. ./InjectTables-H6-ChessOKPro.exe $(EXE)
  473. else ifeq ($(family)$(VERSION),ChessOKStd)
  474. ./InjectTables-H6-ChessOKPro.exe $(EXE)
  475. else ifeq ($(family),ChessOK)
  476. ./InjectTables-H6-ChessOK.exe $(EXE)
  477. else ifeq ($(VERSION),Pro)
  478. ./InjectTables-H6Pro.exe $(EXE)
  479. else ifeq ($(VERSION),Std)
  480. ./InjectTables-H6Pro.exe $(EXE)
  481. else ifneq ($(VERSION),Dev)
  482. ./InjectTables-H6.exe $(EXE)
  483. endif
  484. ifneq ($(VERSION),Dev)
  485. ./$(EXE) z? >nul 2>aes.dat
  486. ./InjectFileSize-H6.exe $(EXE) aes.dat
  487. endif
  488. @echo "Step 2b/4. Running benchmark for pgo-build ..."
  489. $(PGOBENCH) >nul
  490. @echo ""
  491. @echo "Step 3/4. Building final executable ..."
  492. $(MAKE) -B ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
  493. @echo ""
  494. @echo "Step 4/4. Deleting profile data ..."
  495. $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
  496. $(MAKE) strip
  497.  
  498. strip:
  499. strip $(EXE)
  500.  
  501. install:
  502. -mkdir -p -m 755 $(BINDIR)
  503. -cp $(EXE) $(BINDIR)
  504. -strip $(BINDIR)/$(EXE)
  505.  
  506. clean:
  507. $(RM) $(EXE) $(EXE).exe *.o .depend *.gcda ./syzygy/*.o ./syzygy/*.gcda \
  508. zlib/*.o zlib/*.gcda polarssl/*.o polarssl/*.gcda
  509.  
  510. default:
  511. help
  512.  
  513. ### Section 5. Private targets
  514. ### ==========================================================================
  515.  
  516. all: $(EXE) .depend
  517.  
  518. config-sanity:
  519. @echo ""
  520. @echo "Config:"
  521. @echo "debug: '$(debug)'"
  522. @echo "optimize: '$(optimize)'"
  523. @echo "arch: '$(arch)'"
  524. @echo "bits: '$(bits)'"
  525. @echo "prefetch: '$(prefetch)'"
  526. @echo "popcnt: '$(popcnt)'"
  527. @echo "sse: '$(sse)'"
  528. @echo "pext: '$(pext)'"
  529. @echo ""
  530. @echo "Compiler:"
  531. @echo "CXX: $(CXX)"
  532. @echo "CXXFLAGS: $(CXXFLAGS)"
  533. @echo "LDFLAGS: $(LDFLAGS)"
  534. @echo "CC: $(CC)"
  535. @echo "CFLAGS: $(CFLAGS)"
  536. @echo ""
  537. @echo "Testing config sanity. If this fails, try 'make help' ..."
  538. @echo ""
  539. @test "$(debug)" = "yes" || test "$(debug)" = "no"
  540. @test "$(optimize)" = "yes" || test "$(optimize)" = "no"
  541. @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
  542. test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "armv7" || test "$(arch)" = "native"
  543. @test "$(bits)" = "32" || test "$(bits)" = "64"
  544. @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
  545. @test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
  546. @test "$(sse)" = "yes" || test "$(sse)" = "no"
  547. @test "$(pext)" = "yes" || test "$(pext)" = "no"
  548. @test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw" || test "$(comp)" = "clang"
  549.  
  550. $(EXE): $(OBJS) $(COBJS)
  551. $(CXX) -o $@ $(OBJS) $(COBJS) $(LDFLAGS)
  552.  
  553. $(COBJS): %.o : %.c
  554. $(CC) $(CFLAGS) -c $< -o $@
  555.  
  556. gcc-profile-prepare:
  557. $(MAKE) ARCH=$(ARCH) COMP=$(COMP) gcc-profile-clean
  558.  
  559. gcc-profile-make:
  560. $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
  561. EXTRACXXFLAGS='-fprofile-generate' \
  562. EXTRALDFLAGS='-lgcov' \
  563. all
  564.  
  565. gcc-profile-use:
  566. $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
  567. EXTRACXXFLAGS='-fprofile-use -fno-peel-loops -fno-tracer -fprofile-correction' \
  568. EXTRALDFLAGS='-lgcov -Wl,-Map,h.map' \
  569. all
  570.  
  571. gcc-profile-clean:
  572. @rm -rf *.gcda syzygy/*.gcda zlib/*.gcda polarssl/*.gcda
  573. @rm -rf *.o syzygy/*.o zlib/*.o polarssl/*.o
  574.  
  575. icc-profile-prepare:
  576. $(MAKE) ARCH=$(ARCH) COMP=$(COMP) icc-profile-clean
  577. @mkdir profdir
  578.  
  579. icc-profile-make:
  580. $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
  581. EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
  582. all
  583.  
  584. icc-profile-use:
  585. $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
  586. EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
  587. all
  588.  
  589. icc-profile-clean:
  590. @rm -rf profdir bench.txt
  591.  
  592. .depend:
  593. -@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) $(COBJS:.o=.c) > $@ 2> /dev/null
  594.  
  595. -include .depend
RAW Paste Data