1# File: Makefile.sdl2
2# Makefile for compiling Angband with SDL2.
3#
4# This makefile requires GNU make.
5#
6# This makefile is intended for use with Unix machines that have SDL2 library.
7# The video subsystem requires libsdl2, libsdl2-ttf and libsdl2-image.
8# The sound subsystem requires libsdl2 and libsdl2-mixer.
9#
10# If you want only video (but not sound), use it like this:
11# (from angband directory)
12#
13# cd src
14# make -f Makefile.msys2.sdl
15#
16# TODO: sound is not working for windows build
17#
18
19# By default, copy the executable to ../ so that
20# you don't find yourself debugging a stale copy.
21.PHONY: default
22default: install
23
24# Support SDL2 frontend, link all dependencies statically
25# freetype and harfbuzz has Circular dependency
26VIDEO_sdl2 := -DUSE_SDL2 \
27	$(shell sdl2-config --cflags) \
28	$(shell sdl2-config --static-libs) \
29	-lSDL2_ttf -lSDL2_image \
30	-ltiff \
31	-lzstd \
32	-llzma \
33	-lwebp \
34	-lfreetype \
35	-lharfbuzz \
36	-lfreetype \
37	-lbrotlidec-static \
38	-lbrotlicommon-static \
39	-lgraphite2 \
40	-lpng \
41	-ljpeg \
42	-lbz2 \
43	-lintl \
44	-lrpcrt4 \
45	-lz \
46	-lVersion \
47	-lstdc++ \
48	-lImm32 \
49	-lhid \
50	-lsetupapi \
51	-lole32 \
52	-loleaut32 \
53	-lwinmm \
54
55## Support SDL_mixer for sound, doesn't work yet
56#SOUND_sdl2 := -DSOUND_SDL -DSOUND \
57#	$(shell sdl2-config --cflags) \
58#	$(shell sdl2-config --libs) -lSDL2_mixer
59
60# Compiler to use
61CC := gcc
62
63# Flags to use in compilation
64CFLAGS := -std=c99 \
65	-g \
66	-O2 \
67	-W -Wall -Wextra -Wno-unused-parameter -pedantic \
68	-static \
69	-DUSE_PRIVATE_PATHS \
70	-DHAVE_DIRENT_H \
71
72# Linker flags
73LDFLAGS := -lm
74
75# Frontends to compile
76MODULES := $(VIDEO_sdl2)
77
78#ifdef SOUND
79#	MODULES += $(SOUND_sdl2)
80#endif
81
82# Extract CFLAGS and LDFLAGS from the module definitions
83CFLAGS += $(patsubst -l%,,$(MODULES))
84LDFLAGS += $(patsubst -D%,,$(patsubst -I%,, $(MODULES)))
85
86# Makefile.inc contains an up-to-date set of object files to compile
87include Makefile.inc
88
89#### Targets and objects #####
90
91# Program name (PROGNAME comes from Makefile.src via Makefile.inc)
92EXE := $(PROGNAME)
93
94# Object definitions (BASEOBJS come from Makefile.inc)
95OBJS := main.o main-sdl2.o $(BASEOBJS)
96
97ifdef SOUND
98	OBJS += snd-sdl.o
99endif
100
101# Build the "Angband" program
102$(EXE): $(OBJS)
103	@printf "%10s %-20s\n" LINK $@
104	@$(CC) -o $(EXE) $(OBJS) $(CFLAGS) $(LDFLAGS)
105
106# Install the game.
107.PHONY: install
108install: ../$(EXE)
109
110../$(EXE): $(EXE)
111	cp $(EXE) ..
112
113# Clean up old junk
114.PHONY: clean
115clean:
116	-rm -f $(OBJS) $(EXE) snd-sdl.o
117
118# Verify module arguments
119.PHONY: args
120args:
121	@echo CFLAGS = $(CFLAGS)
122	@echo "---"
123	@echo LDFLAGS = $(LDFLAGS)
124	@echo "---"
125	@echo MODULES = $(MODULES)
126	@echo "---"
127	@echo INCLUDES = $(INCLUDES)
128
129# Some file dependencies
130%.o: %.c
131	@printf "%10s %-20s\n" CC $<
132	@$(CC) -o $@ -c $< $(CFLAGS)
133