9c22aba9ccb2852235cf071626406f93b0f8daba
[rocksndiamonds.git] / src / Makefile
1 #=============================================================================#
2 # Makefile for Rocks'n'Diamonds                                               #
3 # (c) 1995-2002 Holger Schemel, info@artsoft.org                              #
4 #=============================================================================#
5
6 .EXPORT_ALL_VARIABLES:
7
8 ifndef PLATFORM                 # platform not specified -- try auto detection
9 ifdef COMSPEC
10 PLATFORM = msdos
11 else
12 PLATFORM = unix
13 endif
14 endif
15
16 ifdef X11_PATH                  # path to X11 specified by top level Makefile
17 XINC_PATH = $(X11_PATH)/include
18 XLIB_PATH = $(X11_PATH)/lib
19 X11_INCL = -I$(XINC_PATH)
20 X11_LIBS = -L$(XLIB_PATH)
21 endif
22
23 AR = ar
24 RANLIB = ranlib
25
26 BMP2ICO = bmp2ico
27 WINDRES = windres
28
29 ifeq ($(PLATFORM),msdos)        # MS-DOS native compiling
30
31 RM = del
32
33 PROGBASE = rocks
34 PROGNAME = ../$(PROGBASE).exe
35
36 SYS_CFLAGS = -DTARGET_X11
37 SYS_LDFLAGS = -s -lalleg
38
39 else                            # Unix or cross-compiling for MS-DOS and Win32
40
41 RM = rm -f
42
43 PROGBASE = rocksndiamonds
44 PROGNAME = ../$(PROGBASE)
45
46 ifeq ($(PLATFORM),solaris)
47 EXTRA_LDFLAGS = -lnsl -lsocket -R$(XLIB_PATH)
48 PLATFORM = unix
49 endif
50
51 ifeq ($(PLATFORM),macosx)
52 PLATFORM = unix
53 TARGET=sdl
54 endif
55
56 ifeq ($(PLATFORM),unix)
57 PROFILING_FLAGS = -pg
58 endif
59
60 ifeq ($(PLATFORM),cross-msdos)
61 PROGBASE = rocks
62 PROGNAME = ../$(PROGBASE).exe
63 TARGET = allegro
64 endif
65
66 ifeq ($(PLATFORM),cross-win32)
67 PROGNAME = ../$(PROGBASE).exe
68 TARGET = sdl
69 endif
70
71 ifeq ($(TARGET),x11)
72 SYS_CFLAGS  = -DTARGET_X11 $(X11_INCL)
73 SYS_LDFLAGS = $(X11_LIBS) -lX11
74 endif
75
76 ifeq ($(TARGET),sdl)
77 SYS_CFLAGS  = -DTARGET_SDL $(shell sdl-config --cflags)
78 SYS_LDFLAGS = -lSDL_image -lSDL_mixer $(shell sdl-config --libs)
79 endif
80
81 ifeq ($(TARGET),allegro)
82 SYS_CFLAGS = -DTARGET_ALLEGRO -I$(CROSS_PATH_MSDOS)/include
83 SYS_LDFLAGS = -lalleg
84 endif
85
86 endif                           # (PLATFORM != msdos)
87
88
89 ifdef RO_GAME_DIR               # path to read-only game data specified
90 CONFIG_RO_GAME_DIR = -DRO_GAME_DIR="\"$(RO_GAME_DIR)\""
91 endif
92
93 ifdef RW_GAME_DIR               # path to writable game data specified
94 CONFIG_RW_GAME_DIR = -DRW_GAME_DIR="\"$(RW_GAME_DIR)\""
95 endif
96
97 ifdef SCORE_ENTRIES             # number of score entries per player specified
98 CONFIG_SCORE_ENTRIES = -D$(SCORE_ENTRIES)
99 endif
100
101 CONFIG_GAME_DIR = $(CONFIG_RO_GAME_DIR) $(CONFIG_RW_GAME_DIR)
102
103
104 CONFIG = $(CONFIG_GAME_DIR) $(CONFIG_SCORE_ENTRIES) $(JOYSTICK)
105 DEBUG = -DDEBUG -g
106 # PROFILING = $(PROFILING_FLAGS)
107
108 # OPTIONS = $(DEBUG) -Wall                      # only for debugging purposes
109 OPTIONS = $(DEBUG) -O3 -Wall                    # only for debugging purposes
110 # OPTIONS = $(DEBUG) -Wall -ansi -pedantic      # only for debugging purposes
111 # OPTIONS = -O3 -Wall -ansi -pedantic
112 # OPTIONS = -O3 -Wall
113 # OPTIONS = -O3
114 # OPTIONS = -DSYSV -Ae                          # may be needed for HP-UX
115
116 ifdef BUILD_DIST                                # distribution build
117 OPTIONS = -O3 -Wall
118 endif
119
120 CFLAGS = $(OPTIONS) $(SYS_CFLAGS) $(CONFIG)
121 LDFLAGS = $(SYS_LDFLAGS) $(EXTRA_LDFLAGS) -lm
122
123
124 SRCS =  main.c          \
125         init.c          \
126         config.c        \
127         events.c        \
128         tools.c         \
129         screens.c       \
130         game.c          \
131         editor.c        \
132         files.c         \
133         tape.c          \
134         cartoons.c      \
135         network.c       \
136         netserv.c
137
138 OBJS =  main.o          \
139         init.o          \
140         config.o        \
141         events.o        \
142         tools.o         \
143         screens.o       \
144         game.o          \
145         editor.o        \
146         files.o         \
147         tape.o          \
148         cartoons.o      \
149         network.o       \
150         netserv.o
151
152 TIMESTAMP_FILE = conftime.h
153
154 LIBDIR = libgame
155 LIBGAME = $(LIBDIR)/libgame.a
156
157 ICONBASE = windows_icon
158 ifeq ($(PLATFORM),cross-win32)
159 ICON32X32 = ../graphics/$(ICONBASE)_32x32.bmp
160 ICON = $(ICONBASE).o
161 endif
162
163
164 all: libgame_dir $(PROGNAME)
165
166 $(PROGNAME): $(LIBGAME) $(TIMESTAMP_FILE) $(OBJS) $(ICON)
167         $(CC) $(PROFILING) $(OBJS) $(ICON) $(LIBGAME) $(LDFLAGS) -o $(PROGNAME)
168
169 libgame_dir:
170         @$(MAKE) -C $(LIBDIR)
171 $(LIBGAME):
172         @$(MAKE) -C $(LIBDIR)
173
174 $(TIMESTAMP_FILE): $(SRCS) $(LIBGAME)
175         @date '+"[%Y-%m-%d %H:%M]"' \
176         | sed -e 's/^/#define COMPILE_DATE_STRING /' \
177         > $(TIMESTAMP_FILE)
178
179 $(ICON):
180         $(BMP2ICO) -transparent $(ICONBASE).ico $(ICON32X32)
181         echo "$(ICONBASE) ICON $(ICONBASE).ico" | $(WINDRES) -o $(ICON)
182
183 .c.o:
184         $(CC) $(PROFILING) $(CFLAGS) -c $*.c
185
186 clean-obj:
187         $(MAKE) -C $(LIBDIR) clean
188         $(RM) $(OBJS)
189         $(RM) $(LIBGAME)
190
191 clean-ico:
192         $(RM) $(ICONBASE).ico
193         $(RM) $(ICONBASE).o
194
195 clean-bin:
196         $(RM) $(PROGNAME)
197         $(RM) ../*.exe
198
199 clean: clean-obj clean-ico clean-bin
200
201
202 #-----------------------------------------------------------------------------#
203 # development only stuff                                                      #
204 #-----------------------------------------------------------------------------#
205
206 dist-clean: clean-obj
207
208 depend:
209         $(MAKE) -C $(LIBDIR) depend
210         for i in $(SRCS); do $(CPP) $(CFLAGS) -M $$i; done > .depend
211
212 ifeq (.depend,$(wildcard .depend))
213 include .depend
214 endif