Makefile 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. CACHED = $(shell ls | grep Makefile.cache)
  2. ifeq ($(findstring Makefile.cache,$(CACHED)), Makefile.cache)
  3. MKDEF = $(shell cat Makefile.cache)
  4. else
  5. CC = gcc -pipe
  6. # CC = g++ --pipe
  7. MAKE = make
  8. # MAKE = gmake
  9. # Detecting gcc version
  10. GCC_VERSION = $(shell $(CC) -v 2>&1 | grep version | cut -d' ' -f3 | cut -d'.' -f1)
  11. OPT = -g
  12. OPT += -O2
  13. # OPT += -O3
  14. # OPT += -mmmx
  15. # OPT += -msse
  16. # OPT += -msse2
  17. # OPT += -msse3
  18. # OPT += -rdynamic
  19. OPT += -ffast-math
  20. # OPT += -fbounds-checking
  21. # OPT += -fstack-protector
  22. # OPT += -fomit-frame-pointer
  23. OPT += -Wall -Wno-sign-compare
  24. ifeq ($(GCC_VERSION), 4)
  25. OPT += -Wno-unused-parameter -Wno-pointer-sign
  26. endif
  27. # Server Packet Protocol version (also defined in src/common/mmo.h)
  28. # OPT += -DPACKETVER=8
  29. # Makes map-wide script variables be saved to SQL instead of TXT files.
  30. # OPT += -DMAPREGSQL
  31. # Enable the perl regular expression support for scripts
  32. # OPT += -DPCRE_SUPPORT
  33. # OPT += -DGCOLLECT
  34. # OPT += -DMEMWATCH
  35. # OPT += -DDMALLOC -DDMALLOC_FUNC_CHECK
  36. # OPT += -DBCHECK
  37. # LIBS += -lgc
  38. # LIBS += -ldmalloc
  39. # LIBS += -L/usr/local/lib -lpcre
  40. PLATFORM = $(shell uname)
  41. ARCH = $(shell uname -m)
  42. ifeq ($(findstring Linux,$(PLATFORM)), Linux)
  43. LIBS += -ldl
  44. endif
  45. ifeq ($(findstring SunOS,$(PLATFORM)), SunOS)
  46. LIBS += -lsocket -lnsl -ldl
  47. MAKE = gmake
  48. endif
  49. ifeq ($(findstring FreeBSD,$(PLATFORM)), FreeBSD)
  50. MAKE = gmake
  51. OS_TYPE = -D__FREEBSD__
  52. endif
  53. ifeq ($(findstring NetBSD,$(PLATFORM)), NetBSD)
  54. MAKE = gmake
  55. OS_TYPE = -D__NETBSD__
  56. endif
  57. ifeq ($(findstring CYGWIN,$(PLATFORM)), CYGWIN)
  58. OPT += -DFD_SETSIZE=4096
  59. OS_TYPE = -DCYGWIN
  60. endif
  61. ifeq ($(findstring mingw,$(shell gcc --version)), mingw)
  62. IS_MINGW = 1
  63. OS_TYPE = -DMINGW
  64. OPT += -DFD_SETSIZE=4096
  65. # CFLAGS += -I../zlib
  66. # LIBS += -L../../lib
  67. LIBS += -lws2_32
  68. endif
  69. ifeq ($(findstring x86_64,$(ARCH)), x86_64)
  70. OPT += -m32
  71. endif
  72. CFLAGS = $(OPT) -I../common $(OS_TYPE)
  73. ifdef SQLFLAG
  74. ifdef IS_MINGW
  75. CFLAGS += -I../mysql
  76. LIBS += -lmysql
  77. else
  78. MYSQLFLAG_CONFIG = $(shell which mysql_config)
  79. ifeq ($(findstring /,$(MYSQLFLAG_CONFIG)), /)
  80. MYSQLFLAG_VERSION = $(shell $(MYSQLFLAG_CONFIG) --version | sed s:\\..*::)
  81. ifeq ($(findstring 5,$(MYSQLFLAG_VERSION)), 5)
  82. MYSQLFLAG_CONFIG_ARGUMENT = --include
  83. else
  84. MYSQLFLAG_CONFIG_ARGUMENT = --cflags
  85. endif
  86. CFLAGS += $(shell $(MYSQLFLAG_CONFIG) $(MYSQLFLAG_CONFIG_ARGUMENT))
  87. LIBS += $(shell $(MYSQLFLAG_CONFIG) --libs)
  88. else
  89. CFLAGS += -I/usr/local/include/mysql
  90. LIBS += -L/usr/local/lib/mysql -lmysqlclient
  91. endif
  92. endif
  93. endif
  94. ifneq ($(findstring -lz,$(LIBS)), -lz)
  95. LIBS += -lz
  96. endif
  97. ifneq ($(findstring -lm,$(LIBS)), -lm)
  98. LIBS += -lm
  99. endif
  100. MKDEF = CC="$(CC)" CFLAGS="$(CFLAGS)" LIB_S="$(LIBS)"
  101. endif
  102. .PHONY: txt sql common login login_sql char char_sql map map_sql ladmin converters \
  103. addons plugins tools clean depend
  104. txt : Makefile.cache conf common login char map ladmin
  105. ifdef SQLFLAG
  106. sql: Makefile.cache conf common login_sql char_sql map_sql
  107. else
  108. sql:
  109. $(MAKE) SQLFLAG=1 $@
  110. endif
  111. conf:
  112. cp -r conf-tmpl conf
  113. cp -r save-tmpl save
  114. rm -rf conf/.svn conf/*/.svn save/.svn
  115. common: src/common/GNUmakefile
  116. $(MAKE) -C src/$@ $(MKDEF)
  117. login: src/login/GNUmakefile common
  118. $(MAKE) -C src/$@ $(MKDEF) txt
  119. char: src/char/GNUmakefile common
  120. $(MAKE) -C src/$@ $(MKDEF) txt
  121. map: src/map/GNUmakefile common
  122. $(MAKE) -C src/$@ $(MKDEF) txt
  123. login_sql: src/login_sql/GNUmakefile common
  124. $(MAKE) -C src/$@ $(MKDEF) sql
  125. char_sql: src/char_sql/GNUmakefile common
  126. $(MAKE) -C src/$@ $(MKDEF) sql
  127. map_sql: src/map/GNUmakefile common
  128. $(MAKE) -C src/map $(MKDEF) sql
  129. ladmin: src/ladmin/GNUmakefile common
  130. $(MAKE) -C src/$@ $(MKDEF)
  131. plugins addons: src/plugins/GNUmakefile common
  132. $(MAKE) -C src/plugins $(MKDEF)
  133. tools:
  134. $(MAKE) -C src/tool $(MKDEF)
  135. ifdef SQLFLAG
  136. converters: src/txt-converter/GNUmakefile common
  137. $(MAKE) -C src/txt-converter $(MKDEF)
  138. else
  139. converters:
  140. $(MAKE) SQLFLAG=1 $@
  141. endif
  142. clean: src/common/GNUmakefile src/login/GNUmakefile src/login_sql/GNUmakefile \
  143. src/char/GNUmakefile src/char_sql/GNUmakefile src/map/GNUmakefile \
  144. src/ladmin/GNUmakefile src/plugins/GNUmakefile src/txt-converter/GNUmakefile
  145. rm -f Makefile.cache
  146. $(MAKE) -C src/common $@
  147. $(MAKE) -C src/login $@
  148. $(MAKE) -C src/login_sql $@
  149. $(MAKE) -C src/char $@
  150. $(MAKE) -C src/char_sql $@
  151. $(MAKE) -C src/map $@
  152. $(MAKE) -C src/ladmin $@
  153. $(MAKE) -C src/plugins $@
  154. $(MAKE) -C src/txt-converter $@
  155. depend: src/common/GNUmakefile src/login/GNUmakefile src/login_sql/GNUmakefile \
  156. src/char/GNUmakefile src/char_sql/GNUmakefile src/map/GNUmakefile \
  157. src/ladmin/GNUmakefile src/plugins/GNUmakefile src/txt-converter/GNUmakefile
  158. cd src/common; makedepend -fGNUmakefile -pobj/ -Y. *.c; cd ../..;
  159. cd src/login; makedepend -DTXT_ONLY -fGNUmakefile -Y. -Y../common *.c; cd ../..;
  160. cd src/login_sql; makedepend -fGNUmakefile -Y. -Y../common *.c; cd ../..;
  161. cd src/char; makedepend -DTXT_ONLY -fGNUmakefile -Y. -Y../common *.c; cd ../..;
  162. cd src/char_sql; makedepend -fGNUmakefile -Y. -Y../common *.c; cd ../..;
  163. cd src/map; makedepend -DTXT_ONLY -fGNUmakefile -ptxtobj/ -Y. -Y../common *.c; cd ../..;
  164. cd src/map; makedepend -fGNUmakefile -a -psqlobj/ -Y. -Y../common *.c; cd ../..;
  165. cd src/ladmin; makedepend -fGNUmakefile -Y. -Y../common *.c; cd ../..;
  166. cd src/txt-converter; makedepend -DTXT_SQL_CONVERT -fGNUmakefile -Y. -Y../common *.c; cd ../..;
  167. $(MAKE) -C src/plugins $@
  168. Makefile.cache:
  169. printf "$(subst ",\",$(MKDEF))" > Makefile.cache
  170. src/%/GNUmakefile: src/%/Makefile
  171. sed -e 's/$$>/$$^/' $< > $@
  172. src/common/GNUmakefile: src/common/Makefile
  173. src/login/GNUmakefile: src/login/Makefile
  174. src/login_sql/GNUmakefile: src/login_sql/Makefile
  175. src/char/GNUmakefile: src/char/Makefile
  176. src/char_sql/GNUmakefile: src/char_sql/Makefile
  177. src/map/GNUmakefile: src/map/Makefile
  178. src/plugins/GNUmakefile: src/plugins/Makefile
  179. src/ladmin/GNUmakefile: src/ladmin/Makefile
  180. src/txt-converter/GNUmakefile: src/txt-converter/Makefile
  181. install: conf/%.conf conf/%.txt
  182. $(shell mkdir -p /opt/eathena/bin/)
  183. $(shell mkdir -p /opt/eathena/etc/eathena/)
  184. $(shell mkdir -p /opt/eathena/var/log/eathena/)
  185. $(shell mv save /opt/eathena/etc/eathena/save)
  186. $(shell mv db /opt/eathena/etc/eathena/db)
  187. $(shell mv conf /opt/eathena/etc/eathena/conf)
  188. $(shell mv npc /opt/eathena/etc/eathena/npc)
  189. $(shell mv log/* /opt/eathena/var/log/eathena/)
  190. $(shell cp *-server* /opt/eathena/bin/)
  191. $(shell cp ladmin /opt/eathena/bin/)
  192. $(shell ln -s /opt/eathena/etc/eathena/save/ /opt/eathena/bin/)
  193. $(shell ln -s /opt/eathena/etc/eathena/db/ /opt/eathena/bin/)
  194. $(shell ln -s /opt/eathena/etc/eathena/conf/ /opt/eathena/bin/)
  195. $(shell ln -s /opt/eathena/etc/eathena/npc/ /opt/eathena/bin/)
  196. $(shell ln -s /opt/eathena/var/log/eathena/ /opt/eathena/bin/log)
  197. bin-clean:
  198. $(shell rm /opt/eathena/bin/login-server*)
  199. $(shell rm /opt/eathena/bin/char-server*)
  200. $(shell rm /opt/eathena/bin/map-server*)
  201. $(shell rm /opt/eathena/bin/ladmin)
  202. uninstall:
  203. bin-clean
  204. $(shell rm /opt/eathena/bin/save)
  205. $(shell rm /opt/eathena/bin/db)
  206. $(shell rm /opt/eathena/bin/conf)
  207. $(shell rm /opt/eathena/bin/npc)
  208. $(shell rm /opt/eathena/bin/log)
  209. $(shell rm -rf /opt/eathena/etc/eathena)
  210. $(shell rm -rf /opt/eathena/var/log/eathena)