Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

610 lines
24 KiB

  1. #
  2. # Base makefile for Linux.
  3. #
  4. # !!!!! Note to future editors !!!!!
  5. #
  6. # before you make changes, make sure you grok:
  7. # 1. the difference between =, :=, +=, and ?=
  8. # 2. how and when this base makefile gets included in the generated makefile(s)
  9. # ( see http://www.gnu.org/software/make/manual/make.html#Flavors )
  10. #
  11. # Command line prefixes:
  12. # - errors are ignored
  13. # @ command is not printed to stdout before being executed
  14. # + command is executed even if Make is invoked in "do not exec" mode
  15. ifneq "$(LINUX_TOOLS_PATH)" ""
  16. TOOL_PATH = $(LINUX_TOOLS_PATH)/
  17. endif
  18. # Allow redirection to an arbitrary location for the tools we use.
  19. # This helps with cross-compilation by not requiring Linux tools
  20. # to be on the path and possibly overriding Windows tools.
  21. CP = $(TOOL_PATH)cp
  22. CUT = $(TOOL_PATH)cut
  23. DIRNAME = $(TOOL_PATH)dirname
  24. ECHO = $(TOOL_PATH)echo
  25. FGREP = $(TOOL_PATH)fgrep
  26. FIND = $(TOOL_PATH)find
  27. GREP = $(TOOL_PATH)grep
  28. MKDIR = $(TOOL_PATH)mkdir
  29. RM = $(TOOL_PATH)rm
  30. TAIL = $(TOOL_PATH)tail
  31. SHELL = $(TOOL_PATH)bash
  32. OS := $($(SHELL) $(TOOL_PATH)uname)
  33. HOSTNAME := $($(SHELL) $(TOOL_PATH)hostname)
  34. -include $(SRCROOT)/devtools/steam_def.mak
  35. -include $(SRCROOT)/devtools/sourcesdk_def.mak
  36. # To build with clang, set the following in your environment:
  37. # CC = clang
  38. # CXX = clang++
  39. ifneq (,$(findstring clang,$(CXX)))
  40. CLANG_BUILD = 1
  41. endif
  42. ifeq ($(OS),Darwin)
  43. $(error This file should never be used for Mac - use base.xconfig)
  44. endif
  45. # Optimization flags specific to compiler/CFG combination
  46. ifeq ($(CFG), release)
  47. # With gcc 4.6.3, engine.so went from 7,383,765 to 8,429,109 when building with -O3.
  48. # There also was no speed difference running at 1280x1024. May 2012, mikesart.
  49. # tonyp: The size increase was likely caused by -finline-functions and -fipa-cp-clone getting switched on with -O3.
  50. # -fno-omit-frame-pointer: need this for stack traces with perf.
  51. OptimizerLevel_CompilerSpecific = -O2 -fno-strict-aliasing -ffast-math -fno-omit-frame-pointer -ftree-vectorize
  52. ifeq ($(CLANG_BUILD),1)
  53. OptimizerLevel_CompilerSpecific += -funswitch-loops
  54. else
  55. OptimizerLevel_CompilerSpecific += -fpredictive-commoning -funswitch-loops
  56. endif
  57. else
  58. OptimizerLevel_CompilerSpecific = -O0
  59. #-O1 -finline-functions
  60. endif
  61. # When we move to a modern toolchain, this will be necessary for early testing
  62. # until we can ensure that every user has libraries built against the new C++11
  63. # ABI. Further reading here:
  64. # https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html
  65. DEFINES += -D_GLIBCXX_USE_CXX11_ABI=0
  66. # CPPFLAGS == "c/c++ *preprocessor* flags" - not "cee-plus-plus flags"
  67. ARCH_FLAGS =
  68. BUILDING_MULTI_ARCH = 0
  69. # Preserve cflags set in environment
  70. ENV_CFLAGS := $(CFLAGS)
  71. ENV_CXXFLAGS := $(CXXFLAGS)
  72. CPPFLAGS = $(DEFINES) $(addprefix -I, $(abspath $(INCLUDEDIRS) ))
  73. BASE_CFLAGS = $(ARCH_FLAGS) $(CPPFLAGS) $(WARN_FLAGS) -fvisibility=$(SymbolVisibility) $(OptimizerLevel) -pipe $(GCC_ExtraCompilerFlags) -Usprintf -Ustrncpy -UPROTECTED_THINGS_ENABLE
  74. BASE_CXXFLAGS = -std=c++11
  75. # Additional CXXFLAGS when compiling PCH files
  76. PCH_CXXFLAGS =
  77. # Compiler specific flags
  78. ifeq ($(CLANG_BUILD),1)
  79. # The template depth for C++11 should be 1024, but compilers differ greatly. We go beyond 256 in at least one
  80. # spot, so turn it up to 900 which is GCC's default as of this writing
  81. BASE_CXXFLAGS += -ftemplate-depth=900
  82. # Needed for older versions of clang (newer versions are compatible with gcc syntax)
  83. PCH_CXXFLAGS += -emit-pch
  84. else
  85. # GCC specific - better PCH behavior w/ccache and better debugging information
  86. BASE_CFLAGS += -fpch-preprocess -fvar-tracking-assignments
  87. endif
  88. DEFINES += -DVPROF_LEVEL=1 -DGNUC -DNO_HOOK_MALLOC
  89. ## TODO: This cases build errors in cstrike/bin right now. Need to debug.
  90. # This causes all filesystem interfaces to default to their 64bit versions on
  91. # 32bit systems, which means we don't break on filesystems with inodes > 32bit.
  92. # DEFINES += -D_FILE_OFFSET_BITS=64
  93. # Final CFLAGS/CXXFLAGS
  94. CFLAGS = $(BASE_CFLAGS) $(ENV_CFLAGS)
  95. CXXFLAGS = $(BASE_CFLAGS) $(BASE_CXXFLAGS) $(ENV_CXXFLAGS)
  96. LDFLAGS = $(CFLAGS) $(GCC_ExtraLinkerFlags) $(OptimizerLevel)
  97. GENDEP_CXXFLAGS = -MMD -MP -MF $(patsubst %.gch,%.P,$(@:.o=.P)) -MT $@
  98. MAP_FLAGS =
  99. Srv_GAMEOUTPUTFILE =
  100. COPY_DLL_TO_SRV = 0
  101. # We should always specify -Wl,--build-id, as documented at:
  102. # http://linux.die.net/man/1/ld and http://fedoraproject.org/wiki/Releases/FeatureBuildId.http://fedoraproject.org/wiki/Releases/FeatureBuildId
  103. LDFLAGS += -Wl,--build-id
  104. #
  105. # If we should be running in a chroot, check to see if we are. If not, then prefix everything with the
  106. # required chroot
  107. #
  108. ifdef MAKE_CHROOT
  109. export STEAM_RUNTIME_PATH := /usr
  110. ifneq ("$(SCHROOT_CHROOT_NAME)", "$(CHROOT_NAME)")
  111. $(info '$(SCHROOT_CHROOT_NAME)' is not '$(CHROOT_NAME)')
  112. $(error This makefile should be run from within a chroot. 'schroot --chroot $(CHROOT_NAME) -- $(MAKE) $(MAKEFLAGS)')
  113. endif
  114. GCC_VER = -4.8
  115. P4BIN = $(SRCROOT)/devtools/bin/linux/p4
  116. CRYPTOPPDIR=ubuntu12_32_gcc48
  117. else ifeq ($(USE_VALVE_BINDIR),1)
  118. # Using /valve/bin directory.
  119. export STEAM_RUNTIME_PATH ?= /valve
  120. GCC_VER = -4.6
  121. P4BIN = p4
  122. CRYPTOPPDIR=linux32
  123. else
  124. # Not using chroot, use old steam-runtime. (gcc 4.6.3)
  125. export STEAM_RUNTIME_PATH ?= /valve/steam-runtime
  126. GCC_VER =
  127. P4BIN = p4
  128. CRYPTOPPDIR=ubuntu12_32
  129. endif
  130. ifeq ($(TARGET_PLATFORM),linux64)
  131. MARCH_TARGET = core2
  132. else
  133. MARCH_TARGET = pentium4
  134. endif
  135. ifeq ($(USE_VALVE_BINDIR),1)
  136. # On dedicated servers, some plugins depend on global variable symbols in addition to functions.
  137. # So symbols like _Z16ClearMultiDamagev should show up when you do "nm server_srv.so" in TF2.
  138. STRIP_FLAGS =
  139. else
  140. # Linux desktop client (or client/dedicated server in chroot).
  141. STRIP_FLAGS = -x
  142. endif
  143. ifeq ($(CLANG_BUILD),1)
  144. # Clang does not support -mfpmath=sse because it uses whatever
  145. # instruction set extensions are available by default.
  146. SSE_GEN_FLAGS = -msse2
  147. else
  148. SSE_GEN_FLAGS = -msse2 -mfpmath=sse
  149. endif
  150. CCACHE := $(SRCROOT)/devtools/bin/linux/ccache
  151. # - pch_defines,time_macros,file_macro needed for precompiled headers to be beneficial. See additional ".defines" wrapper
  152. # for PCH below to prevent this from biting us (in theory)
  153. # - include_file_ctime/mtime causes re-generated but identical headers, like protobuf, to cause a cache miss. I couldn't
  154. # find the justification for this setting being on by default, perhaps to not waste time preprocessing the files?
  155. # Let's find out the painful way.
  156. export CCACHE_SLOPPINESS := $(CCACHE_SLOPPINESS),time_macros,file_macro,include_file_ctime,include_file_mtime,pch_defines
  157. # Needed for clang to take advantage of PCH, we include the PCH in the
  158. # source files and clang doesn't support -fpch-preprocess properly
  159. ifeq ($(CLANG_BUILD),1)
  160. export CCACHE_CPP2 = 1
  161. endif
  162. # If not specified by environment, use steam runtime compilers + in-tree ccache
  163. ifneq ($(filter default undefined,$(origin AR)),)
  164. AR = $(STEAM_RUNTIME_PATH)/bin/ar crs
  165. endif
  166. ifneq ($(filter default undefined,$(origin CC)),)
  167. CC = $(CCACHE) $(STEAM_RUNTIME_PATH)/bin/gcc$(GCC_VER)
  168. endif
  169. ifneq ($(filter default undefined,$(origin CXX)),)
  170. CXX = $(CCACHE) $(STEAM_RUNTIME_PATH)/bin/g++$(GCC_VER)
  171. endif
  172. LINK ?= $(CC)
  173. ifeq ($(STEAM_BRANCH),1)
  174. WARN_FLAGS = -Wall -Wextra -Wshadow -Wno-invalid-offsetof
  175. else
  176. WARN_FLAGS = -Wall -Wno-invalid-offsetof -Wno-multichar -Wno-overloaded-virtual
  177. WARN_FLAGS += -Wno-write-strings
  178. WARN_FLAGS += -Wno-unused-variable
  179. WARN_FLAGS += -Wno-unused-function
  180. # Additional warnings to -Wall
  181. WARN_FLAGS += -Winvalid-pch -Wswitch
  182. endif
  183. ifeq ($(CLANG_BUILD),1)
  184. # Clang specific flags
  185. WARN_FLAGS += -Wno-unused-const-variable -Wno-unused-local-typedef
  186. else ifeq ($(GCC_VER),-4.8)
  187. WARN_FLAGS += -Wno-unused-result
  188. WARN_FLAGS += -Wno-unused-but-set-variable
  189. # WARN_FLAGS += -Wno-unused-function
  190. endif
  191. WARN_FLAGS += -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-value
  192. WARN_FLAGS += -Wno-invalid-offsetof -Wno-float-equal -Wno-reorder -Werror=return-type
  193. WARN_FLAGS += -fdiagnostics-show-option -Wformat -Wformat-security
  194. ifeq ($(TARGET_PLATFORM),linux64)
  195. # nocona = pentium4 + 64bit + MMX, SSE, SSE2, SSE3 - no SSSE3 (that's three s's - added in core2)
  196. ARCH_FLAGS += -march=$(MARCH_TARGET) -mtune=core2
  197. LD_SO = ld-linux-x86_64.so.2
  198. LIBSTDCXX := $(shell $(CXX) -print-file-name=libstdc++.a)
  199. LIBSTDCXXPIC := $(shell $(CXX) -print-file-name=libstdc++-pic.a)
  200. else
  201. # pentium4 = MMX, SSE, SSE2 - no SSE3 (added in prescott) # -msse3 -mfpmath=sse
  202. ARCH_FLAGS += -m32 -march=$(MARCH_TARGET) -mtune=core2 $(SSE_GEN_FLAGS)
  203. LD_SO = ld-linux.so.2
  204. LIBSTDCXX := $(shell $(CXX) $(ARCH_FLAGS) -print-file-name=libstdc++.so)
  205. LIBSTDCXXPIC := $(shell $(CXX) $(ARCH_FLAGS) -print-file-name=libstdc++.so)
  206. LDFLAGS += -m32
  207. endif
  208. GEN_SYM ?= $(SRCROOT)/devtools/gendbg.sh
  209. ifeq ($(CFG),release)
  210. STRIP ?= strip $(STRIP_FLAGS) -S
  211. # CFLAGS += -ffunction-sections -fdata-sections
  212. # LDFLAGS += -Wl,--gc-sections -Wl,--print-gc-sections
  213. else
  214. STRIP ?= true
  215. endif
  216. VSIGN ?= true
  217. ifeq ($(SOURCE_SDK), 1)
  218. Srv_GAMEOUTPUTFILE := $(GAMEOUTPUTFILE:.so=_srv.so)
  219. COPY_DLL_TO_SRV := 1
  220. endif
  221. LINK_MAP_FLAGS = -Wl,-Map,$(@:.so=).map
  222. SHLIBLDFLAGS = -shared $(LDFLAGS) -Wl,--no-undefined
  223. _WRAP := -Xlinker --wrap=
  224. PATHWRAP = $(_WRAP)fopen $(_WRAP)freopen $(_WRAP)open $(_WRAP)creat $(_WRAP)access $(_WRAP)__xstat \
  225. $(_WRAP)stat $(_WRAP)lstat $(_WRAP)fopen64 $(_WRAP)open64 $(_WRAP)opendir $(_WRAP)__lxstat \
  226. $(_WRAP)chmod $(_WRAP)chown $(_WRAP)lchown $(_WRAP)symlink $(_WRAP)link $(_WRAP)__lxstat64 \
  227. $(_WRAP)mknod $(_WRAP)utimes $(_WRAP)unlink $(_WRAP)rename $(_WRAP)utime $(_WRAP)__xstat64 \
  228. $(_WRAP)mount $(_WRAP)mkfifo $(_WRAP)mkdir $(_WRAP)rmdir $(_WRAP)scandir $(_WRAP)realpath
  229. ifeq "$(BufferSecurityCheck)" "No"
  230. CFLAGS += -fno-stack-protector
  231. else
  232. ifeq ($(shell $(CC) -fstack-protector-strong -xc -c /dev/null -o /dev/null 2>/dev/null && echo yes || echo no),yes)
  233. # Newer GCC versions have a better stack protector available
  234. # http://lwn.net/Articles/584225/
  235. STACK_PROTECTOR := -fstack-protector-strong
  236. else
  237. STACK_PROTECTOR := -fstack-protector
  238. endif
  239. CFLAGS += $(STACK_PROTECTOR)
  240. endif
  241. LIB_START_EXE = $(PATHWRAP) -static-libgcc -Wl,--start-group
  242. LIB_END_EXE = -Wl,--end-group -lm -ldl $(LIBSTDCXX) -lpthread
  243. LIB_START_SHLIB = $(PATHWRAP) -static-libgcc -Wl,--start-group
  244. LIB_END_SHLIB = -Wl,--end-group -lm -ldl $(LIBSTDCXXPIC) -lpthread -l:$(LD_SO) -Wl,--version-script=$(SRCROOT)/devtools/version_script.linux.txt
  245. #
  246. # Profile-directed optimizations.
  247. # Note: Last time these were tested 3/5/08, it actually slowed down the server benchmark by 5%!
  248. #
  249. # First, uncomment these, build, and test. It will generate .gcda and .gcno files where the .o files are.
  250. # PROFILE_LINKER_FLAG=-fprofile-arcs
  251. # PROFILE_COMPILER_FLAG=-fprofile-arcs
  252. #
  253. # Then, comment the above flags out again and rebuild with this flag uncommented:
  254. # PROFILE_COMPILER_FLAG=-fprofile-use
  255. #
  256. #############################################################################
  257. # The compiler command lne for each src code file to compile
  258. #############################################################################
  259. OBJ_DIR = ./obj_$(NAME)_$(TARGET_PLATFORM)$(TARGET_PLATFORM_EXT)/$(CFG)
  260. CPP_TO_OBJ = $(CPPFILES:.cpp=.o)
  261. CXX_TO_OBJ = $(CPP_TO_OBJ:.cxx=.o)
  262. CC_TO_OBJ = $(CXX_TO_OBJ:.cc=.o)
  263. MM_TO_OBJ = $(CC_TO_OBJ:.mm=.o)
  264. C_TO_OBJ = $(MM_TO_OBJ:.c=.o)
  265. OBJS = $(addprefix $(OBJ_DIR)/, $(notdir $(C_TO_OBJ)))
  266. ifeq ($(MAKE_VERBOSE),1)
  267. QUIET_PREFIX =
  268. QUIET_ECHO_POSTFIX =
  269. else
  270. QUIET_PREFIX = @
  271. QUIET_ECHO_POSTFIX = > /dev/null
  272. endif
  273. ifeq ($(MAKE_CC_VERBOSE),1)
  274. CC += -v
  275. endif
  276. ifeq ($(CONFTYPE),lib)
  277. LIB_File = $(OUTPUTFILE)
  278. endif
  279. ifeq ($(CONFTYPE),dll)
  280. SO_File = $(OUTPUTFILE)
  281. endif
  282. ifeq ($(CONFTYPE),exe)
  283. EXE_File = $(OUTPUTFILE)
  284. endif
  285. # we generate dependencies as a side-effect of compilation now
  286. GEN_DEP_FILE=
  287. PRE_COMPILE_FILE =
  288. POST_COMPILE_FILE =
  289. ifeq ($(CLANG_BUILD),1)
  290. # https://bugzilla.samba.org/show_bug.cgi?id=11251
  291. # ccache bug 11251: Clang PCH files always have the timestamps of their deps baked in, so if
  292. # make thinks a file needs to be rebuilt, ccache pulling an older one from cache will cause
  293. # an error.
  294. # Unfortunately, this means any touching of headers in PCH files will cause it to be rebuilt
  295. # and all files using that PCH to cache-miss.
  296. # One specific case we could fix is otherwise-no-op *clean* builds missing the cache: We
  297. # could use a similar trick to the the CCACHE_EXTRAFILES hack used below to bake timestamps
  298. # into the PCH, so that at least clean builds could pull a PCH from cache.
  299. PCH_CXX = CCACHE_DISABLE=1 $(CXX)
  300. # Newer clang supports the -include $PCH_FILE syntax for finding the associated GCH, but for compatibility with
  301. # older versions we'll use the more explicit -include-pch option
  302. INCLUDE_PCH_FILE = -include-pch $(TARGET_PCH_FILE).gch
  303. else
  304. PCH_CXX = $(CXX)
  305. INCLUDE_PCH_FILE = -include $(abspath $(TARGET_PCH_FILE))
  306. endif
  307. ifeq ($(BUILDING_MULTI_ARCH),1)
  308. SINGLE_ARCH_CXXFLAGS=$(subst -arch x86_64,,$(CXXFLAGS))
  309. _MULTI_ARCH_FIRST_FILE = \
  310. mkdir -p $(OBJ_DIR) && \
  311. $(CXX) $(SINGLE_ARCH_CXXFLAGS) $(GENDEP_CXXFLAGS) -o $@ -c $<
  312. _MULTI_ARCH_SECOND_FILE = $(CXX) $(CXXFLAGS) -o $@ -c $<
  313. COMPILE_FILE = $(QUIET_PREFIX) \
  314. echo "--M- $(lastword $(subst /, ,$<)) ----";\
  315. $(_MULTI_ARCH_FIRST_FILE) $(_MULTI_ARCH_SECOND_FILE)
  316. COMPILE_FILE_WITH_PCH = \
  317. $(QUIET_PREFIX) \
  318. echo "-PM- $(lastword $(subst /, ,$<)) ----";\
  319. $(COMPILE_MULTI_ARCH_FIRST_FILE) $(INCLUDE_PCH_FILE) \
  320. $(COMPILE_MULTI_ARCH_SECOND_FILE) $(INCLUDE_PCH_FILE)
  321. # Compile for PCH - the VPC code handles the deps for these
  322. # (See EXTRAFILES note below in non-multiarch compile)
  323. PCH_FINAL_CXXFLAGS = $(filter-out -gsplit-dwarf,$(SINGLE_ARCH_CXXFLAGS) $(GENDEP_CXXFLAGS) $(PCH_CXXFLAGS))
  324. PCH_FINAL_CXXFLAGS_MULTI = $(filter-out -gsplit-dwarf,$(CXXFLAGS) $(PCH_CXXFLAGS))
  325. COMPILE_PCH = \
  326. $(QUIET_PREFIX) \
  327. echo "-M-- $(lastword $(subst /, ,$<)) [PCH] ----";\
  328. mkdir -p $(OBJ_DIR) && \
  329. $(CXX) -x c++-header -E -dM -o $@.defines -c $< && \
  330. CCACHE_EXTRAFILES=$@.defines $(PCH_CXX) $(PCH_FINAL_CXXFLAGS) -x c++-header -o $@ -c $< && \
  331. $(CXX) $(CXXFLAGS) $(PCH_CXXFLAGS) -x c++-header -E -dM -o $@.defines -c $< && \
  332. CCACHE_EXTRAFILES=$@.defines $(PCH_CXX) $(PCH_FINAL_CXXFLAGS_MULTI) -x c++-header -o $@ -c $<
  333. else
  334. COMPILE_FILE_BASE = \
  335. mkdir -p $(OBJ_DIR) && \
  336. $(CXX) $(CXXFLAGS) $(GENDEP_CXXFLAGS) -o $@ -c $<
  337. COMPILE_FILE = \
  338. $(QUIET_PREFIX) echo "---- $(lastword $(subst /, ,$<)) ----"; \
  339. $(COMPILE_FILE_BASE)
  340. COMPILE_FILE_WITH_PCH = \
  341. $(QUIET_PREFIX) \
  342. echo "-P-- $(lastword $(subst /, ,$<)) ----"; \
  343. $(COMPILE_FILE_BASE) $(INCLUDE_PCH_FILE)
  344. # Compile for PCH - the VPC code handles the deps for these.
  345. #
  346. # Because we set CCACHE_SLOPPINESS=pch_defines (or ccache would recompile it every time), we'll miss define-only
  347. # changes in dep files. As a dirty workaround, when we compile a PCH file, first run with
  348. # { -E -dM -o [email protected] } to build a file that represents all of the defines in that file, then pass that
  349. # .defines to CCACHE_EXTRAFILES for the real compile.
  350. #
  351. # This allows ccache to properly re-compile when defines change, so we can still cache PCH files (except for
  352. # clang, see PCH_CXX definition above). This is a huge compile speedup for clean builds and other changes that
  353. # don't affect the preprocessed result of the PCH.
  354. #
  355. # Adding to the fun things-that-break-ccache list, -gsplit-dwarf on PCH compiles -> 100% miss rate (and thus
  356. # 100% miss on all files using it
  357. PCH_FINAL_CXXFLAGS = $(filter-out -gsplit-dwarf,$(CXXFLAGS) $(GENDEP_CXXFLAGS) $(PCH_CXXFLAGS))
  358. COMPILE_PCH = \
  359. $(QUIET_PREFIX) echo "---- $(lastword $(subst /, ,$<)) [PCH] ----";\
  360. mkdir -p $(OBJ_DIR) && \
  361. $(PCH_CXX) $(PCH_FINAL_CXXFLAGS) -x c++-header -E -dM -o $@.defines $< && \
  362. CCACHE_EXTRAFILES=$@.defines $(PCH_CXX) $(PCH_FINAL_CXXFLAGS) -x c++-header -o $@ -c $<
  363. endif
  364. ifneq "$(origin VALVE_NO_AUTO_P4)" "undefined"
  365. P4_EDIT_START = chmod -R +w
  366. P4_EDIT_END = || true
  367. P4_REVERT_START = true
  368. P4_REVERT_END =
  369. else
  370. # You can use an environment variable to specify what changelist to check the Linux Binaries out into. Normally the default
  371. # setting is best, but here is an alternate example:
  372. # export P4_EDIT_CHANGELIST_CMD="echo 1424335"
  373. # ?= means that if P4_EDIT_CHANGELIST_CMD is already set it won't be changed.
  374. P4_EDIT_CHANGELIST_CMD ?= $(P4BIN) changes -c `$(P4BIN) client -o | grep ^Client | cut -f 2` -s pending | fgrep 'POSIX Auto Checkout' | cut -d' ' -f 2 | tail -n 1
  375. ifndef P4_EDIT_CHANGELIST
  376. P4_EDIT_CHANGELIST := $(shell $(P4_EDIT_CHANGELIST_CMD))
  377. endif
  378. ifeq ($(P4_EDIT_CHANGELIST),)
  379. # If we haven't found a changelist to check out to then create one. The name must match the one from a few
  380. # lines above or else a new changelist will be created each time.
  381. # Warning: the behavior of 'echo' is not consistent. In bash you need the "-e" option in order for \n to be
  382. # interpreted as a line-feed, but in dash you do not, and if "-e" is passed along then it is printed, which
  383. # confuses p4. So, if you run this command from the bash shell don't forget to add "-e" to the echo command.
  384. P4_EDIT_CHANGELIST = $(shell /bin/echo -e "Change: new\nDescription: POSIX Auto Checkout" | $(P4BIN) change -i | cut -f 2 -d ' ')
  385. endif
  386. P4_EDIT_START := for f in
  387. P4_EDIT_END := ; do if [ -n $$f ]; then if [ -d $$f ]; then find $$f -type f -print | $(P4BIN) -x - edit -c $(P4_EDIT_CHANGELIST); else $(P4BIN) edit -c $(P4_EDIT_CHANGELIST) $$f; fi; fi; done $(QUIET_ECHO_POSTFIX)
  388. P4_REVERT_START := for f in
  389. P4_REVERT_END := ; do if [ -n $$f ]; then if [ -d $$f ]; then find $$f -type f -print | $(P4BIN) -x - revert; else $(P4BIN) revert $$f; fi; fi; done $(QUIET_ECHO_POSTFIX)
  390. endif
  391. ifneq "$(GAMEOUTPUTFILE)" ""
  392. all: $(OTHER_DEPENDENCIES) $(OBJS) $(GAMEOUTPUTFILE)
  393. @echo $(GAMEOUTPUTFILE) $(QUIET_ECHO_POSTFIX)
  394. else
  395. all: $(OTHER_DEPENDENCIES) $(OBJS) $(OUTPUTFILE)
  396. @echo $(OUTPUTFILE) $(QUIET_ECHO_POSTFIX)
  397. endif
  398. .PHONY: clean cleantargets cleanandremove rebuild relink RemoveOutputFile SingleFile
  399. rebuild :
  400. $(MAKE) -f $(firstword $(MAKEFILE_LIST)) cleanandremove
  401. $(MAKE) -f $(firstword $(MAKEFILE_LIST))
  402. # Use the relink target to force to relink the project.
  403. relink: RemoveOutputFile all
  404. RemoveOutputFile:
  405. rm -f $(OUTPUTFILE)
  406. # This rule is so you can say "make SingleFile SingleFilename=/home/myname/valve_main/src/engine/language.cpp" and have it only build that file.
  407. # It basically just translates the full filename to create a dependency on the appropriate .o file so it'll build that.
  408. SingleFile : RemoveSingleFile $(OBJ_DIR)/$(basename $(notdir $(SingleFilename))).o
  409. @echo ""
  410. RemoveSingleFile:
  411. $(QUIET_PREFIX) rm -f $(OBJ_DIR)/$(basename $(notdir $(SingleFilename))).o
  412. clean:
  413. ifneq "$(OBJ_DIR)" ""
  414. $(QUIET_PREFIX) echo "rm -rf $(OBJ_DIR)"
  415. $(QUIET_PREFIX) rm -rf $(OBJ_DIR)
  416. endif
  417. ifneq "$(OUTPUTFILE)" ""
  418. $(QUIET_PREFIX) if [ -e $(OUTPUTFILE) ]; then \
  419. echo "$(P4BIN) revert $(OUTPUTFILE)"; \
  420. $(P4_REVERT_START) $(OUTPUTFILE) $(OUTPUTFILE)$(SYM_EXT) $(P4_REVERT_END); \
  421. fi;
  422. endif
  423. ifneq "$(OTHER_DEPENDENCIES)" ""
  424. $(QUIET_PREFIX) echo "rm -f $(OTHER_DEPENDENCIES)"
  425. $(QUIET_PREFIX) rm -f $(OTHER_DEPENDENCIES)
  426. endif
  427. ifneq "$(GAMEOUTPUTFILE)" ""
  428. $(QUIET_PREFIX) echo "$(P4BIN) revert $(GAMEOUTPUTFILE)"
  429. $(QUIET_PREFIX) $(P4_REVERT_START) $(GAMEOUTPUTFILE) $(GAMEOUTPUTFILE)$(SYM_EXT) $(P4_REVERT_END)
  430. endif
  431. # Do the above cleaning, except with p4 edit and rm. Reason being ar crs adds and replaces obj files to the
  432. # archive. However if you've renamed or deleted a source file, $(AR) won't remove it. This can leave
  433. # us with archive files that have extra unused symbols, and also potentially cause compilation errors
  434. # when you rename a file and have many duplicate symbols.
  435. cleanandremove:
  436. ifneq "$(OBJ_DIR)" ""
  437. $(QUIET_PREFIX) echo "rm -rf $(OBJ_DIR)"
  438. $(QUIET_PREFIX) -rm -rf $(OBJ_DIR)
  439. endif
  440. ifneq "$(OUTPUTFILE)" ""
  441. $(QUIET_PREFIX) if [ -e $(OUTPUTFILE) ]; then \
  442. echo "$(P4BIN) edit and rm -f $(OUTPUTFILE) $(OUTPUTFILE)$(SYM_EXT)"; \
  443. $(P4_EDIT_START) $(OUTPUTFILE) $(OUTPUTFILE)$(SYM_EXT) $(P4_EDIT_END); \
  444. fi;
  445. $(QUIET_PREFIX) -rm -f $(OUTPUTFILE) $(OUTPUTFILE)$(SYM_EXT);
  446. endif
  447. ifneq "$(OTHER_DEPENDENCIES)" ""
  448. $(QUIET_PREFIX) echo "rm -f $(OTHER_DEPENDENCIES)"
  449. $(QUIET_PREFIX) -rm -f $(OTHER_DEPENDENCIES)
  450. endif
  451. ifneq "$(GAMEOUTPUTFILE)" ""
  452. $(QUIET_PREFIX) echo "$(P4BIN) edit and rm -f $(GAMEOUTPUTFILE) $(GAMEOUTPUTFILE)$(SYM_EXT)"
  453. $(QUIET_PREFIX) $(P4_EDIT_START) $(GAMEOUTPUTFILE) $(GAMEOUTPUTFILE)$(SYM_EXT) $(P4_EDIT_END)
  454. $(QUIET_PREFIX) -rm -f $(GAMEOUTPUTFILE)
  455. endif
  456. # This just reverts the final targets so it'll do a relink next time we build.
  457. cleantargets:
  458. ifneq "$(GAMEOUTPUTFILE)" ""
  459. $(QUIET_PREFIX) echo "$(P4BIN) revert $(GAMEOUTPUTFILE)"
  460. $(QUIET_PREFIX) $(P4_REVERT_START) $(GAMEOUTPUTFILE) $(GAMEOUTPUTFILE)$(SYM_EXT) $(P4_REVERT_END)
  461. endif
  462. ifneq "$(OUTPUTFILE)" ""
  463. $(QUIET_PREFIX) echo "$(P4BIN) revert $(OUTPUTFILE)"
  464. $(QUIET_PREFIX) $(P4_REVERT_START) $(OUTPUTFILE) $(OUTPUTFILE)$(SYM_EXT) $(P4_REVERT_END)
  465. endif
  466. $(LIB_File): $(OTHER_DEPENDENCIES) $(OBJS)
  467. $(QUIET_PREFIX) -$(P4_EDIT_START) $(LIB_File) $(P4_EDIT_END);
  468. $(QUIET_PREFIX) $(AR) $(LIB_File) $(OBJS) $(LIBFILES);
  469. $(SHELL) -c "$(POSTBUILDCOMMAND)"
  470. SO_GameOutputFile = $(GAMEOUTPUTFILE)
  471. # Remove the target before installing a file over it; this prevents existing
  472. # instances of the game from crashing due to the overwrite.
  473. $(GAMEOUTPUTFILE): $(OUTPUTFILE)
  474. $(QUIET_PREFIX) \
  475. $(P4_EDIT_START) $(GAMEOUTPUTFILE) $(P4_EDIT_END) && \
  476. echo "----" $(QUIET_ECHO_POSTFIX);\
  477. echo "---- COPYING TO $@ [$(CFG)] ----";\
  478. echo "----" $(QUIET_ECHO_POSTFIX);
  479. $(QUIET_PREFIX) -$(P4_EDIT_START) $(GAMEOUTPUTFILE) $(P4_EDIT_END);
  480. $(QUIET_PREFIX) -mkdir -p `dirname $(GAMEOUTPUTFILE)` > /dev/null;
  481. $(QUIET_PREFIX) rm -f $(GAMEOUTPUTFILE) $(QUIET_ECHO_POSTFIX);
  482. $(QUIET_PREFIX) cp -v $(OUTPUTFILE) $(GAMEOUTPUTFILE) $(QUIET_ECHO_POSTFIX);
  483. $(QUIET_PREFIX) -$(P4_EDIT_START) $(GAMEOUTPUTFILE)$(SYM_EXT) $(P4_EDIT_END);
  484. $(QUIET_PREFIX) $(GEN_SYM) $(GAMEOUTPUTFILE);
  485. $(QUIET_PREFIX) -$(STRIP) $(GAMEOUTPUTFILE);
  486. $(QUIET_PREFIX) $(VSIGN) -signvalve $(GAMEOUTPUTFILE);
  487. $(QUIET_PREFIX) if [ "$(COPY_DLL_TO_SRV)" = "1" ]; then\
  488. echo "----" $(QUIET_ECHO_POSTFIX);\
  489. echo "---- COPYING TO $(Srv_GAMEOUTPUTFILE) ----";\
  490. echo "----" $(QUIET_ECHO_POSTFIX);\
  491. cp -v $(GAMEOUTPUTFILE) $(Srv_GAMEOUTPUTFILE) $(QUIET_ECHO_POSTFIX);\
  492. cp -v $(GAMEOUTPUTFILE)$(SYM_EXT) $(Srv_GAMEOUTPUTFILE)$(SYM_EXT) $(QUIET_ECHO_POSTFIX);\
  493. fi;
  494. $(QUIET_PREFIX) if [ "$(IMPORTLIBRARY)" != "" ]; then\
  495. echo "----" $(QUIET_ECHO_POSTFIX);\
  496. echo "---- COPYING TO IMPORT LIBRARY $(IMPORTLIBRARY) ----";\
  497. echo "----" $(QUIET_ECHO_POSTFIX);\
  498. $(P4_EDIT_START) $(IMPORTLIBRARY) $(P4_EDIT_END) && \
  499. mkdir -p `dirname $(IMPORTLIBRARY)` > /dev/null && \
  500. cp -v $(OUTPUTFILE) $(IMPORTLIBRARY); \
  501. fi;
  502. $(SO_File): $(OTHER_DEPENDENCIES) $(OBJS) $(LIBFILENAMES)
  503. $(QUIET_PREFIX) \
  504. echo "----" $(QUIET_ECHO_POSTFIX);\
  505. echo "---- LINKING $@ [$(CFG)] ----";\
  506. echo "----" $(QUIET_ECHO_POSTFIX);\
  507. \
  508. $(LINK) $(LINK_MAP_FLAGS) $(SHLIBLDFLAGS) $(PROFILE_LINKER_FLAG) -o $(OUTPUTFILE) $(LIB_START_SHLIB) $(OBJS) $(LIBFILES) $(SystemLibraries) $(LIB_END_SHLIB);
  509. $(QUIET_PREFIX) $(VSIGN) -signvalve $(OUTPUTFILE);
  510. $(QUIET_PREFIX) $(SHELL) -c "$(POSTBUILDCOMMAND)"
  511. $(EXE_File) : $(OTHER_DEPENDENCIES) $(OBJS) $(LIBFILENAMES)
  512. $(QUIET_PREFIX) \
  513. echo "----" $(QUIET_ECHO_POSTFIX);\
  514. echo "---- LINKING EXE $@ [$(CFG)] ----";\
  515. echo "----" $(QUIET_ECHO_POSTFIX);\
  516. \
  517. $(P4_EDIT_START) $(OUTPUTFILE) $(P4_EDIT_END);\
  518. $(LINK) $(LINK_MAP_FLAGS) $(LDFLAGS) $(PROFILE_LINKER_FLAG) -o $(OUTPUTFILE) $(LIB_START_EXE) $(OBJS) $(LIBFILES) $(SystemLibraries) $(LIB_END_EXE);
  519. $(QUIET_PREFIX) -$(P4_EDIT_START) $(OUTPUTFILE)$(SYM_EXT) $(P4_EDIT_END);
  520. $(QUIET_PREFIX) $(GEN_SYM) $(OUTPUTFILE);
  521. $(QUIET_PREFIX) -$(STRIP) $(OUTPUTFILE);
  522. $(QUIET_PREFIX) $(VSIGN) -signvalve $(OUTPUTFILE);
  523. $(QUIET_PREFIX) $(SHELL) -c "$(POSTBUILDCOMMAND)"
  524. tags:
  525. etags -a -C -o $(SRCROOT)/TAGS *.cpp *.cxx *.h *.hxx