1include config.mk
2
3cflags := -Isrc/brogue -Isrc/platform -std=c99 \
4	-Wall -Wpedantic -Werror=implicit -Wno-parentheses -Wno-unused-result \
5	-Wformat -Werror=format-security -Wformat-overflow=0 -Wformat-truncation=0
6libs := -lm
7cppflags := -DDATADIR=$(DATADIR)
8
9sources := $(wildcard src/brogue/*.c) $(addprefix src/platform/,main.c platformdependent.c)
10
11ifeq ($(RELEASE),YES)
12	extra_version :=
13else
14	extra_version := $(shell bash tools/git-extra-version)
15endif
16cppflags += -DBROGUE_EXTRA_VERSION='"$(extra_version)"'
17
18ifeq ($(TERMINAL),YES)
19	sources += $(addprefix src/platform/,curses-platform.c term.c)
20	cppflags += -DBROGUE_CURSES
21	libs += -lncurses
22endif
23
24ifeq ($(GRAPHICS),YES)
25	sources += $(addprefix src/platform/,sdl2-platform.c tiles.c)
26	cflags += $(shell $(SDL_CONFIG) --cflags)
27	cppflags += -DBROGUE_SDL
28	libs += $(shell $(SDL_CONFIG) --libs) -lSDL2_image
29endif
30
31ifeq ($(WEBBROGUE),YES)
32	sources += $(addprefix src/platform/,web-platform.c)
33	cppflags += -DBROGUE_WEB
34endif
35
36ifeq ($(MAC_APP),YES)
37	cppflags += -DSDL_PATHS
38endif
39
40ifeq ($(DEBUG),YES)
41	cflags += -g -Og
42	cppflags += -DENABLE_PLAYBACK_SWITCH
43else
44	cflags += -O2
45endif
46
47objects := $(sources:.c=.o)
48
49.PHONY: clean
50
51%.o: %.c src/brogue/Rogue.h src/brogue/IncludeGlobals.h
52	$(CC) $(cppflags) $(CPPFLAGS) $(cflags) $(CFLAGS) -c $< -o $@
53
54bin/brogue: $(objects)
55	$(CC) $(cflags) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(libs) $(LDLIBS)
56
57windows/icon.o: windows/icon.rc
58	windres $< $@
59
60bin/brogue.exe: $(objects) windows/icon.o
61	$(CC) $(cflags) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(libs) $(LDLIBS)
62	mt -manifest windows/brogue.exe.manifest '-outputresource:bin/brogue.exe;1'
63
64clean:
65	$(RM) src/brogue/*.o src/platform/*.o windows/icon.o bin/brogue{,.exe}
66
67
68# Release archives
69
70common_bin := bin/assets bin/keymap.txt
71
72define make_release_base
73	mkdir $@
74	cp README.md $@/README.txt
75	cp CHANGELOG.md $@/CHANGELOG.txt
76	cp LICENSE.txt $@
77endef
78
79# Flatten bin/ in the Windows archive
80BrogueCE-windows: bin/brogue.exe
81	$(make_release_base)
82	cp -r $(common_bin) bin/{brogue.exe,brogue-cmd.bat} $@
83
84BrogueCE-macos: Brogue.app
85	$(make_release_base)
86	cp -r Brogue.app $@/"Brogue CE.app"
87
88BrogueCE-linux: bin/brogue
89	$(make_release_base)
90	cp brogue $@
91	cp -r --parents $(common_bin) bin/brogue $@
92	cp linux/make-link-for-desktop.sh $@
93
94
95# macOS app bundle
96
97# $* is the matched %
98icon_%.png: bin/assets/icon.png
99	convert $< -resize $* $@
100
101macos/Brogue.icns: icon_32.png icon_128.png icon_256.png icon_512.png
102	png2icns $@ $^
103	$(RM) $^
104
105Brogue.app: bin/brogue
106	mkdir -p $@/Contents/{MacOS,Resources}
107	cp macos/Info.plist $@/Contents
108	cp bin/brogue $@/Contents/MacOS
109	cp -r macos/Brogue.icns bin/assets $@/Contents/Resources
110
111macos/sdl2.rb:
112	curl -L 'https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/sdl2.rb' >$@
113	patch $@ macos/sdl2-deployment-target.patch
114