-
Notifications
You must be signed in to change notification settings - Fork 13
/
Makefile
152 lines (122 loc) · 3.99 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
# Makefile for SIDFactoryII linux distribution
#
# Also used to build a 'linux-style' macOS binary for debugging only.
#
# There is a 'proper' macOS Makefile in /macos, which compiles and
# packages a self-contained SIDFactoryII.app, and distribution disk image.
#
# Prerequisites:
# - gnu make
# - g++ (Xcode with command line utilities on macOS)
# - git
# - sdl2
#
# Make an executable:
# make
#
# Make a complete distribution:
# make dist
#
# Clean build artifacts:
# make clean
#
# Build artifacts are in /artifacts
PLATFORM=LINUX
APP_NAME=SIDFactoryII
BUILD_NR= $(shell git show --no-patch --format='%cs').$(shell git rev-parse --short HEAD)
ARTIFACTS_FOLDER=artifacts
DIST_FOLDER=$(ARTIFACTS_FOLDER)/$(APP_NAME)_$(PLATFORM)_$(BUILD_NR)
# SF2 sources
PROJECT_ROOT=./SIDFactoryII
SOURCE=$(PROJECT_ROOT)/source
SRC_TMP=$(PROJECT_ROOT)/main.cpp $(shell find $(SOURCE) -name "*.cpp")
SRC=$(patsubst %miniz_tester.cpp,,$(SRC_TMP))
# Artifacts
EXE=$(ARTIFACTS_FOLDER)/$(APP_NAME)
# Compiler
CC=g++
CC_FLAGS=$(shell sdl2-config --cflags) -I$(SOURCE) -D_SF2_$(PLATFORM) -D_BUILD_NR=\"$(BUILD_NR)\" -std=gnu++14 -g
LINKER_FLAGS=$(shell sdl2-config --libs) -lstdc++ -flto
ifeq ($(PLATFORM),MACOS)
LINKER_FLAGS := $(LINKER_FLAGS) -framework ApplicationServices
endif
ifneq ($(TARGET),DEBUG)
# optimizations, don't play well with debugging
CC_FLAGS := $(CC_FLAGS) -O2 -flto -DNDEBUG
endif
# Rule to compile .o from .cpp
%.o: %.cpp
$(CC) $(CC_FLAGS) -c $< -o $@
# Rule to compile .o from .c
%.o: %.c
gcc -c $< -o $@
# Determine all .o files to be built
OBJ = $(SRC:.cpp=.o) $(SOURCE)/libraries/miniz/miniz.o
# Compile SIDFactoryII
$(EXE): $(OBJ) $(ARTIFACTS_FOLDER) \
$(ARTIFACTS_FOLDER)/drivers \
$(ARTIFACTS_FOLDER)/overlay \
$(ARTIFACTS_FOLDER)/color_schemes \
$(ARTIFACTS_FOLDER)/config/config.ini
$(CC) $(OBJ) $(LINKER_FLAGS) -o $(EXE)
$(ARTIFACTS_FOLDER)/drivers: $(PROJECT_ROOT)/drivers
cp -r $(PROJECT_ROOT)/drivers $(ARTIFACTS_FOLDER)
$(ARTIFACTS_FOLDER)/overlay: $(PROJECT_ROOT)/overlay
cp -r $(PROJECT_ROOT)/overlay $(ARTIFACTS_FOLDER)
$(ARTIFACTS_FOLDER)/color_schemes: $(PROJECT_ROOT)/color_schemes
cp -r $(PROJECT_ROOT)/color_schemes $(ARTIFACTS_FOLDER)
$(ARTIFACTS_FOLDER)/config/config.ini: $(ARTIFACTS_FOLDER)/config ${PROJECT_ROOT}/config.ini
cp $(PROJECT_ROOT)/config.ini $@
$(ARTIFACTS_FOLDER)/config:
mkdir -p $@
# Create a distribution folder with executables and resources
.PHONY: dist
dist: $(EXE) $(DIST_FOLDER)
strip $(EXE)
mv $(EXE) $(DIST_FOLDER)
mkdir -p ${DIST_FOLDER}/config
mv $(ARTIFACTS_FOLDER)/drivers $(DIST_FOLDER)
mv $(ARTIFACTS_FOLDER)/overlay $(DIST_FOLDER)
mv $(ARTIFACTS_FOLDER)/color_schemes $(DIST_FOLDER)
mv $(ARTIFACTS_FOLDER)/config $(DIST_FOLDER)
cp -r $(PROJECT_ROOT)/music $(DIST_FOLDER)
cp -r dist/documentation $(DIST_FOLDER)
cp $(PROJECT_ROOT)/COPYING $(DIST_FOLDER)
$(ARTIFACTS_FOLDER):
mkdir -p $@
$(DIST_FOLDER):
mkdir -p $@
.PHONY: clean
clean:
rm ${OBJ} || true
rm -rf $(ARTIFACTS_FOLDER) || true
# Local development specific
.PHONY: run
run: $(EXE)
cd $(ARTIFACTS_FOLDER) && ./$(APP_NAME)
.PHONY: debug
debug: $(EXE)
cd $(ARTIFACTS_FOLDER) && lldb $(APP_NAME)
# For local development with ccls, make this file first
compile_commands.json: clean
bear -- make TARGET=DEBUG PLATFORM=$(PLATFORM)
# --- DOCKER BUILDS ---
TMP_CONTAINER=sf2_build_tmp
# Compile with the Ubuntu image
BUILD_IMAGE_UBUNTU=sidfactory2/build-ubuntu
.PHONY: ubuntu
ubuntu:
docker container rm $(TMP_CONTAINER) || true
docker build -t $(BUILD_IMAGE_UBUNTU) .
docker run --name $(TMP_CONTAINER) $(BUILD_IMAGE_UBUNTU)
docker cp $(TMP_CONTAINER):/home/$(ARTIFACTS_FOLDER) .
docker container rm $(TMP_CONTAINER)
# Compile with the Archlinux image
BUILD_IMAGE_ARCHLINUX=sidfactory2/build-archlinux
.PHONY: archlinux
archlinux:
docker container rm $(TMP_CONTAINER) || true
docker build -t $(BUILD_IMAGE_ARCHLINUX) -f Dockerfile.Archlinux .
docker run --name $(TMP_CONTAINER) $(BUILD_IMAGE_ARCHLINUX)
docker cp $(TMP_CONTAINER):/home/$(ARTIFACTS_FOLDER) .
docker container rm $(TMP_CONTAINER)