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