Makefile 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 clean zlib depend
  96. txt : Makefile.cache conf common login char map ladmin
  97. ifdef SQLFLAG
  98. sql: Makefile.cache conf common login_sql char_sql map_sql
  99. else
  100. sql:
  101. $(MAKE) SQLFLAG=1 $@
  102. endif
  103. conf:
  104. cp -r conf-tmpl conf
  105. rm -rf conf/.svn conf/*/.svn
  106. cp -r save-tmpl save
  107. rm -rf save/.svn
  108. common: src/common/GNUmakefile
  109. $(MAKE) -C src/$@ $(MKDEF)
  110. login: src/login/GNUmakefile common
  111. $(MAKE) -C src/$@ $(MKDEF) txt
  112. char: src/char/GNUmakefile common
  113. $(MAKE) -C src/$@ $(MKDEF) txt
  114. map: src/map/GNUmakefile common
  115. $(MAKE) -C src/$@ $(MKDEF) txt
  116. login_sql: src/login_sql/GNUmakefile common
  117. $(MAKE) -C src/$@ $(MKDEF) sql
  118. char_sql: src/char_sql/GNUmakefile common
  119. $(MAKE) -C src/$@ $(MKDEF) sql
  120. map_sql: src/map/GNUmakefile common
  121. $(MAKE) -C src/map $(MKDEF) sql
  122. ladmin: src/ladmin/GNUmakefile common
  123. $(MAKE) -C src/$@ $(MKDEF)
  124. plugins addons: src/plugins/GNUmakefile common
  125. $(MAKE) -C src/plugins $(MKDEF)
  126. tools:
  127. $(MAKE) -C src/tool $(MKDEF)
  128. ifdef SQLFLAG
  129. converters: src/txt-converter/GNUmakefile common
  130. $(MAKE) -C src/txt-converter $(MKDEF)
  131. else
  132. converters:
  133. $(MAKE) SQLFLAG=1 $@
  134. endif
  135. zlib:
  136. $(MAKE) -C src/$@ $(MKDEF)
  137. clean: src/common/GNUmakefile src/login/GNUmakefile src/login_sql/GNUmakefile \
  138. src/char/GNUmakefile src/char_sql/GNUmakefile src/map/GNUmakefile \
  139. src/ladmin/GNUmakefile src/plugins/GNUmakefile src/txt-converter/GNUmakefile
  140. rm -f Makefile.cache
  141. $(MAKE) -C src/common $@
  142. $(MAKE) -C src/login $@
  143. $(MAKE) -C src/login_sql $@
  144. $(MAKE) -C src/char $@
  145. $(MAKE) -C src/char_sql $@
  146. $(MAKE) -C src/map $@
  147. $(MAKE) -C src/ladmin $@
  148. $(MAKE) -C src/plugins $@
  149. $(MAKE) -C src/zlib $@
  150. $(MAKE) -C src/txt-converter $@
  151. depend: src/common/GNUmakefile src/login/GNUmakefile src/login_sql/GNUmakefile \
  152. src/char/GNUmakefile src/char_sql/GNUmakefile src/map/GNUmakefile \
  153. src/ladmin/GNUmakefile src/plugins/GNUmakefile src/txt-converter/GNUmakefile
  154. cd src/common; makedepend -fGNUmakefile -pobj/ -Y. *.c; cd ../..;
  155. cd src/login; makedepend -DTXT_ONLY -fGNUmakefile -Y. -Y../common *.c; cd ../..;
  156. cd src/login_sql; makedepend -fGNUmakefile -Y. -Y../common *.c; cd ../..;
  157. cd src/char; makedepend -DTXT_ONLY -fGNUmakefile -Y. -Y../common *.c; cd ../..;
  158. cd src/char_sql; makedepend -fGNUmakefile -Y. -Y../common *.c; cd ../..;
  159. cd src/map; makedepend -DTXT_ONLY -fGNUmakefile -ptxtobj/ -Y. -Y../common *.c; cd ../..;
  160. cd src/map; makedepend -fGNUmakefile -a -psqlobj/ -Y. -Y../common *.c; cd ../..;
  161. cd src/ladmin; makedepend -fGNUmakefile -Y. -Y../common *.c; cd ../..;
  162. cd src/txt-converter; makedepend -DTXT_SQL_CONVERT -fGNUmakefile -Y. -Y../common *.c; cd ../..;
  163. $(MAKE) -C src/plugins $@
  164. Makefile.cache:
  165. printf "$(subst ",\",$(MKDEF))" > Makefile.cache
  166. src/%/GNUmakefile: src/%/Makefile
  167. sed -e 's/$$>/$$^/' $< > $@
  168. src/common/GNUmakefile: src/common/Makefile
  169. src/login/GNUmakefile: src/login/Makefile
  170. src/login_sql/GNUmakefile: src/login_sql/Makefile
  171. src/char/GNUmakefile: src/char/Makefile
  172. src/char_sql/GNUmakefile: src/char_sql/Makefile
  173. src/map/GNUmakefile: src/map/Makefile
  174. src/plugins/GNUmakefile: src/plugins/Makefile
  175. src/ladmin/GNUmakefile: src/ladmin/Makefile
  176. src/txt-converter/GNUmakefile: src/txt-converter/Makefile
  177. install: conf/%.conf conf/%.txt
  178. $(shell mkdir -p /opt/eathena/bin/)
  179. $(shell mkdir -p /opt/eathena/etc/eathena/)
  180. $(shell mkdir -p /opt/eathena/var/log/eathena/)
  181. $(shell mv save /opt/eathena/etc/eathena/save)
  182. $(shell mv db /opt/eathena/etc/eathena/db)
  183. $(shell mv conf /opt/eathena/etc/eathena/conf)
  184. $(shell mv npc /opt/eathena/etc/eathena/npc)
  185. $(shell mv log/* /opt/eathena/var/log/eathena/)
  186. $(shell cp *-server* /opt/eathena/bin/)
  187. $(shell cp ladmin /opt/eathena/bin/)
  188. $(shell ln -s /opt/eathena/etc/eathena/save/ /opt/eathena/bin/)
  189. $(shell ln -s /opt/eathena/etc/eathena/db/ /opt/eathena/bin/)
  190. $(shell ln -s /opt/eathena/etc/eathena/conf/ /opt/eathena/bin/)
  191. $(shell ln -s /opt/eathena/etc/eathena/npc/ /opt/eathena/bin/)
  192. $(shell ln -s /opt/eathena/var/log/eathena/ /opt/eathena/bin/log)
  193. bin-clean:
  194. $(shell rm /opt/eathena/bin/login-server*)
  195. $(shell rm /opt/eathena/bin/char-server*)
  196. $(shell rm /opt/eathena/bin/map-server*)
  197. $(shell rm /opt/eathena/bin/ladmin)
  198. uninstall:
  199. bin-clean
  200. $(shell rm /opt/eathena/bin/save)
  201. $(shell rm /opt/eathena/bin/db)
  202. $(shell rm /opt/eathena/bin/conf)
  203. $(shell rm /opt/eathena/bin/npc)
  204. $(shell rm /opt/eathena/bin/log)
  205. $(shell rm -rf /opt/eathena/etc/eathena)
  206. $(shell rm -rf /opt/eathena/var/log/eathena)