Makefile 6.9 KB

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