Makefile 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. OPT = -g
  10. OPT += -O2
  11. # OPT += -O3
  12. # OPT += -mmmx
  13. # OPT += -msse
  14. # OPT += -msse2
  15. # OPT += -msse3
  16. # OPT += -rdynamic
  17. OPT += -ffast-math
  18. # OPT += -fbounds-checking
  19. # OPT += -fstack-protector
  20. # OPT += -fomit-frame-pointer
  21. OPT += -Wall -Wno-sign-compare
  22. # Uncomment this one if you are using GCC 4.X
  23. # OPT += -Wno-unused-parameter -Wno-pointer-sign
  24. # Makes map-wide script variables be saved to SQL instead of TXT files.
  25. # OPT += -DMAPREGSQL
  26. # Turbo is an alternate socket access implementation which should be faster.
  27. # DO NOT ENABLE YET as it isn't quite ready for general usage.
  28. # OPT += -DTURBO
  29. # Enable the perl regular expression support for scripts
  30. # OPT += -DPCRE_SUPPORT
  31. # OPT += -DGCOLLECT
  32. # OPT += -DMEMWATCH
  33. # OPT += -DDMALLOC -DDMALLOC_FUNC_CHECK
  34. # OPT += -DBCHECK
  35. # LIBS += -lgc
  36. # LIBS += -ldmalloc
  37. # LIBS += -L/usr/local/lib -lpcre
  38. PLATFORM = $(shell uname)
  39. ARCH = $(shell uname -m)
  40. ifeq ($(findstring Linux,$(PLATFORM)), Linux)
  41. LIBS += -ldl
  42. endif
  43. ifeq ($(findstring SunOS,$(PLATFORM)), SunOS)
  44. LIBS += -lsocket -lnsl -ldl
  45. MAKE = gmake
  46. endif
  47. ifeq ($(findstring FreeBSD,$(PLATFORM)), FreeBSD)
  48. MAKE = gmake
  49. OS_TYPE = -D__FREEBSD__
  50. endif
  51. ifeq ($(findstring NetBSD,$(PLATFORM)), NetBSD)
  52. MAKE = gmake
  53. OS_TYPE = -D__NETBSD__
  54. endif
  55. ifeq ($(findstring CYGWIN,$(PLATFORM)), CYGWIN)
  56. OPT += -DFD_SETSIZE=4096
  57. ifeq ($(findstring mingw,$(shell gcc --version)), mingw)
  58. IS_MINGW = 1
  59. OS_TYPE = -DMINGW
  60. LIBS += -L../.. -lwsock32
  61. else
  62. OS_TYPE = -DCYGWIN
  63. endif
  64. endif
  65. ifeq ($(findstring x86_64,$(ARCH)), x86_64)
  66. OPT += -m32
  67. endif
  68. CFLAGS = $(OPT) -I../common $(OS_TYPE)
  69. ifdef SQLFLAG
  70. ifdef IS_MINGW
  71. CFLAGS += -I../mysql
  72. LIBS += -lmysql
  73. else
  74. MYSQLFLAG_CONFIG = $(shell which mysql_config)
  75. ifeq ($(findstring /,$(MYSQLFLAG_CONFIG)), /)
  76. MYSQLFLAG_VERSION = $(shell $(MYSQLFLAG_CONFIG) --version | sed s:\\..*::)
  77. ifeq ($(findstring 5,$(MYSQLFLAG_VERSION)), 5)
  78. MYSQLFLAG_CONFIG_ARGUMENT = --include
  79. else
  80. MYSQLFLAG_CONFIG_ARGUMENT = --cflags
  81. endif
  82. CFLAGS += $(shell $(MYSQLFLAG_CONFIG) $(MYSQLFLAG_CONFIG_ARGUMENT))
  83. LIBS += $(shell $(MYSQLFLAG_CONFIG) --libs)
  84. else
  85. CFLAGS += -I/usr/local/include/mysql
  86. LIBS += -L/usr/local/lib/mysql -lmysqlclient
  87. endif
  88. endif
  89. endif
  90. ifneq ($(findstring -lz,$(LIBS)), -lz)
  91. LIBS += -lz
  92. endif
  93. ifneq ($(findstring -lm,$(LIBS)), -lm)
  94. LIBS += -lm
  95. endif
  96. MKDEF = CC="$(CC)" CFLAGS="$(CFLAGS)" LIB_S="$(LIBS)"
  97. endif
  98. .PHONY: txt sql common login login_sql char char_sql map map_sql ladmin converters \
  99. addons plugins tools clean zlib depend
  100. txt : Makefile.cache conf common login char map ladmin
  101. ifdef SQLFLAG
  102. sql: Makefile.cache conf common login_sql char_sql map_sql
  103. else
  104. sql:
  105. $(MAKE) SQLFLAG=1 $@
  106. endif
  107. conf:
  108. cp -r conf-tmpl conf
  109. rm -rf conf/.svn conf/*/.svn
  110. cp -r save-tmpl save
  111. rm -rf save/.svn
  112. common: src/common/GNUmakefile
  113. $(MAKE) -C src/$@ $(MKDEF)
  114. login: src/login/GNUmakefile common
  115. $(MAKE) -C src/$@ $(MKDEF) txt
  116. char: src/char/GNUmakefile common
  117. $(MAKE) -C src/$@ $(MKDEF) txt
  118. map: src/map/GNUmakefile common
  119. $(MAKE) -C src/$@ $(MKDEF) txt
  120. login_sql: src/login_sql/GNUmakefile common
  121. $(MAKE) -C src/$@ $(MKDEF) sql
  122. char_sql: src/char_sql/GNUmakefile common
  123. $(MAKE) -C src/$@ $(MKDEF) sql
  124. map_sql: src/map/GNUmakefile common
  125. $(MAKE) -C src/map $(MKDEF) sql
  126. ladmin: src/ladmin/GNUmakefile common
  127. $(MAKE) -C src/$@ $(MKDEF)
  128. plugins addons: src/plugins/GNUmakefile common
  129. $(MAKE) -C src/plugins $(MKDEF)
  130. tools:
  131. $(MAKE) -C src/tool $(MKDEF)
  132. ifdef SQLFLAG
  133. converters: src/txt-converter/GNUmakefile common
  134. $(MAKE) -C src/txt-converter $(MKDEF)
  135. else
  136. converters:
  137. $(MAKE) SQLFLAG=1 $@
  138. endif
  139. zlib:
  140. $(MAKE) -C src/$@ $(MKDEF)
  141. clean: src/common/GNUmakefile src/login/GNUmakefile src/login_sql/GNUmakefile \
  142. src/char/GNUmakefile src/char_sql/GNUmakefile src/map/GNUmakefile \
  143. src/ladmin/GNUmakefile src/plugins/GNUmakefile src/txt-converter/GNUmakefile
  144. rm -f Makefile.cache
  145. $(MAKE) -C src/common $@
  146. $(MAKE) -C src/login $@
  147. $(MAKE) -C src/login_sql $@
  148. $(MAKE) -C src/char $@
  149. $(MAKE) -C src/char_sql $@
  150. $(MAKE) -C src/map $@
  151. $(MAKE) -C src/ladmin $@
  152. $(MAKE) -C src/plugins $@
  153. $(MAKE) -C src/zlib $@
  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)