-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
165 lines (132 loc) · 4.59 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
161
162
163
164
165
OS_MAC :=
ifeq ($(shell uname -s),Darwin)
OS_MAC := 1
endif
DESTDIR =
PREFIX = /usr/local
APPNAME = Crystal Tracker
crystaltracker = crystaltracker
crystaltrackerd = crystaltrackerd
ifdef OS_MAC
CXX ?= clang++
else
CXX ?= g++
endif
LD = $(CXX)
RM = rm -rf
srcdir = src
resdir = res
tmpdir = tmp
debugdir = tmp/debug
bindir = bin
pkg-config = PKG_CONFIG_PATH=lib/pkgconfig pkg-config
fltk-config = $(bindir)/fltk-config
CXXFLAGS := -std=c++17 -I$(srcdir) -I$(resdir) $(shell $(fltk-config) --use-images --cxxflags) $(CXXFLAGS)
ifdef OS_MAC
PORTAUDIOLDLIBS := $(shell $(pkg-config) --static --libs-only-other portaudiocpp)
FLTKLDLIBS := $(shell $(fltk-config) --use-images --ldstaticflags)
else
PORTAUDIOLDLIBS := $(shell $(pkg-config) --static --libs-only-l portaudiocpp | sed -E "s/-lportaudio(cpp)?//g")
FLTKLDLIBS := $(shell $(fltk-config) --use-images --ldstaticflags) $(shell $(pkg-config) --libs libpng xpm)
endif
LDFLAGS := lib/libportaudio.a lib/libportaudiocpp.a lib/libopenmpt.a $(PORTAUDIOLDLIBS) $(FLTKLDLIBS) $(LDFLAGS)
RELEASEFLAGS = -DNDEBUG -O3 -flto
DEBUGFLAGS = -DDEBUG -D_DEBUG -O0 -g -ggdb3 -Wall -Wextra -pedantic -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter
COMMON = $(wildcard $(srcdir)/*.h) $(wildcard $(resdir)/*.xpm) $(resdir)/help.html
SOURCES = $(wildcard $(srcdir)/*.cpp)
OBJECTS = $(SOURCES:$(srcdir)/%.cpp=$(tmpdir)/%.o)
DEBUGOBJECTS = $(SOURCES:$(srcdir)/%.cpp=$(debugdir)/%.o)
ifdef OS_MAC
SOURCES_MAC = $(wildcard $(srcdir)/*.mm)
OBJECTS += $(SOURCES_MAC:$(srcdir)/%.mm=$(tmpdir)/%.o)
DEBUGOBJECTS += $(SOURCES_MAC:$(srcdir)/%.mm=$(debugdir)/%.o)
endif
TARGET = $(bindir)/$(crystaltracker)
DEBUGTARGET = $(bindir)/$(crystaltrackerd)
.PHONY: all $(crystaltracker) $(crystaltrackerd) release debug clean appdir appdmg install uninstall
.SUFFIXES: .o .cpp
all: $(crystaltracker)
$(crystaltracker): release
$(crystaltrackerd): debug
release: CXXFLAGS := $(RELEASEFLAGS) $(CXXFLAGS)
release: $(TARGET)
debug: CXXFLAGS := $(DEBUGFLAGS) $(CXXFLAGS)
debug: $(DEBUGTARGET)
$(TARGET): $(OBJECTS)
@mkdir -p $(@D)
$(LD) -o $@ $^ $(CXXFLAGS) $(LDFLAGS)
$(DEBUGTARGET): $(DEBUGOBJECTS)
@mkdir -p $(@D)
$(LD) -o $@ $^ $(CXXFLAGS) $(LDFLAGS)
$(tmpdir)/%.o: $(srcdir)/%.cpp $(COMMON)
@mkdir -p $(@D)
$(CXX) -c $(CXXFLAGS) -o $@ $<
$(debugdir)/%.o: $(srcdir)/%.cpp $(COMMON)
@mkdir -p $(@D)
$(CXX) -c $(CXXFLAGS) -o $@ $<
ifdef OS_MAC
$(tmpdir)/%.o: $(srcdir)/%.mm $(COMMON)
@mkdir -p $(@D)
$(CXX) -c $(CXXFLAGS) -o $@ $<
$(debugdir)/%.o: $(srcdir)/%.mm $(COMMON)
@mkdir -p $(@D)
$(CXX) -c $(CXXFLAGS) -o $@ $<
endif
clean:
$(RM) $(TARGET) $(DEBUGTARGET) $(OBJECTS) $(DEBUGOBJECTS)
ifdef OS_MAC
APPDIR = "$(bindir)/$(APPNAME).app"
APPDMG = "$(bindir)/$(APPNAME).dmg"
CONTENTS = $(APPDIR)/Contents
appdir: release
rm -rf $(APPDIR)
install -d $(CONTENTS)/macOS $(CONTENTS)/Resources
install -m755 $(TARGET) $(CONTENTS)/macOS/crystaltracker
install -m644 $(resdir)/app.icns $(CONTENTS)/Resources/AppIcon.icns
install -m644 $(resdir)/Info.plist $(CONTENTS)/Info.plist
printf 'APPL????' > $(CONTENTS)/PkgInfo
create-dmg = create-dmg
appdmg: appdir
rm -f $(APPDMG)
rm -rf $(APPDMG).dir/
mkdir -p $(APPDMG).dir
cp -a $(APPDIR) $(APPDMG).dir/
$(create-dmg) \
--volname "$(APPNAME)" \
--volicon $(resdir)/app.icns \
--window-pos 200 120 \
--window-size 800 400 \
--icon-size 100 \
--icon "$(APPNAME).app" 200 190 \
--hide-extension "$(APPNAME).app" \
--app-drop-link 600 185 \
$(APPDMG) $(APPDMG).dir/
rm -rf $(APPDMG).dir/
install: appdir
rm -rf "/Applications/$(APPNAME).app"
cp -av $(APPDIR) "/Applications/$(APPNAME).app"
rm -rf $(APPDIR)
uninstall:
rm -rf "/Applications/$(APPNAME).app"
else
DESKTOP = "$(DESTDIR)$(PREFIX)/share/applications/$(APPNAME).desktop"
install: release
mkdir -p $(DESTDIR)$(PREFIX)/bin
cp $(TARGET) $(DESTDIR)$(PREFIX)/bin/$(crystaltracker)
mkdir -p $(DESTDIR)$(PREFIX)/share/pixmaps
cp $(resdir)/app.xpm $(DESTDIR)$(PREFIX)/share/pixmaps/crystaltracker48.xpm
cp $(resdir)/app-icon.xpm $(DESTDIR)$(PREFIX)/share/pixmaps/crystaltracker16.xpm
mkdir -p $(DESTDIR)$(PREFIX)/share/applications
echo "[Desktop Entry]" > $(DESKTOP)
echo "Name=$(APPNAME)" >> $(DESKTOP)
echo "Comment=Edit pokecrystal music and sound effects" >> $(DESKTOP)
echo "Icon=$(PREFIX)/share/pixmaps/crystaltracker48.xpm" >> $(DESKTOP)
echo "Exec=$(PREFIX)/bin/$(crystaltracker)" >> $(DESKTOP)
echo "Type=Application" >> $(DESKTOP)
echo "Terminal=false" >> $(DESKTOP)
uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/$(crystaltracker)
rm -f $(DESTDIR)$(PREFIX)/share/pixmaps/crystaltracker48.xpm
rm -f $(DESTDIR)$(PREFIX)/share/pixmaps/crystaltracker16.xpm
rm -f $(DESKTOP)
endif