Makefile 6.9 KB

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