summaryrefslogtreecommitdiff
path: root/Makefile
blob: 5aa76de70398707601ace3c7e667b04e63bbf4b9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
CACHED = $(shell ls | grep Makefile.cache)
ifeq ($(findstring Makefile.cache,$(CACHED)), Makefile.cache)
MKDEF = $(shell cat Makefile.cache)
else

CC = gcc -pipe
# CC = g++ --pipe

MAKE = make
# MAKE = gmake

OPT = -g
OPT += -O2
# OPT += -O3
# OPT += -mmmx
# OPT += -msse
# OPT += -msse2
# OPT += -msse3
# OPT += -rdynamic
OPT += -ffast-math
# OPT += -fbounds-checking
# OPT += -fstack-protector
# OPT += -fomit-frame-pointer
OPT += -Wall -Wno-sign-compare
# Uncomment this one if you are using GCC 4.X
# OPT += -Wno-unused-parameter -Wno-pointer-sign
# OPT += -DMAPREGSQL
# OPT += -DCHRIF_OLDINFO
# OPT += -DPCRE_SUPPORT
# OPT += -DGCOLLECT
# OPT += -DMEMWATCH
# OPT += -DDMALLOC -DDMALLOC_FUNC_CHECK
# OPT += -DBCHECK

# LIBS += -lgc
# LIBS += -ldmalloc
# LIBS += -L/usr/local/lib -lpcre

PLATFORM = $(shell uname)

ifeq ($(findstring Linux,$(PLATFORM)), Linux)
   LIBS += -ldl
endif

ifeq ($(findstring SunOS,$(PLATFORM)), SunOS)
   LIBS += -lsocket -lnsl -ldl
   MAKE = gmake
endif

ifeq ($(findstring FreeBSD,$(PLATFORM)), FreeBSD)
   MAKE = gmake
   OS_TYPE = -D__FREEBSD__
endif

ifeq ($(findstring NetBSD,$(PLATFORM)), NetBSD)
   MAKE = gmake
   OS_TYPE = -D__NETBSD__
endif

ifeq ($(findstring CYGWIN,$(PLATFORM)), CYGWIN)
   OPT += -DFD_SETSIZE=4096
   ifeq ($(findstring mingw,$(shell gcc --version)), mingw)
      IS_MINGW = 1
      OS_TYPE = -DMINGW
      LIBS += -L../.. -lwsock32
   else
      OS_TYPE = -DCYGWIN
   endif
endif

CFLAGS = $(OPT) -I../common $(OS_TYPE)

ifdef SQLFLAG
  ifdef IS_MINGW
    CFLAGS += -I../mysql
    LIBS += -lmysql
  else
    MYSQLFLAG_CONFIG = $(shell which mysql_config)
    ifeq ($(findstring /,$(MYSQLFLAG_CONFIG)), /)
      MYSQLFLAG_VERSION = $(shell $(MYSQLFLAG_CONFIG) --version | sed s:\\..*::)
      ifeq ($(findstring 5,$(MYSQLFLAG_VERSION)), 5)
        MYSQLFLAG_CONFIG_ARGUMENT = --include
      else
        MYSQLFLAG_CONFIG_ARGUMENT = --cflags
      endif
      CFLAGS += $(shell $(MYSQLFLAG_CONFIG) $(MYSQLFLAG_CONFIG_ARGUMENT))
      LIBS += $(shell $(MYSQLFLAG_CONFIG) --libs)
    else
      CFLAGS += -I/usr/local/include/mysql
      LIBS += -L/usr/local/lib/mysql -lmysqlclient
    endif
  endif
endif

ifneq ($(findstring -lz,$(LIBS)), -lz)
   LIBS += -lz
endif
ifneq ($(findstring -lm,$(LIBS)), -lm)
   LIBS += -lm
endif

MKDEF = CC="$(CC)" CFLAGS="$(CFLAGS)" LIB_S="$(LIBS)"

endif

.PHONY: txt sql common login login_sql char char_sql map map_sql ladmin converters \
	addons plugins tools webserver clean zlib depend

all: txt

txt : Makefile.cache conf common login char map ladmin

ifdef SQLFLAG
sql: Makefile.cache conf common login_sql char_sql map_sql
else
sql:
	$(MAKE) SQLFLAG=1 $@
endif

conf:
	cp -r conf-tmpl conf
	rm -rf conf/.svn conf/*/.svn
	cp -r save-tmpl save
	rm -rf save/.svn

common: src/common/GNUmakefile
	$(MAKE) -C src/$@ $(MKDEF)

login: src/login/GNUmakefile common
	$(MAKE) -C src/$@ $(MKDEF) txt

char: src/char/GNUmakefile common
	$(MAKE) -C src/$@ $(MKDEF) txt

map: src/map/GNUmakefile common
	$(MAKE) -C src/$@ $(MKDEF) txt

login_sql: src/login_sql/GNUmakefile common
	$(MAKE) -C src/$@ $(MKDEF) sql

char_sql: src/char_sql/GNUmakefile common
	$(MAKE) -C src/$@ $(MKDEF) sql

map_sql: src/map/GNUmakefile common
	$(MAKE) -C src/map $(MKDEF) sql

ladmin: src/ladmin/GNUmakefile common
	$(MAKE) -C src/$@ $(MKDEF)

plugins addons: src/plugins/GNUmakefile common
	$(MAKE) -C src/plugins $(MKDEF)

webserver:
	$(MAKE) -C src/$@ $(MKDEF)

tools:
	$(MAKE) -C src/tool $(MKDEF)
	
ifdef SQLFLAG
converters: src/txt-converter/GNUmakefile common
	$(MAKE) -C src/txt-converter $(MKDEF)
else
converters:
	$(MAKE) SQLFLAG=1 $@
endif

zlib:
	$(MAKE) -C src/$@ $(MKDEF)

clean: src/common/GNUmakefile src/login/GNUmakefile src/login_sql/GNUmakefile \
	src/char/GNUmakefile src/char_sql/GNUmakefile src/map/GNUmakefile \
	src/ladmin/GNUmakefile src/plugins/GNUmakefile src/txt-converter/GNUmakefile
	rm -f Makefile.cache
	$(MAKE) -C src/common $@
	$(MAKE) -C src/login $@
	$(MAKE) -C src/login_sql $@
	$(MAKE) -C src/char $@
	$(MAKE) -C src/char_sql $@
	$(MAKE) -C src/map $@
	$(MAKE) -C src/ladmin $@
	$(MAKE) -C src/plugins $@
	$(MAKE) -C src/zlib $@
	$(MAKE) -C src/txt-converter $@

depend: src/common/GNUmakefile src/login/GNUmakefile src/login_sql/GNUmakefile \
	src/char/GNUmakefile src/char_sql/GNUmakefile src/map/GNUmakefile \
	src/ladmin/GNUmakefile src/plugins/GNUmakefile src/txt-converter/GNUmakefile
	cd src/common; makedepend -fGNUmakefile -pobj/ -Y. *.c; cd ../..;
	cd src/login; makedepend -DTXT_ONLY -fGNUmakefile -Y. -Y../common *.c; cd ../..;
	cd src/login_sql; makedepend -fGNUmakefile -Y. -Y../common *.c; cd ../..;
	cd src/char; makedepend -DTXT_ONLY -fGNUmakefile -Y. -Y../common *.c; cd ../..;
	cd src/char_sql; makedepend -fGNUmakefile -Y. -Y../common *.c; cd ../..;
	cd src/map; makedepend -DTXT_ONLY -fGNUmakefile -ptxtobj/ -Y. -Y../common *.c; cd ../..;
	cd src/map; makedepend -fGNUmakefile -a -psqlobj/ -Y. -Y../common *.c; cd ../..;
	cd src/ladmin; makedepend -fGNUmakefile -Y. -Y../common *.c; cd ../..;
	cd src/txt-converter; makedepend -DTXT_SQL_CONVERT -fGNUmakefile -Y. -Y../common *.c; cd ../..;
	$(MAKE) -C src/plugins $@

Makefile.cache:
	printf "$(subst ",\",$(MKDEF))" > Makefile.cache

src/%/GNUmakefile: src/%/Makefile
	sed -e 's/$$>/$$^/' $< > $@

src/common/GNUmakefile: src/common/Makefile
src/login/GNUmakefile: src/login/Makefile
src/login_sql/GNUmakefile: src/login_sql/Makefile
src/char/GNUmakefile: src/char/Makefile
src/char_sql/GNUmakefile: src/char_sql/Makefile
src/map/GNUmakefile: src/map/Makefile
src/plugins/GNUmakefile: src/plugins/Makefile
src/ladmin/GNUmakefile: src/ladmin/Makefile
src/txt-converter/GNUmakefile: src/txt-converter/Makefile

install:	conf/%.conf conf/%.txt
	$(shell mkdir -p /opt/eathena/bin/)
	$(shell mkdir -p /opt/eathena/etc/eathena/)
	$(shell mkdir -p /opt/eathena/var/log/eathena/)
	$(shell mv save /opt/eathena/etc/eathena/save)
	$(shell mv db /opt/eathena/etc/eathena/db)
	$(shell mv conf /opt/eathena/etc/eathena/conf)
	$(shell mv npc /opt/eathena/etc/eathena/npc)
	$(shell mv log/* /opt/eathena/var/log/eathena/)
	$(shell cp *-server* /opt/eathena/bin/)
	$(shell cp ladmin /opt/eathena/bin/)
	$(shell ln -s /opt/eathena/etc/eathena/save/ /opt/eathena/bin/)
	$(shell ln -s /opt/eathena/etc/eathena/db/ /opt/eathena/bin/)
	$(shell ln -s /opt/eathena/etc/eathena/conf/ /opt/eathena/bin/)
	$(shell ln -s /opt/eathena/etc/eathena/npc/ /opt/eathena/bin/)
	$(shell ln -s /opt/eathena/var/log/eathena/ /opt/eathena/bin/log)

bin-clean:
	$(shell rm /opt/eathena/bin/login-server*)
	$(shell rm /opt/eathena/bin/char-server*)
	$(shell rm /opt/eathena/bin/map-server*)
	$(shell rm /opt/eathena/bin/ladmin)

uninstall:
	bin-clean
	$(shell rm /opt/eathena/bin/save)
	$(shell rm /opt/eathena/bin/db)
	$(shell rm /opt/eathena/bin/conf)
	$(shell rm /opt/eathena/bin/npc)
	$(shell rm /opt/eathena/bin/log)
	$(shell rm -rf /opt/eathena/etc/eathena)
	$(shell rm -rf /opt/eathena/var/log/eathena)