forked from opentyrian/opentyrian
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
160 lines (129 loc) · 4.56 KB
/
Makefile
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
# BUILD SETTINGS ###############################################################
ifneq ($(filter Msys Cygwin, $(shell uname -o)), )
PLATFORM := WIN32
TYRIAN_DIR = C:\\TYRIAN
else
PLATFORM := UNIX
TYRIAN_DIR = $(gamesdir)/tyrian
endif
WITH_NETWORK := true
################################################################################
# see https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html
SHELL = /bin/sh
CC ?= gcc
INSTALL ?= install
PKG_CONFIG ?= pkg-config
VCS_IDREV ?= (git describe --tags || git rev-parse --short HEAD)
INSTALL_PROGRAM ?= $(INSTALL)
INSTALL_DATA ?= $(INSTALL) -m 644
prefix ?= /usr/local
exec_prefix ?= $(prefix)
bindir ?= $(exec_prefix)/bin
datarootdir ?= $(prefix)/share
datadir ?= $(datarootdir)
docdir ?= $(datarootdir)/doc/opentyrian
mandir ?= $(datarootdir)/man
man6dir ?= $(mandir)/man6
man6ext ?= .6
desktopdir ?= $(datarootdir)/applications
icondir ?= $(datarootdir)/icons
# see https://www.pathname.com/fhs/pub/fhs-2.3.html
gamesdir ?= $(datadir)/games
###
TARGET := opentyrian
SRCS := $(wildcard src/*.c)
OBJS := $(SRCS:src/%.c=obj/%.o)
DEPS := $(SRCS:src/%.c=obj/%.d)
###
ifeq ($(WITH_NETWORK), true)
EXTRA_CPPFLAGS += -DWITH_NETWORK
endif
OPENTYRIAN_VERSION := $(shell $(VCS_IDREV) 2>/dev/null && \
touch src/opentyrian_version.h)
ifneq ($(OPENTYRIAN_VERSION), )
EXTRA_CPPFLAGS += -DOPENTYRIAN_VERSION='"$(OPENTYRIAN_VERSION)"'
endif
CPPFLAGS ?= -MMD
CPPFLAGS += -DNDEBUG
CFLAGS ?= -pedantic \
-Wall \
-Wextra \
-Wno-format-truncation \
-Wno-missing-field-initializers \
-O2
LDFLAGS ?=
LDLIBS ?=
ifeq ($(WITH_NETWORK), true)
SDL_CPPFLAGS := $(shell $(PKG_CONFIG) sdl2 SDL2_net --cflags)
SDL_LDFLAGS := $(shell $(PKG_CONFIG) sdl2 SDL2_net --libs-only-L --libs-only-other)
SDL_LDLIBS := $(shell $(PKG_CONFIG) sdl2 SDL2_net --libs-only-l)
else
SDL_CPPFLAGS := $(shell $(PKG_CONFIG) sdl2 --cflags)
SDL_LDFLAGS := $(shell $(PKG_CONFIG) sdl2 --libs-only-L --libs-only-other)
SDL_LDLIBS := $(shell $(PKG_CONFIG) sdl2 --libs-only-l)
endif
ALL_CPPFLAGS = -DTARGET_$(PLATFORM) \
-DTYRIAN_DIR='"$(TYRIAN_DIR)"' \
$(EXTRA_CPPFLAGS) \
$(SDL_CPPFLAGS) \
$(CPPFLAGS)
ALL_CFLAGS = -std=iso9899:1999 \
$(CFLAGS)
ALL_LDFLAGS = $(SDL_LDFLAGS) \
$(LDFLAGS)
ALL_LDLIBS = -lm \
$(SDL_LDLIBS) \
$(LDLIBS)
###
.PHONY : all
all : $(TARGET)
.PHONY : debug
debug : CPPFLAGS += -UNDEBUG
debug : CFLAGS += -Werror
debug : CFLAGS += -O0
debug : CFLAGS += -g3
debug : all
.PHONY : installdirs
installdirs :
mkdir -p $(DESTDIR)$(bindir)
mkdir -p $(DESTDIR)$(docdir)
mkdir -p $(DESTDIR)$(man6dir)
mkdir -p $(DESTDIR)$(desktopdir)
mkdir -p $(DESTDIR)$(icondir)/hicolor/22x22/apps
mkdir -p $(DESTDIR)$(icondir)/hicolor/24x24/apps
mkdir -p $(DESTDIR)$(icondir)/hicolor/32x32/apps
mkdir -p $(DESTDIR)$(icondir)/hicolor/48x48/apps
mkdir -p $(DESTDIR)$(icondir)/hicolor/128x128/apps
.PHONY : install
install : $(TARGET) installdirs
$(INSTALL_PROGRAM) $(TARGET) $(DESTDIR)$(bindir)/
$(INSTALL_DATA) NEWS README $(DESTDIR)$(docdir)/
$(INSTALL_DATA) linux/man/opentyrian.6 $(DESTDIR)$(man6dir)/opentyrian$(man6ext)
$(INSTALL_DATA) linux/opentyrian.desktop $(DESTDIR)$(desktopdir)/
$(INSTALL_DATA) linux/icons/tyrian-22.png $(DESTDIR)$(icondir)/hicolor/22x22/apps/opentyrian.png
$(INSTALL_DATA) linux/icons/tyrian-24.png $(DESTDIR)$(icondir)/hicolor/24x24/apps/opentyrian.png
$(INSTALL_DATA) linux/icons/tyrian-32.png $(DESTDIR)$(icondir)/hicolor/32x32/apps/opentyrian.png
$(INSTALL_DATA) linux/icons/tyrian-48.png $(DESTDIR)$(icondir)/hicolor/48x48/apps/opentyrian.png
$(INSTALL_DATA) linux/icons/tyrian-128.png $(DESTDIR)$(icondir)/hicolor/128x128/apps/opentyrian.png
.PHONY : uninstall
uninstall :
rm -f $(DESTDIR)$(bindir)/$(TARGET)
rm -f $(DESTDIR)$(docdir)/NEWS $(DESTDIR)$(docdir)/README
rm -f $(DESTDIR)$(man6dir)/opentyrian$(man6ext)
rm -f $(DESTDIR)$(desktopdir)/opentyrian.desktop
rm -f $(DESTDIR)$(icondir)/hicolor/22x22/apps/opentyrian.png
rm -f $(DESTDIR)$(icondir)/hicolor/24x24/apps/opentyrian.png
rm -f $(DESTDIR)$(icondir)/hicolor/32x32/apps/opentyrian.png
rm -f $(DESTDIR)$(icondir)/hicolor/48x48/apps/opentyrian.png
rm -f $(DESTDIR)$(icondir)/hicolor/128x128/apps/opentyrian.png
.PHONY : clean
clean :
rm -f $(OBJS)
rm -f $(DEPS)
rm -f $(TARGET)
$(TARGET) : $(OBJS)
$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) -o $@ $^ $(ALL_LDLIBS)
-include $(DEPS)
obj/%.o : src/%.c
@mkdir -p "$(dir $@)"
$(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) -c -o $@ $<