Mac OS X: fix mac command-line build
[crawl:crawl-sdl.git] / Makefile
1 # -*- Makefile -*- for sdl
2
3 ifneq ($(findstring $(MAKEFLAGS),s),s)
4 ifndef V
5         QUIET_CC       = @echo '   ' CC $@;
6         QUIET_AR       = @echo '   ' AR $@;
7         QUIET_RANLIB   = @echo '   ' RANLIB $@;
8         QUIET_INSTALL  = @echo '   ' INSTALL $<;
9         export V
10 endif
11 endif
12
13 uname_S ?= $(shell uname -s)
14
15 # Since Windows builds could be done with MinGW or Cygwin,
16 # set a TARGET_OS_WINDOWS flag when either shows up.
17 ifneq (,$(findstring MINGW,$(uname_S)))
18 TARGET_OS_WINDOWS := YesPlease
19 endif
20 ifneq (,$(findstring CYGWIN,$(uname_S)))
21 TARGET_OS_WINDOWS := YesPlease
22 endif
23
24 SDL_LIB = libSDL.a
25 SDLMAIN_LIB = libSDLmain.a
26 AR    ?= ar
27 CC    ?= gcc
28 RANLIB?= ranlib
29 RM    ?= rm -f
30
31 CFLAGS ?= -O2
32
33 prefix ?= /usr/local
34 libdir := $(prefix)/lib
35 man3dir := $(prefix)/share/man/man3
36 includedir := $(prefix)/include/SDL
37
38 HEADERS = include/*.h
39
40 MAN3_PAGES = docs/man3/*.3
41
42 SDL_SOURCES = \
43     src/*.c \
44     src/audio/*.c \
45     src/cdrom/*.c \
46     src/cpuinfo/*.c \
47     src/events/*.c \
48     src/file/*.c \
49     src/joystick/*.c \
50     src/stdlib/*.c \
51     src/thread/*.c \
52     src/timer/*.c \
53     src/video/*.c \
54         src/audio/disk/*.c \
55         src/audio/dummy/*.c \
56         src/video/dummy/*.c \
57         src/joystick/dummy/*.c \
58         src/cdrom/dummy/*.c \
59         src/timer/dummy/*.c \
60         src/loadso/dummy/*.c
61
62 SDLMAIN_SOURCES =
63
64 ifeq ($(uname_S),Linux)
65 SDL_SOURCES += \
66     src/audio/alsa/*.c \
67     src/audio/dma/*.c \
68     src/audio/dsp/*.c \
69     src/audio/esd/*.c \
70     src/cdrom/linux/*.c \
71     src/joystick/linux/*.c \
72     src/loadso/dlopen/*.c \
73     src/thread/pthread/*.c \
74     src/timer/unix/*.c \
75     src/video/dga/*.c \
76     src/video/fbcon/*.c \
77     src/video/Xext/*/*.c \
78     src/video/x11/*.c
79
80 CFLAGS += -D_GNU_SOURCE -D_REENTRANT
81 endif
82
83 ifeq ($(uname_S),Darwin)
84 SDL_SOURCES += \
85     src/audio/macosx/*.c \
86     src/cdrom/macosx/*.c \
87     src/joystick/darwin/*.c \
88     src/loadso/dlopen/*.c \
89     src/thread/pthread/*.c \
90     src/timer/unix/*.c \
91     src/video/quartz/*.m
92
93 SDLMAIN_SOURCES += \
94     src/main/macosx/*.m
95 endif
96
97 ifdef TARGET_OS_WINDOWS
98 SDL_SOURCES += \
99         src/audio/windib/*.c \
100     src/cdrom/win32/*.c \
101     src/joystick/win32/*.c \
102     src/loadso/win32/*.c \
103     src/thread/win32/SDL*.c \
104     src/timer/win32/*.c \
105     src/video/wincommon/*.c \
106     src/video/windib/*.c
107
108 SDLMAIN_SOURCES += \
109     src/main/win32/*.c
110 endif
111
112 SDL_SOURCES := $(shell echo $(SDL_SOURCES))
113 SDLMAIN_SOURCES := $(shell echo $(SDLMAIN_SOURCES))
114 MAN3_PAGES := $(shell echo $(MAN3_PAGES))
115 HEADERS := $(shell echo $(HEADERS))
116
117 HEADERS_INST := $(patsubst include/%,$(includedir)/%,$(HEADERS))
118 MAN3_INST := $(patsubst docs/man3/%,$(man3dir)/%,$(MAN3_PAGES))
119
120 # First handle .c files
121 SDL_OBJECTS := $(patsubst %.c,%.o,$(SDL_SOURCES))
122 SDLMAIN_OBJECTS := $(patsubst %.c,%.o,$(SDLMAIN_SOURCES))
123
124 # Now .m files
125 SDL_OBJECTS := $(patsubst %.m,%.o,$(SDL_OBJECTS))
126 SDLMAIN_OBJECTS := $(patsubst %.m,%.o,$(SDLMAIN_OBJECTS))
127
128 CFLAGS += -I. -Iinclude -DNO_STDIO_REDIRECT
129
130 .PHONY: install
131
132 all: $(SDL_LIB) $(SDLMAIN_LIB)
133
134 $(includedir)/%.h: include/%.h
135         -@if [ ! -d $(includedir)  ]; then mkdir -p $(includedir); fi
136         $(QUIET_INSTALL)cp $< $@
137         @chmod 0644 $@
138
139 $(libdir)/%.a: %.a
140         -@if [ ! -d $(libdir)  ]; then mkdir -p $(libdir); fi
141         $(QUIET_INSTALL)cp $< $@
142         @chmod 0644 $@
143
144 $(man3dir)/%.3: docs/man3/%.3
145         -@if [ ! -d $(man3dir)  ]; then mkdir -p $(man3dir); fi
146         $(QUIET_INSTALL)cp $< $@
147         @chmod 0644 $@
148
149 install: $(MAN3_INST) $(HEADERS_INST) $(libdir)/$(SDL_LIB) $(libdir)/$(SDLMAIN_LIB)
150
151 clean:
152         $(RM) $(SDL_OBJECTS) $(SDLMAIN_OBJECTS) *.a
153
154 distclean: clean
155
156 $(SDL_LIB): $(SDL_OBJECTS)
157         $(QUIET_AR)$(AR) rcu $@ $^
158         $(QUIET_RANLIB)$(RANLIB) $@
159
160 $(SDLMAIN_LIB): $(SDLMAIN_OBJECTS)
161         $(QUIET_AR)$(AR) rcu $@ $^
162         $(QUIET_RANLIB)$(RANLIB) $@
163
164 %.o: %.c
165         $(QUIET_CC)$(CC) $(CFLAGS) -o $@ -c $<
166
167 %.o: %.m
168         $(QUIET_CC)$(CC) $(CFLAGS) -o $@ -c $<