SHARE
TWEET

Metamod-P makefile

a guest Apr 24th, 2012 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # vi: set ts=4 sw=4 :
  2. # vim: set tw=75 :
  3.  
  4. # MetaMod makefile
  5. # Copyright (c) 2001-2003 Will Day <willday@hpgx.net>
  6. #
  7. # based on the Valve SDK 2.1 Makefile as well as the Makefile
  8. # in adminmod by Alfred Reynolds.
  9. #
  10. # From SDK 2.1 dlls/Makefile:
  11. #! Half-Life StandardSDK 2.0 mp_i386.so Makefile for i386 Linux
  12. #! April 2000 by Leon Hartwig (jehannum@planethalflife.com)
  13.  
  14.  
  15. # NOTE: This is a generic Makefile for metamod and the bundled plugins, and
  16. # is symlinked into each subdir.  Per-module config statements are in
  17. # Config.mak in each subdir.
  18.  
  19. ifeq "$(shell uname | cut -d _ -f1)" "CYGWIN"
  20.         HOST=cygwin
  21. endif
  22.  
  23. ifdef COMSPEC
  24.         ifeq "$(HOST)" "cygwin"
  25.                 ifeq "$(TARGET)" "win32"
  26.                         OS=windows
  27.                 else
  28.                         OS=linux
  29.                 endif
  30.         else
  31.                 OS=windows
  32.         endif
  33. else
  34.         OS=linux
  35. endif
  36.  
  37. #############################################################################
  38. # CONFIGURATION
  39. #############################################################################
  40.  
  41. #
  42. ifeq "$(TARGET)" "amd64"
  43.         TARGETTYPE = amd64
  44. else
  45.         TARGETTYPE = i386
  46. endif
  47.  
  48. # set paths for your environment
  49. ifeq "$(OS)" "linux"
  50.         PATH_WIN=/usr/local/cross-tools/i586-mingw32msvc/bin
  51.         INST_DIR=$(HOME)/half-life/cstrike/dlls
  52.         TEST_DIR=$(HOME)/test/tfc/dlls
  53.         TST_DIR=$(HOME)/tmp
  54. else    ## windows
  55.         PATH_WIN=/mingw/bin
  56.         INST_DIR=/hlserver/tfc/dlls
  57.         TEST_DIR=/hlserver/tfc/dlls
  58. endif
  59.  
  60. DLLS_DIR=../dlls
  61. SDKSRC=../hlsdk
  62. METADIR=../metamod
  63.  
  64. COMPILE_TZ=EET
  65. ## Developer overrides
  66. ifeq "$(USER)" "jussi"
  67.         COMPILE_TZ=EET
  68. endif
  69.  
  70.  
  71. #############################################################################
  72. # OS DEPENDENCIES
  73. #############################################################################
  74.  
  75. ifeq "$(OS)" "linux"
  76.         INSTALL=install -m 644
  77.         LD_WINDLL= PATH=$(PATH_WIN) $(PATH_WIN)/dllwrap
  78.         OSTARGET=linux
  79.         LIBFILE=$(LIBFILE_LINUX)
  80.         TARGET_FILE=$(TARGET_LINUX)
  81. else    ## windows
  82.         INSTALL=cp
  83.         LD_WINDLL= dllwrap
  84.         OSTARGET=win32
  85.         LIBFILE=$(LIBFILE_WIN)
  86.         TARGET_FILE=$(TARGET_WIN)
  87. endif
  88.  
  89. CC_WIN=gcc
  90. RES_WIN=windres
  91.  
  92. ifeq "$(HOST)" "cygwin"
  93.         CC_WIN += -mno-cygwin
  94.         EXTRA_LINK += -L/lib/w32api
  95. endif
  96.  
  97. OBJDIR_LINUX_OPT=opt.linux_$(TARGETTYPE)
  98. OBJDIR_LINUX_DBG=debug.linux_$(TARGETTYPE)
  99. OBJDIR_WIN_OPT=opt.win32
  100. OBJDIR_WIN_DBG=debug.win32
  101.  
  102.  
  103. #############################################################################
  104. # COMPILE OPTIONS - ARCHITECTURE AND OPTIMIZATIONS
  105. #############################################################################
  106.  
  107. ifeq "$(OS)" "linux"
  108.         GCCMAJ = $(shell $(CC) -dumpversion | sed -e 's/\.[0-9][0-9]*\.[0-9]//')
  109.         GCCMIN = $(shell $(CC) -dumpversion | sed -e 's/[0-9]\.//;s/\.[0-9]//')
  110. else
  111.         GCCMAJ = $(shell $(CC_WIN) -dumpversion | sed -e 's/\.[0-9][0-9]*\.[0-9]//')
  112.         GCCMIN = $(shell $(CC_WIN) -dumpversion | sed -e 's/[0-9]\.//;s/\.[0-9]//')
  113. endif
  114.  
  115. ifeq "$(HOST)" "cygwin"
  116.         ifeq "$(TARGETTYPE)" "amd64"
  117.                 CC=gcc-linux-x86_64
  118.         else
  119.                 CC=gcc-linux
  120.         endif
  121. else
  122.         ifeq "$(TARGETTYPE)" "amd64"
  123.                 CC=gcc-x86_64
  124.         else
  125.                 CC=gcc
  126.         endif
  127. endif
  128.  
  129. MCPU=-mcpu
  130.  
  131. ifeq "$(GCCMAJ)" "3"
  132.         ifeq "$(GCCMIN)" "4"
  133.                 MCPU=-mtune
  134.         endif
  135. endif
  136. ifeq "$(GCCMAJ)" "4"
  137.         MCPU=-mtune
  138. endif
  139.  
  140. ifeq "$(OS)" "linux"
  141.         CC_DEP=$(CC)
  142. else
  143.         CC_DEP=$(CC_WIN)
  144. endif
  145.  
  146. # Note! About gcc optimization levels.
  147. #  There is four optimization levels:
  148. #       -O0     No optimizations.
  149. #       -O1     Optimize for smaller size.
  150. #       -O2     Optimize for speed without increasing size (alot).
  151. #       -O3     Optimize for speed, can result much greater filesize.
  152. #  Levels higher -O3 (-O6 for example) is threaded as -O3.
  153. #  See differences at "http://gcc.gnu.org/" (look for link to 'gcc manual').
  154.  
  155. # original safe optimization, from valve Makefile
  156. #CCOPT = -O2 -ffast-math -funroll-loops \
  157. #       -fomit-frame-pointer -fexpensive-optimizations -malign-loops=2 \
  158. #       -malign-jumps=2 -malign-functions=2
  159.  
  160. # safe optimization, adapted from adminmod Makefile
  161. #CCOPT = -m486 -O6 -ffast-math -funroll-loops \
  162. # -fexpensive-optimizations -malign-loops=2  -malign-jumps=2 \
  163. # -malign-functions=2 -Wall
  164.  
  165. # full optimization, adapted from adminmod Makefile
  166. # "WONT WORK WITH omit-frame-pointer"?
  167. # - disable (unneeded) C++ exceptions and rtti code to save some space ?
  168.  
  169. CCOPT = $(CCO) $(CCOPT_ARCH) -fno-exceptions -fno-rtti
  170.  
  171. # optimization level; overridden for certain problematic files
  172. CCO = -O2 -fomit-frame-pointer -ffast-math
  173.  
  174. # architecture tuning by target type
  175. ifeq "$(TARGETTYPE)" "amd64"
  176.         CCOPT_ARCH =
  177. else
  178.         #default: pentium or newer
  179.         CCOPT_ARCH = -march=i586 $(MCPU)=pentium4
  180. endif
  181.  
  182. # debugging; halt on warnings
  183. CCDEBUG+= -ggdb3
  184.  
  185.  
  186. #############################################################################
  187. # COMPILE SETUP
  188. #############################################################################
  189.  
  190. SRCDIR=.
  191. INCLUDEDIRS+=-I$(SRCDIR) -I$(METADIR) -I$(SDKSRC)/engine -I$(SDKSRC)/common -I$(SDKSRC)/pm_shared -I$(SDKSRC)/dlls -I$(SDKSRC)
  192. FILES_ALL = *.cpp *.h [A-Z]* *.rc
  193.  
  194. CFLAGS=-Wall -Wno-unknown-pragmas
  195.  
  196. CFLAGS+=-m32
  197.  
  198. #CFLAGS += -DTEST
  199.  
  200. ifeq "$(OPT)" "opt-fast"
  201.         ODEF = -DOPT_TYPE="\"optimized+meta_debug-disabled\""
  202.         CFLAGS := $(CCOPT) $(CFLAGS) $(ODEF) -D__BUILD_FAST_METAMOD__
  203.         OBJDIR_LINUX = $(OBJDIR_LINUX_OPT)
  204.         OBJDIR_WIN = $(OBJDIR_WIN_OPT)
  205. else    #other
  206. ifeq "$(OPT)" "opt"
  207.         ODEF = -DOPT_TYPE="\"optimized\""
  208.         CFLAGS := $(CCOPT) $(CFLAGS) $(ODEF)
  209.         OBJDIR_LINUX = $(OBJDIR_LINUX_OPT)
  210.         OBJDIR_WIN = $(OBJDIR_WIN_OPT)
  211. else    # debug
  212.         ODEF = -DOPT_TYPE="\"debugging\""
  213.         CFLAGS := $(CCDEBUG) $(CFLAGS) $(ODEF)
  214.         OBJDIR_LINUX = $(OBJDIR_LINUX_DBG)
  215.         OBJDIR_WIN = $(OBJDIR_WIN_DBG)
  216.         DLLS_DIR := $(DLLS_DIR)/debug
  217. endif
  218. endif
  219.  
  220. ifeq "$(OS)" "linux"
  221.         OBJDIR = $(OBJDIR_LINUX)
  222. else
  223.         OBJDIR = $(OBJDIR_WIN)
  224. endif
  225.  
  226. include Config.mak
  227. # any local CFLAGS from Config.mak
  228. CFLAGS += $(EXTRA_CFLAGS)
  229.  
  230. # provide timezone info
  231. $(OBJDIR_LINUX)/vdate.o $(OBJDIR_WIN)/vdate.o: CFLAGS += -DCOMPILE_TZ=\"$(COMPILE_TZ)\"
  232.  
  233. # ignore complaints from SDK files like cbase.h
  234. #$(OBJDIR_LINUX)/sdk_util.o $(OBJDIR_WIN)/sdk_util.o: CFLAGS += -Wno-unused
  235.  
  236. # ignore complaints from STL headers
  237. STLOBJ = $(STLFILES:%.cpp=$(OBJDIR_LINUX)/%.o)
  238. STLOBJ += $(STLFILES:%.cpp=$(OBJDIR_WIN)/%.o)
  239. #$(OBJDIR_LINUX)/mreg.o $(OBJDIR_WIN)/mreg.o: CFLAGS += -Wno-effc++
  240. $(STLOBJ): FILTER= 2>&1 | ../tools/stlfilter
  241. $(STLOBJ): CFLAGS += -Wno-error
  242.  
  243. # these files seem to create "Internal compiler error" errors under mingw
  244. # when using -O6
  245. #$(OBJDIR_WIN)/engine_api.o: CCO = -O5
  246. #$(OBJDIR_WIN)/dllapi_api.o: CCO = -O5
  247.  
  248. #############################################################################
  249. # BUILDING LINUX SO
  250. #############################################################################
  251.  
  252. # linux .so compile commands
  253. DO_CC_LINUX=$(CC) $(CFLAGS) -fPIC $(INCLUDEDIRS) -o $@ -c $< $(FILTER)
  254. LINK_LINUX=$(CC) $(CFLAGS) -shared -ldl -lm -static-libgcc $(EXTRA_LINK) $(OBJ_LINUX) -o $@
  255.  
  256. # sort by date
  257. #SRCFILES := $(shell ls -t $(SRCFILES))
  258.  
  259. # linux object files
  260. OBJ_LINUX := $(SRCFILES:%.cpp=$(OBJDIR_LINUX)/%.o)
  261.  
  262. # compiling linux object files
  263. $(OBJDIR_LINUX)/%.o: $(SRCDIR)/%.cpp
  264.         $(DO_CC_LINUX)
  265.  
  266. # linux .so target file
  267. LIBFILE_LINUX = $(MODNAME)_$(TARGETTYPE).so
  268. TARGET_LINUX = $(OBJDIR_LINUX)/$(LIBFILE_LINUX)
  269.  
  270.  
  271. #############################################################################
  272. # BUILDING WINDOWS DLL
  273. #############################################################################
  274.  
  275. # windows .dll compile commands
  276. DO_CC_WIN=$(CC_WIN) $(CFLAGS) $(INCLUDEDIRS) -o $@ -c $<
  277. DO_RES_WIN=$(RES_WIN) '$(ODEF)' --include-dir . --include-dir ../metamod -i $< -O coff -o $@
  278. #LINK_WIN=$(LD_WINDLL) -k -mwindows --add-stdcall-alias --def metamod.def -o $@ $(OBJ_WIN)
  279. #LINK_WIN=$(LD_WINDLL) -A -k -mwindows --export-all-symbols -o $@ $(OBJ_WIN)
  280. #LINK_WIN=$(LD_WINDLL) -mwindows --add-stdcall-alias $(OBJ_WIN) $(RES_OBJ_WIN) -lstdc++ -s -o $@
  281. LINK_WIN=$(CC_WIN) -mdll -Xlinker --add-stdcall-alias $(EXTRA_LINK) $(OBJ_WIN) $(RES_OBJ_WIN) -s -o $@
  282.  
  283. # windows object files
  284. OBJ_WIN := $(SRCFILES:%.cpp=$(OBJDIR_WIN)/%.o)
  285. RES_OBJ_WIN := $(RESFILE:%.rc=$(OBJDIR_WIN)/%.o)
  286.  
  287. # compiling windows object files
  288. $(OBJDIR_WIN)/%.o: $(SRCDIR)/%.cpp
  289.         $(DO_CC_WIN)
  290.  
  291. # compiling windows resource file
  292. $(OBJDIR_WIN)/%.o: $(SRCDIR)/%.rc $(INFOFILES)
  293.         $(DO_RES_WIN)
  294.  
  295. # windows .dll target file
  296. LIBFILE_WIN = $(MODNAME).dll
  297. TARGET_WIN = $(OBJDIR_WIN)/$(LIBFILE_WIN)
  298.  
  299.  
  300. #############################################################################
  301. # OVERRIDES
  302. #############################################################################
  303.  
  304. ifeq "$(PLATFORM)" "linux-only"
  305.         LIBFILE_WIN =
  306.         TARGET_WIN =
  307. endif
  308. ifeq "$(PLATFORM)" "win32-only"
  309.         LIBFILE_LINUX =
  310.         TARGET_LINUX =
  311.         OSTARGET=win32
  312.         LIBFILE=$(LIBFILE_WIN)
  313.         TARGET_FILE=$(TARGET_WIN)
  314. endif
  315.  
  316.  
  317. #############################################################################
  318. # BUILD RULES
  319. #############################################################################
  320.  
  321. default: $(TARGET_FILE)
  322.  
  323. all: do_dll_linux do_dll_win32
  324.  
  325. opt:
  326.         $(MAKE) default OPT=opt
  327.  
  328. linux: do_dll_linux
  329. win32: do_dll_win32
  330.  
  331. linux_opt:
  332.         $(MAKE) linux OPT=opt
  333. win32_opt:
  334.         $(MAKE) win32 OPT=opt
  335.  
  336. $(TARGET_LINUX): msgs/debug msgs/warning msgs/log msgs/error $(OBJDIR_LINUX) $(OBJ_LINUX)
  337.         $(LINK_LINUX)
  338.  
  339. # for plugins, recompile meta_api.cpp if info_name.h changed
  340. $(OBJDIR_LINUX)/meta_api.o $(OBJDIR_WIN)/meta_api.o: info_name.h
  341.  
  342. $(TARGET_WIN): msgs/debug msgs/warning msgs/log msgs/error $(OBJDIR_WIN) $(OBJ_WIN) $(RES_OBJ_WIN)
  343.         $(LINK_WIN)
  344.  
  345. $(OBJDIR_LINUX) $(OBJDIR_WIN) msgs:
  346.         mkdir $@
  347.  
  348. # make sure to recompile vdate.c for each link
  349. $(OBJDIR_LINUX)/vdate.o $(OBJDIR_WIN)/vdate.o : $(SRCFILES) *.h
  350.  
  351. domsgs: msgs/debug msgs/log msgs/error msgs/warning
  352.  
  353. msgs/debug: $(SRCFILES) *.h msgs
  354.         egrep "DEBUG\([0-9]" $(SRCFILES) *.h | sed "s/:[        ]*/     /" | sort -k2,2 > $@
  355.  
  356. msgs/log: $(SRCFILES) *.h msgs
  357.         egrep "META_LOG\(" $(SRCFILES) *.h | sed "s/:[  ]*/     /" | sort > $@
  358.  
  359. msgs/error: $(SRCFILES) *.h msgs
  360.         egrep "META_ERROR\(" $(SRCFILES) *.h | sed "s/:[        ]*/     /" | sort > $@
  361.  
  362. msgs/warning: $(SRCFILES) *.h msgs
  363.         egrep "META_WARNING\(" $(SRCFILES) *.h | sed "s/:[      ]*/     /" | sort > $@
  364.  
  365. tags:   .tags .htags
  366. ctags:  .tags
  367. htags:  .htags
  368.  
  369. .tags: $(SRCFILES) *.h
  370.         -ctags -a $?
  371.  
  372. .htags: *.h
  373.         -htags $?
  374.  
  375. retags:
  376.         -rm -f .tags .htags
  377.         ctags -f .tags `find $(SDKSRC) -name '*.h'`
  378.         ctags -f .tags -a `find $(METADIR) -name old -prune -o -name '*.h' -print`
  379.         ctags -f .tags -a $(SRCFILES)
  380.         htags -R $(SDKSRC)
  381.         htags `find $(METADIR) -name old -prune -o -name '*.h' -print`
  382.         htags *.h
  383.  
  384. clean: clean_$(OSTARGET)
  385.  
  386. clean_linux:
  387.         test -n "$(OBJDIR_LINUX)"
  388.         -rm -f $(OBJDIR_LINUX)/*
  389.  
  390. clean_win32:
  391.         test -n "$(OBJDIR_WIN)"
  392.         -rm -f $(OBJDIR_WIN)/*
  393.  
  394. cleanall_linux:
  395.         $(MAKE) clean_linux
  396.         $(MAKE) clean_linux OPT=opt
  397.         $(MAKE) clean_linux TARGET=amd64
  398.         $(MAKE) clean_linux TARGET=amd64 OPT=opt
  399.  
  400. cleanall_win32:
  401.         $(MAKE) clean_win32
  402.         $(MAKE) clean_win32 OPT=opt
  403.  
  404. cleanall: cleanall_linux cleanall_win32
  405.  
  406. dll_linux dll_win32:
  407.         $(MAKE) do_$@
  408.         $(MAKE) do_$@ OPT=opt
  409.  
  410. do_dll_linux: $(DLLS_DIR) $(DLLS_DIR)/$(LIBFILE_LINUX)
  411. do_dll_win32: $(DLLS_DIR) $(DLLS_DIR)/$(LIBFILE_WIN)
  412.  
  413. $(DLLS_DIR):
  414.         mkdir $(DLLS_DIR)
  415.  
  416. $(DLLS_DIR)/$(LIBFILE_LINUX): $(TARGET_LINUX)
  417.         $(INSTALL) $+ $@
  418.  
  419. $(DLLS_DIR)/$(LIBFILE_WIN): $(TARGET_WIN)
  420.         $(INSTALL) $+ $@
  421.  
  422. dlls: dll_linux dll_win32
  423. rmdlls:
  424.         -rm -f ../dlls/*.* ../dlls/debug/*.*
  425.  
  426. spotless: cleanall
  427.         -rmdir $(OBJDIR_LINUX) $(OBJDIR_WIN)
  428. #       -rm -f .snap $(GENERATED)
  429.  
  430. distclean:      spotless
  431.  
  432. install: $(INST_DIR)/$(LIBFILE)
  433. test: $(TEST_DIR)/$(LIBFILE)
  434. test_opt:
  435.         $(MAKE) test OPT=opt
  436.  
  437. $(INST_DIR)/$(LIBFILE) $(TEST_DIR)/$(LIBFILE): $(TARGET_FILE)
  438.         $(INSTALL) $< $@
  439.  
  440. tst: $(TST_DIR)/$(LIBFILE_WIN)
  441.  
  442. $(TST_DIR)/$(LIBFILE_WIN): $(TARGET_WIN)
  443.         cp $< $@
  444.  
  445. snap:   .snap
  446.  
  447. .snap: $(FILES_ALL)
  448.         mkdir -p snapshots
  449.         tar zcvf snapshots/`date '+%m%d-%H%M'`.tgz $(FILES_ALL)
  450.         touch .snap
  451.        
  452. depend: $(OBJDIR)/Rules.depend
  453.  
  454. $(OBJDIR)/Rules.depend: Makefile $(SRCFILES) $(OBJDIR)
  455.         $(CC_DEP) -MM $(INCLUDEDIRS) $(SRCFILES) | sed "s;\(^[^         ]*\):\(.*\);$(OBJDIR)/\1: Makefile Config.mak \2;" > $@
  456.  
  457. include $(OBJDIR)/Rules.depend
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top