Advertisement
Tainel

Makefile

Apr 7th, 2023 (edited)
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 3.91 KB | Software | 0 0
  1. # Custom GNU C++20 compiler.
  2. GPP:=g++ -std=gnu++20 -O2 -ftabstop=1 -Werror -DLOCAL
  3.  
  4. # Compilation flags for compile-time diagnostics.
  5. DIAGNOSE:=-Wall -Wextra -Wshadow -Wconversion -Wold-style-cast -Wfloat-equal\
  6. -Walloca -Wvla -Wzero-as-null-pointer-constant -Wlogical-op -Wduplicated-cond\
  7. -Wduplicated-branches -Wredundant-decls -Wredundant-tags -Wmismatched-tags\
  8. -Wctor-dtor-privacy -Wextra-semi -Wundef
  9. # Compilation flags for run-time sanity checks.
  10. SANITIZE:=-g -fno-sanitize-recover=all -fsanitize=undefined\
  11. -fsanitize=float-cast-overflow -fsanitize=float-divide-by-zero\
  12. -fsanitize=address -D_GLIBCXX_SANITIZE_VECTOR -D_GLIBCXX_DEBUG
  13.  
  14. # Command for the creation of new directories.
  15. MKDIR:=mkdir -p --
  16. # Command for the removal of existing directories.
  17. RMDIR:=rm -rf --
  18.  
  19. # Directory of the executables.
  20. BINDIR:=bin/
  21. # Name of the default executable.
  22. BINFILE:=main
  23. # Name of the sanitized executable.
  24. BINFILESAN:=mainsan
  25. # Path to the default executable.
  26. BINPATH:=${BINDIR}${BINFILE}
  27. # Path to the sanitized executable.
  28. BINPATHSAN:=${BINDIR}${BINFILESAN}
  29.  
  30. # Directory of the source code.
  31. SRCDIR:=src/
  32.  
  33. # Main source file extension.
  34. MAINEXT:=.cpp
  35. # Name of the main source file.
  36. MAINFILE:=main${MAINEXT}
  37. # Path to the main source file.
  38. MAINPATH:=${SRCDIR}${MAINFILE}
  39.  
  40. # Header file extension.
  41. HDREXT:=.hpp
  42. # Paths to all header files.
  43. HDRTREE:=$(shell find ${SRCDIR} -name '*${HDREXT}')
  44.  
  45. # Directory of the base header files.
  46. BASEDIR:=${SRCDIR}base/
  47. # Name of the base header index file.
  48. BASEFILE:=index${HDREXT}
  49. # Path to the base header index file.
  50. BASEPATH:=${BASEDIR}${BASEFILE}
  51. # Paths to all base header files.
  52. BASETREE:=$(shell find ${BASEDIR} -name '*${HDREXT}')
  53.  
  54. # Directory of the precompiled headers.
  55. PRECOMPDIR:=${BASEPATH}.gch/
  56. # Name of the default precompiled header.
  57. PRECOMPFILE:=base_precompiled_header
  58. # Name of the sanitized precompiled header.
  59. PRECOMPFILESAN:=base_precompiled_header_sanitized
  60. # Path to the default precompiled header.
  61. PRECOMPPATH:=${PRECOMPDIR}${PRECOMPFILE}
  62. # Path to the sanitized precompiled header.
  63. PRECOMPPATHSAN:=${PRECOMPDIR}${PRECOMPFILESAN}
  64.  
  65. # Precompile the base headers with compile-time diagnostics, build the default
  66. # executable, and run it. This is the default target.
  67. .PHONY:all
  68. all:prepare build run
  69.  
  70. # Precompile the base headers with both compile-time diagnostics and run-time
  71. # sanity checks, build the sanitized executable, and run it.
  72. .PHONY:allsan san
  73. allsan san:preparesan buildsan runsan
  74.  
  75. # Precompile the base headers for the default executable.
  76. .PHONY:prepare
  77. prepare:${PRECOMPPATH}
  78.  
  79. # Precompile the base headers for the sanitized executable.
  80. .PHONY:preparesan
  81. preparesan:${PRECOMPPATHSAN}
  82.  
  83. # Build the default executable.
  84. .PHONY:build
  85. build:${BINPATH}
  86.  
  87. # Build the sanitized executable.
  88. .PHONY:buildsan
  89. buildsan:${BINPATHSAN}
  90.  
  91. # Run the default executable.
  92. .PHONY:run
  93. ifeq (,$(wildcard ${BINPATH}))
  94. run:${BINPATH}
  95. else
  96. run:
  97. endif
  98.     @${BINPATH}
  99.  
  100. # Run the sanitized executable.
  101. .PHONY:runsan
  102. ifeq (,$(wildcard ${BINPATHSAN}))
  103. runsan:${BINPATHSAN}
  104. else
  105. runsan:
  106. endif
  107.     @${BINPATHSAN}
  108.  
  109. # Delete all existing executables and precompiled headers.
  110. .PHONY:clean
  111. clean:
  112.     @${RMDIR} ${BINDIR} ${PRECOMPDIR}
  113.  
  114. # Run the precompilation of the base headers for the default executable.
  115. ${PRECOMPPATH}:${BASETREE}
  116.     @${MKDIR} ${PRECOMPDIR}
  117.     @${GPP} ${DIAGNOSE} -iquote${SRCDIR} ${BASEPATH} -o $@
  118.  
  119. # Run the precompilation of the base headers for the sanitized executable.
  120. ${PRECOMPPATHSAN}:${BASETREE}
  121.     @${MKDIR} ${PRECOMPDIR}
  122.     @${GPP} ${DIAGNOSE} ${SANITIZE} -iquote${SRCDIR} ${BASEPATH} -o $@
  123.  
  124. # Run the compilation of the default executable.
  125. ${BINPATH}:${MAINPATH} ${HDRTREE}
  126.     @${MKDIR} ${BINDIR}
  127.     @${GPP} ${DIAGNOSE} -iquote${SRCDIR} $< -o $@
  128.  
  129. # Run the compilation of the sanitized executable.
  130. ${BINPATHSAN}:${MAINPATH} ${HDRTREE}
  131.     @${MKDIR} ${BINDIR}
  132.     @${GPP} ${DIAGNOSE} ${SANITIZE} -iquote${SRCDIR} $< -o $@
  133.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement