Makefile 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. # Turbo is an alternate socket access implementation which should be faster.
  32. # DO NOT ENABLE YET as it isn't quite ready for general usage.
  33. # OPT += -DTURBO
  34. # Enable the perl regular expression support for scripts
  35. # OPT += -DPCRE_SUPPORT
  36. # OPT += -DGCOLLECT
  37. # OPT += -DMEMWATCH
  38. # OPT += -DDMALLOC -DDMALLOC_FUNC_CHECK
  39. # OPT += -DBCHECK
  40. # LIBS += -lgc
  41. # LIBS += -ldmalloc
  42. # LIBS += -L/usr/local/lib -lpcre
  43. PLATFORM = $(shell uname)
  44. ARCH = $(shell uname -m)
  45. ifeq ($(findstring Linux,$(PLATFORM)), Linux)
  46. LIBS += -ldl
  47. endif
  48. ifeq ($(findstring SunOS,$(PLATFORM)), SunOS)
  49. LIBS += -lsocket -lnsl -ldl
  50. MAKE = gmake
  51. endif
  52. ifeq ($(findstring FreeBSD,$(PLATFORM)), FreeBSD)
  53. MAKE = gmake
  54. OS_TYPE = -D__FREEBSD__
  55. endif
  56. ifeq ($(findstring NetBSD,$(PLATFORM)), NetBSD)
  57. MAKE = gmake
  58. OS_TYPE = -D__NETBSD__
  59. endif
  60. ifeq ($(findstring CYGWIN,$(PLATFORM)), CYGWIN)
  61. OPT += -DFD_SETSIZE=4096
  62. OS_TYPE = -DCYGWIN
  63. endif
  64. ifeq ($(findstring mingw,$(shell gcc --version)), mingw)
  65. IS_MINGW = 1
  66. OS_TYPE = -DMINGW
  67. OPT += -DFD_SETSIZE=4096
  68. # CFLAGS += -I../zlib
  69. # LIBS += -L../../lib
  70. LIBS += -lws2_32
  71. endif
  72. ifeq ($(findstring x86_64,$(ARCH)), x86_64)
  73. OPT += -m32
  74. endif
  75. CFLAGS = $(OPT) -I../common $(OS_TYPE)
  76. ifdef SQLFLAG
  77. ifdef IS_MINGW
  78. CFLAGS += -I../mysql
  79. LIBS += -lmysql
  80. else
  81. MYSQLFLAG_CONFIG = $(shell which mysql_config)
  82. ifeq ($(findstring /,$(MYSQLFLAG_CONFIG)), /)
  83. MYSQLFLAG_VERSION = $(shell $(MYSQLFLAG_CONFIG) --version | sed s:\\..*::)
  84. ifeq ($(findstring 5,$(MYSQLFLAG_VERSION)), 5)
  85. MYSQLFLAG_CONFIG_ARGUMENT = --include
  86. else
  87. MYSQLFLAG_CONFIG_ARGUMENT = --cflags
  88. endif
  89. CFLAGS += $(shell $(MYSQLFLAG_CONFIG) $(MYSQLFLAG_CONFIG_ARGUMENT))
  90. LIBS += $(shell $(MYSQLFLAG_CONFIG) --libs)
  91. else
  92. CFLAGS += -I/usr/local/include/mysql
  93. LIBS += -L/usr/local/lib/mysql -lmysqlclient
  94. endif
  95. endif
  96. endif
  97. ifneq ($(findstring -lz,$(LIBS)), -lz)
  98. LIBS += -lz
  99. endif
  100. ifneq ($(findstring -lm,$(LIBS)), -lm)
  101. LIBS += -lm
  102. endif
  103. MKDEF = CC="$(CC)" CFLAGS="$(CFLAGS)" LIB_S="$(LIBS)"
  104. endif
  105. .PHONY: txt sql common login login_sql char char_sql map map_sql ladmin converters \
  106. addons plugins tools clean depend
  107. txt : Makefile.cache conf common login char map ladmin
  108. ifdef SQLFLAG
  109. sql: Makefile.cache conf common login_sql char_sql map_sql
  110. else
  111. sql:
  112. $(MAKE) SQLFLAG=1 $@
  113. endif
  114. conf:
  115. cp -r conf-tmpl conf
  116. cp -r save-tmpl save
  117. rm -rf conf/.svn conf/*/.svn save/.svn
  118. common: src/common/GNUmakefile
  119. $(MAKE) -C src/$@ $(MKDEF)
  120. login: src/login/GNUmakefile common
  121. $(MAKE) -C src/$@ $(MKDEF) txt
  122. char: src/char/GNUmakefile common
  123. $(MAKE) -C src/$@ $(MKDEF) txt
  124. map: src/map/GNUmakefile common
  125. $(MAKE) -C src/$@ $(MKDEF) txt
  126. login_sql: src/login_sql/GNUmakefile common
  127. $(MAKE) -C src/$@ $(MKDEF) sql
  128. char_sql: src/char_sql/GNUmakefile common
  129. $(MAKE) -C src/$@ $(MKDEF) sql
  130. map_sql: src/map/GNUmakefile common
  131. $(MAKE) -C src/map $(MKDEF) sql
  132. ladmin: src/ladmin/GNUmakefile common
  133. $(MAKE) -C src/$@ $(MKDEF)
  134. plugins addons: src/plugins/GNUmakefile common
  135. $(MAKE) -C src/plugins $(MKDEF)
  136. tools:
  137. $(MAKE) -C src/tool $(MKDEF)
  138. ifdef SQLFLAG
  139. converters: src/txt-converter/GNUmakefile common
  140. $(MAKE) -C src/txt-converter $(MKDEF)
  141. else
  142. converters:
  143. $(MAKE) SQLFLAG=1 $@
  144. endif
  145. clean: src/common/GNUmakefile src/login/GNUmakefile src/login_sql/GNUmakefile \
  146. src/char/GNUmakefile src/char_sql/GNUmakefile src/map/GNUmakefile \
  147. src/ladmin/GNUmakefile src/plugins/GNUmakefile src/txt-converter/GNUmakefile
  148. rm -f Makefile.cache
  149. $(MAKE) -C src/common $@
  150. $(MAKE) -C src/login $@
  151. $(MAKE) -C src/login_sql $@
  152. $(MAKE) -C src/char $@
  153. $(MAKE) -C src/char_sql $@
  154. $(MAKE) -C src/map $@
  155. $(MAKE) -C src/ladmin $@
  156. $(MAKE) -C src/plugins $@
  157. $(MAKE) -C src/txt-converter $@
  158. depend: src/common/GNUmakefile src/login/GNUmakefile src/login_sql/GNUmakefile \
  159. src/char/GNUmakefile src/char_sql/GNUmakefile src/map/GNUmakefile \
  160. src/ladmin/GNUmakefile src/plugins/GNUmakefile src/txt-converter/GNUmakefile
  161. cd src/common; makedepend -fGNUmakefile -pobj/ -Y. *.c; cd ../..;
  162. cd src/login; makedepend -DTXT_ONLY -fGNUmakefile -Y. -Y../common *.c; cd ../..;
  163. cd src/login_sql; makedepend -fGNUmakefile -Y. -Y../common *.c; cd ../..;
  164. cd src/char; makedepend -DTXT_ONLY -fGNUmakefile -Y. -Y../common *.c; cd ../..;
  165. cd src/char_sql; makedepend -fGNUmakefile -Y. -Y../common *.c; cd ../..;
  166. cd src/map; makedepend -DTXT_ONLY -fGNUmakefile -ptxtobj/ -Y. -Y../common *.c; cd ../..;
  167. cd src/map; makedepend -fGNUmakefile -a -psqlobj/ -Y. -Y../common *.c; cd ../..;
  168. cd src/ladmin; makedepend -fGNUmakefile -Y. -Y../common *.c; cd ../..;
  169. cd src/txt-converter; makedepend -DTXT_SQL_CONVERT -fGNUmakefile -Y. -Y../common *.c; cd ../..;
  170. $(MAKE) -C src/plugins $@
  171. Makefile.cache:
  172. printf "$(subst ",\",$(MKDEF))" > Makefile.cache
  173. src/%/GNUmakefile: src/%/Makefile
  174. sed -e 's/$$>/$$^/' $< > $@
  175. src/common/GNUmakefile: src/common/Makefile
  176. src/login/GNUmakefile: src/login/Makefile
  177. src/login_sql/GNUmakefile: src/login_sql/Makefile
  178. src/char/GNUmakefile: src/char/Makefile
  179. src/char_sql/GNUmakefile: src/char_sql/Makefile
  180. src/map/GNUmakefile: src/map/Makefile
  181. src/plugins/GNUmakefile: src/plugins/Makefile
  182. src/ladmin/GNUmakefile: src/ladmin/Makefile
  183. src/txt-converter/GNUmakefile: src/txt-converter/Makefile
  184. install: conf/%.conf conf/%.txt
  185. $(shell mkdir -p /opt/eathena/bin/)
  186. $(shell mkdir -p /opt/eathena/etc/eathena/)
  187. $(shell mkdir -p /opt/eathena/var/log/eathena/)
  188. $(shell mv save /opt/eathena/etc/eathena/save)
  189. $(shell mv db /opt/eathena/etc/eathena/db)
  190. $(shell mv conf /opt/eathena/etc/eathena/conf)
  191. $(shell mv npc /opt/eathena/etc/eathena/npc)
  192. $(shell mv log/* /opt/eathena/var/log/eathena/)
  193. $(shell cp *-server* /opt/eathena/bin/)
  194. $(shell cp ladmin /opt/eathena/bin/)
  195. $(shell ln -s /opt/eathena/etc/eathena/save/ /opt/eathena/bin/)
  196. $(shell ln -s /opt/eathena/etc/eathena/db/ /opt/eathena/bin/)
  197. $(shell ln -s /opt/eathena/etc/eathena/conf/ /opt/eathena/bin/)
  198. $(shell ln -s /opt/eathena/etc/eathena/npc/ /opt/eathena/bin/)
  199. $(shell ln -s /opt/eathena/var/log/eathena/ /opt/eathena/bin/log)
  200. bin-clean:
  201. $(shell rm /opt/eathena/bin/login-server*)
  202. $(shell rm /opt/eathena/bin/char-server*)
  203. $(shell rm /opt/eathena/bin/map-server*)
  204. $(shell rm /opt/eathena/bin/ladmin)
  205. uninstall:
  206. bin-clean
  207. $(shell rm /opt/eathena/bin/save)
  208. $(shell rm /opt/eathena/bin/db)
  209. $(shell rm /opt/eathena/bin/conf)
  210. $(shell rm /opt/eathena/bin/npc)
  211. $(shell rm /opt/eathena/bin/log)
  212. $(shell rm -rf /opt/eathena/etc/eathena)
  213. $(shell rm -rf /opt/eathena/var/log/eathena)