gnu_compiler.conf 8.2 KB

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