gnu_compiler.conf 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. _STD_CXX=-std=$_STD_CXX_VERSION
  2. _OPTIMIZE_RELEASE=
  3. when ($_BUILD_RELEASE == "yes") {
  4. when ($_BUILD_SIZE_OPTIMIZED == "yes") {
  5. # -Oz is clang's more size-aggressive version of -Os
  6. # For ARM specifically, clang -Oz is on par with gcc -Os:
  7. # https://github.com/android/ndk/issues/133#issuecomment-365763507
  8. when($CLANG == "yes") {
  9. _OPTIMIZE_RELEASE=-Oz
  10. }
  11. otherwise {
  12. _OPTIMIZE_RELEASE=-Os
  13. }
  14. }
  15. otherwise {
  16. _OPTIMIZE_RELEASE=-O3
  17. }
  18. }
  19. _SFDL_FLAGS=-E -C -x c++
  20. when ($CLANG == "yes") {
  21. _SFDL_FLAGS+=-Qunused-arguments
  22. }
  23. _DEBUG_INFO_FLAGS=-g
  24. when ($OS_LINUX == "yes") {
  25. _DEBUG_INFO_FLAGS=-g -ggnu-pubnames
  26. }
  27. _CROSS_SUFFIX=.pic
  28. when ($FORCE_NO_PIC == "yes") {
  29. when ($TOOL_BUILD_MODE == "yes" && $PIC == "yes") {
  30. # FIXME(spreis): This is temporary fix until more appropriate control over pic-like-in-tools mode will come
  31. }
  32. otherwise {
  33. _CROSS_SUFFIX=
  34. }
  35. }
  36. C_COMPILER=${quo:C_COMPILER_UNQUOTED}
  37. OPTIMIZE=$_OPTIMIZE_RELEASE
  38. FSTACK=-fstack-protector
  39. DUMP_DEPS=
  40. GCC_PREPROCESSOR_OPTS=$DUMP_DEPS $C_DEFINES
  41. # PIE is only valid for executables, while PIC implies a shared library
  42. # `-pie` with a shared library is either ignored or fails to link
  43. when ($PIC == "yes") {
  44. CFLAGS+=-fPIC
  45. LDFLAGS+=-fPIC
  46. }
  47. elsewhen ($PIE == "yes") {
  48. CFLAGS+=-fPIE
  49. LDFLAGS+=-fPIE -pie
  50. }
  51. when ($CLANG16 == "yes") {
  52. CFLAGS+=-Wno-array-parameter -Wno-deprecate-lax-vec-conv-all -Wno-unqualified-std-cast-call -Wno-unused-but-set-parameter -Wno-implicit-function-declaration -Wno-int-conversion -Wno-incompatible-function-pointer-types -Wno-address-of-packed-member
  53. }
  54. when ($MSAN_TRACK_ORIGIN == "yes") {
  55. CFLAGS+=-fsanitize-memory-track-origins=2
  56. }
  57. when ($ARCH_XTENSA == "yes") {
  58. FSTACK=
  59. }
  60. when ($OS_EMSCRIPTEN == "yes") {
  61. FSTACK=-fno-stack-protector
  62. CFLAGS+=-D__EMSCRIPTEN__
  63. CFLAGS+=-D_LIBCPP_HAS_MUSL_LIBC
  64. }
  65. CFLAGS+=$_C_FLAGS $DEBUG_INFO_FLAGS $_C_FOPTIONS $C_WARNING_OPTS $GCC_PREPROCESSOR_OPTS $USER_CFLAGS $USER_CFLAGS_GLOBAL
  66. CXXFLAGS+=$CFLAGS $_STD_CXX $CXX_WARNING_OPTS $USER_CXXFLAGS $USER_CXXFLAGS_GLOBAL
  67. CONLYFLAGS+=$USER_CONLYFLAGS $USER_CONLYFLAGS_GLOBAL
  68. CXX_COMPILER=${quo:CXX_COMPILER_UNQUOTED}
  69. NOGCCSTACKCHECK=yes
  70. SFDL_FLAG=$_SFDL_FLAGS -o $SFDL_TMP_OUT
  71. WERROR_FLAG=-Werror
  72. DEBUG_INFO_FLAGS=$_DEBUG_INFO_FLAGS
  73. when ($NO_WSHADOW == "yes") {
  74. C_WARNING_OPTS += -Wno-shadow
  75. }
  76. # Though -w is intended to switch off all the warnings,
  77. # it does not switch at least -Wregister and -Wreserved-user-defined-literal under clang.
  78. #
  79. # Use -Wno-everything to force warning suppression.
  80. when ($NO_COMPILER_WARNINGS == "yes") {
  81. C_WARNING_OPTS = -Wno-everything
  82. CXX_WARNING_OPTS = -Wno-everything
  83. }
  84. when ($NO_OPTIMIZE == "yes") {
  85. OPTIMIZE = -O0
  86. }
  87. when ($SAVE_TEMPS == "yes") {
  88. CXXFLAGS += -save-temps
  89. }
  90. when ($NOGCCSTACKCHECK != "yes") {
  91. FSTACK += -fstack-check
  92. }
  93. when ($FORCE_CONSISTENT_DEBUG == "yes") {
  94. when ($CLANG == "yes") {
  95. CL_DEBUG_INFO=-fdebug-prefix-map=${ARCADIA_BUILD_ROOT}=/-B -fdebug-prefix-map=${ARCADIA_ROOT}=/-S -fdebug-prefix-map=$(TOOL_ROOT)=/-T -Xclang -fdebug-compilation-dir -Xclang /tmp
  96. }
  97. otherwise {
  98. CL_DEBUG_INFO=-fdebug-prefix-map=${ARCADIA_BUILD_ROOT}=/-B -fdebug-prefix-map=${ARCADIA_ROOT}=/-S -fdebug-prefix-map=$(TOOL_ROOT)=/-T
  99. when ($ARCH_XTENSA == "yes") {
  100. CL_DEBUG_INFO=
  101. }
  102. }
  103. YASM_DEBUG_INFO=--replace=${ARCADIA_BUILD_ROOT}=/-B --replace=${ARCADIA_ROOT}=/-S --replace=$(TOOL_ROOT)=/-T ${env:"YASM_TEST_SUITE=1"}
  104. }
  105. elsewhen ($CONSISTENT_DEBUG == "yes") {
  106. when ($CLANG == "yes") {
  107. CL_DEBUG_INFO_DISABLE_CACHE__NO_UID__=-fdebug-prefix-map=${ARCADIA_BUILD_ROOT}=/-B -fdebug-prefix-map=${ARCADIA_ROOT}=/-S -fdebug-prefix-map=$(TOOL_ROOT)=/-T -Xclang -fdebug-compilation-dir -Xclang /tmp
  108. }
  109. otherwise {
  110. CL_DEBUG_INFO_DISABLE_CACHE__NO_UID__=-fdebug-prefix-map=${ARCADIA_BUILD_ROOT}=/-B -fdebug-prefix-map=${ARCADIA_ROOT}=/-S -fdebug-prefix-map=$(TOOL_ROOT)=/-T
  111. when ($ARCH_XTENSA == "yes") {
  112. CL_DEBUG_INFO_DISABLE_CACHE__NO_UID__=
  113. }
  114. }
  115. YASM_DEBUG_INFO_DISABLE_CACHE__NO_UID__=--replace=${ARCADIA_BUILD_ROOT}=/-B --replace=${ARCADIA_ROOT}=/-S --replace=$(TOOL_ROOT)=/-T ${env:"YASM_TEST_SUITE=1"}
  116. }
  117. elsewhen ($CONSISTENT_DEBUG_LIGHT == "yes") {
  118. when ($CLANG == "yes") {
  119. CL_DEBUG_INFO_DISABLE_CACHE__NO_UID__=-fdebug-prefix-map=${ARCADIA_BUILD_ROOT}=/-B -Xclang -fdebug-compilation-dir -Xclang /tmp
  120. }
  121. otherwise {
  122. CL_DEBUG_INFO_DISABLE_CACHE__NO_UID__=-fdebug-prefix-map=${ARCADIA_BUILD_ROOT}=/-B
  123. when ($ARCH_XTENSA == "yes") {
  124. CL_DEBUG_INFO_DISABLE_CACHE__NO_UID__=
  125. }
  126. }
  127. YASM_DEBUG_INFO_DISABLE_CACHE__NO_UID__=--replace=${ARCADIA_BUILD_ROOT}=/-B ${env:"YASM_TEST_SUITE=1"}
  128. }
  129. when ($FORCE_CONSISTENT_BUILD == "yes") {
  130. CL_MACRO_INFO=-Wno-builtin-macro-redefined -D__DATE__=\""Sep 31 2019\"" -D__TIME__=\"00:00:00\" -fmacro-prefix-map=${ARCADIA_BUILD_ROOT}/= -fmacro-prefix-map=${ARCADIA_ROOT}/= -fmacro-prefix-map=$(TOOL_ROOT)/=
  131. }
  132. elsewhen ($CONSISTENT_BUILD == "yes") {
  133. CL_MACRO_INFO_DISABLE_CACHE__NO_UID__=-Wno-builtin-macro-redefined -D__DATE__=\""Sep 31 2019\"" -D__TIME__=\"00:00:00\" -fmacro-prefix-map=${ARCADIA_BUILD_ROOT}/= -fmacro-prefix-map=${ARCADIA_ROOT}/= -fmacro-prefix-map=$(TOOL_ROOT)/=
  134. }
  135. _CFLAGS_ARCH_I386=
  136. when ($ARCH_I386 == "yes" && $ARCH_I686 != "yes") {
  137. _CFLAGS_ARCH_I386=-march=pentiumpro -mtune=pentiumpro
  138. }
  139. CFLAGS+=$_CFLAGS_ARCH_I386
  140. BC_CFLAGS+=$CFLAGS
  141. BC_CXXFLAGS+=$CXXFLAGS
  142. C_DEFINES+=-D__LONG_LONG_SUPPORTED
  143. OBJ_CROSS_SUF=$OBJ_SUF$_CROSS_SUFFIX
  144. OBJECT_SUF=$OBJ_SUF$_CROSS_SUFFIX.o
  145. GCC_COMPILE_FLAGS=$EXTRA_C_FLAGS -c -o $_COMPILE_OUTPUTS ${pre=-I:_C__INCLUDE}
  146. EXTRA_COVERAGE_OUTPUT=${hide;noauto;output;suf=${OBJECT_SUF}.gcno:SRC}
  147. CLANG_TIDY_OUTPUT_FILE=${noauto;output;suf=${OBJECT_SUF}.tidyjson:SRC}
  148. YNDEXER_OUTPUT_FILE=${noauto;output;suf=${OBJECT_SUF}${COMPILE_OUT_SUFFIX}.ydx.pb2:SRC}
  149. when ($DUMP_COMPILER_DEPS == "yes") {
  150. DUMP_DEPS=-MD ${hide;noauto;output;suf=${OBJ_SUF}.o.d:SRC}
  151. }
  152. elsewhen ($DUMP_COMPILER_DEPS_FAST == "yes") {
  153. DUMP_DEPS=-E -M -MF ${noauto;output;suf=${OBJ_SUF}.o.d:SRC}
  154. }
  155. _COMPILER_TIME_TRACE_GRANULARITY=500
  156. when ($TIME_TRACE_GRANULARITY && $TIME_TRACE_GRANULARITY != "") {
  157. _COMPILER_TIME_TRACE_GRANULARITY=$TIME_TRACE_GRANULARITY
  158. }
  159. _COMPILER_TIME_TRACE_FLAGS=
  160. _COMPILER_TIME_TRACE_POSTPROCESS=
  161. when (($TIME_TRACE == "yes" || $COMPILER_TIME_TRACE == "yes") && $_HAS_TIME_TRACE == "yes") {
  162. _COMPILER_TIME_TRACE_FLAGS=-ftime-trace -ftime-trace-granularity=$_COMPILER_TIME_TRACE_GRANULARITY
  163. _COMPILER_TIME_TRACE_POSTPROCESS=$YMAKE_PYTHON ${input:"build/scripts/find_time_trace.py"} $_COMPILE_OUTPUTS $_COMPILE_TIME_TRACE_OUTPUTS
  164. }
  165. _C_CPP_KV_STYLE=${hide;kv:"p CC"} ${hide;kv:"pc green"}
  166. _C_CPP_KV_STYLE_NEW=${hide;kv:_C_CPP_KV_STYLE_P} ${hide;kv:_C_CPP_KV_STYLE_PC}
  167. _C_CPP_KV_STYLE_P=p CC
  168. _C_CPP_KV_STYLE_PC=pc green
  169. _CPP_ARGS=\
  170. $CLANG_STATIC_ANALYZER_OPTIONS && \
  171. $CLANG_TIDY_ARGS \
  172. $YNDEXER_ARGS \
  173. $RETRY_ARGS \
  174. $CXX_COMPILER \
  175. $C_FLAGS_PLATFORM \
  176. $GCC_COMPILE_FLAGS \
  177. $CXXFLAGS \
  178. $CL_MACRO_INFO \
  179. $CL_MACRO_INFO_DISABLE_CACHE__NO_UID__ \
  180. $_COMPILER_TIME_TRACE_FLAGS \
  181. $EXTRA_OUTPUT \
  182. $SRCFLAGS \
  183. $_LANG_CFLAGS_VALUE \
  184. ${input:SRC} \
  185. $TOOLCHAIN_ENV \
  186. $YNDEXER_OUTPUT \
  187. && $_COMPILER_TIME_TRACE_POSTPROCESS \
  188. $_C_CPP_KV_STYLE
  189. _CPP_ARGS_NEW_CMD_0=\
  190. $CLANG_STATIC_ANALYZER_OPTIONS_NEW
  191. _CPP_ARGS_NEW_CMD_1_1=\
  192. $CLANG_TIDY_ARGS \
  193. $YNDEXER_ARGS \
  194. $RETRY_ARGS \
  195. $CXX_COMPILER \
  196. $C_FLAGS_PLATFORM \
  197. $GCC_COMPILE_FLAGS \
  198. $CXXFLAGS \
  199. $CL_MACRO_INFO \
  200. $CL_MACRO_INFO_DISABLE_CACHE__NO_UID__ \
  201. $_COMPILER_TIME_TRACE_FLAGS \
  202. $EXTRA_OUTPUT
  203. _CPP_ARGS_NEW_CMD_1_2=\
  204. $SRCFLAGS \
  205. $_LANG_CFLAGS_VALUE_NEW \
  206. ${input:SRC} \
  207. $TOOLCHAIN_ENV \
  208. $YNDEXER_OUTPUT
  209. _CPP_ARGS_NEW_CMD_2=\
  210. $_COMPILER_TIME_TRACE_POSTPROCESS \
  211. $_C_CPP_KV_STYLE_NEW \
  212. $SCU_NAME_KV_NEW
  213. _C_ARGS=\
  214. $CLANG_TIDY_ARGS \
  215. $YNDEXER_ARGS \
  216. $RETRY_ARGS \
  217. $C_COMPILER \
  218. $C_FLAGS_PLATFORM \
  219. $GCC_COMPILE_FLAGS \
  220. $CFLAGS \
  221. $CL_MACRO_INFO \
  222. $CL_MACRO_INFO_DISABLE_CACHE__NO_UID__ \
  223. $_COMPILER_TIME_TRACE_FLAGS \
  224. $CONLYFLAGS \
  225. $EXTRA_OUTPUT \
  226. $SRCFLAGS \
  227. ${input:SRC} \
  228. $TOOLCHAIN_ENV \
  229. $YNDEXER_OUTPUT \
  230. $_C_CPP_KV_STYLE
  231. _C_ARGS_NEW=\
  232. $CLANG_TIDY_ARGS \
  233. $YNDEXER_ARGS \
  234. $RETRY_ARGS \
  235. $C_COMPILER \
  236. $C_FLAGS_PLATFORM \
  237. $GCC_COMPILE_FLAGS \
  238. $CFLAGS \
  239. $CL_MACRO_INFO \
  240. $CL_MACRO_INFO_DISABLE_CACHE__NO_UID__ \
  241. $_COMPILER_TIME_TRACE_FLAGS \
  242. $CONLYFLAGS \
  243. $EXTRA_OUTPUT \
  244. $SRCFLAGS \
  245. ${input:SRC} \
  246. $TOOLCHAIN_ENV \
  247. $YNDEXER_OUTPUT \
  248. $_C_CPP_KV_STYLE_NEW \
  249. $SCU_NAME_KV_NEW
  250. ### _SRC_C_NODEPS_CMD is obtained from _C_ARGS by filtering the following elements:
  251. ### ${input:SRC}
  252. ### $CL_MACRO_INFO
  253. ### $CL_MACRO_INFO_DISABLE_CACHE__NO_UID__
  254. ### $CLANG_TIDY_ARGS
  255. ### $EXTRA_OUTPUT
  256. ### $EXTRA_COVERAGE_OUTPUT
  257. ### $SRCFLAGS
  258. ### $YNDEXER_ARGS
  259. ### $YNDEXER_OUTPUT
  260. ###
  261. ### $GCC_COMPILE_FLAGS is substituted for $EXTRA_C_FLAGS -c -o ${OUTFILE} ${SRC} ${pre=-I:INC}
  262. _SRC_C_NODEPS_CMD=\
  263. $C_COMPILER \
  264. $C_FLAGS_PLATFORM \
  265. $EXTRA_C_FLAGS -c -o ${OUTFILE} ${SRC} ${pre=-I:INC} \
  266. $CFLAGS \
  267. $CONLYFLAGS \
  268. $TOOLCHAIN_ENV \
  269. $_C_CPP_KV_STYLE
  270. _FORCE_CPP_FLAGS=-x c++
  271. _SRC_CPP_CMD=$_CPP_ARGS
  272. _SRC_CPP_CMD_NEW= $_CPP_ARGS_NEW_CMD_0 && $_CPP_ARGS_NEW_CMD_1_1 $_CPP_ARGS_NEW_CMD_1_2 && $_CPP_ARGS_NEW_CMD_2
  273. _SRC_CPP_CMD_NEW_FORCED=$_CPP_ARGS_NEW_CMD_0 $CLANG_STATIC_ANALYZER_OPTIONS_NEW_FORCED && $_CPP_ARGS_NEW_CMD_1_1 $_FORCE_CPP_FLAGS $_CPP_ARGS_NEW_CMD_1_2 && $_CPP_ARGS_NEW_CMD_2
  274. _SRC_C_CMD=$_C_ARGS
  275. _SRC_C_CMD_NEW=$_C_ARGS_NEW
  276. _SRC_M_CMD=$SRC_c($SRC $SRCFLAGS)
  277. _SRC_MASM_CMD=$_EMPTY_CMD