File: Makefile

package info (click to toggle)
tanks 1.0.1%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,400 kB
  • sloc: cpp: 5,282; makefile: 94
file content (114 lines) | stat: -rw-r--r-- 3,093 bytes parent folder | download | duplicates (2)
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
PROJECT_NAME = tanks

SRC = src
BUILD = build
BIN = $(BUILD)/bin
RESOURCES_DIR = resources

ifeq ($(OS),Windows_NT)
	CC = $(MINGW_HOME)/bin/mingw32-g++.exe
	INCLUDEPATH = -I$(RESOURCES_DIR)/SDL/i686-w64-mingw32/include
	LFLAGS = -mwindows -O
	CFLAGS = -c -Wall
	LIBS = -L$(RESOURCES_DIR)/SDL/i686-w64-mingw32/lib -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_mixer
	APP_RESOURCES = SDL/i686-w64-mingw32/bin/*.dll dll/*.dll font/kongtext.ttf textures/texture.png levels sounds
	RESOURCES = $(APP_RESOURCES) mingw_resources
else
	UNAME_S := $(shell uname -s)
	UNAME_M := $(shell uname -m)

	ifeq ($(UNAME_S),Darwin)
		ifeq ($(UNAME_M),arm64)
			# Mac M1 (Apple Silicon)
			CC = g++
			INCLUDEPATH = -I/opt/homebrew/include
			LIBSPATH = -L/opt/homebrew/lib
		else
			# Mac x86_64 (Intel)
			CC = g++
			INCLUDEPATH = -I/usr/local/include
			LIBSPATH = -L/usr/local/lib
		endif
		LFLAGS = -O
		CFLAGS = -c -Wall -Wno-narrowing -std=c++17
		LIBS = -lSDL2main -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_mixer
		APP_RESOURCES = font/kongtext.ttf textures/texture.png levels sounds
		RESOURCES = $(APP_RESOURCES)
	else
		CC = g++
		INCLUDEPATH =
		LFLAGS = -O
		CFLAGS = -c -Wall -Wno-narrowing -std=c++17 -g
		LIBS = -lSDL2main -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_mixer
		APP_RESOURCES = font/kongtext.ttf textures/texture.png levels sounds
		RESOURCES = $(APP_RESOURCES)
	endif
endif


MODULES = engine engine/sdl app_state objects
SRC_SUBDIRS = $(shell cd $(SRC) && find * -type d)
SRC_DIRS = $(SRC) $(addprefix $(SRC)/,$(SRC_SUBDIRS))
BUILD_DIRS = $(BUILD) $(BIN) $(addprefix $(BUILD)/,$(SRC_SUBDIRS))

SOURCES = $(foreach sdir,$(SRC_DIRS),$(wildcard $(sdir)/*.cpp))
OBJS = $(patsubst $(SRC)/%.cpp,$(BUILD)/%.o,$(SOURCES))

VERSION := $(shell git describe --tags --abbrev=0 | sed -Ee 's/^v|-.*//')

vpath %.cpp $(SRC_DIRS)

all: print $(BUILD_DIRS) $(RESOURCES) compile

print:
	@echo
	@echo VERSION: $(VERSION)
	@echo OS: $(OS)
	@echo SRC: $(SRC)
	@echo SRC_SUBDIRS: $(SRC_SUBDIRS)
	@echo SRC_DIRS: $(SRC_DIRS)
	@echo BUILD_DIRS: $(BUILD_DIRS)
	@echo SOURCES: $(SOURCES)
	@echo RESOURCES: $(RESOURCES)
	@echo OBJS: $(OBJS)
	@echo INCLUDEPATH: $(INCLUDEPATH)
	@echo LIBSPATH: $(LIBSPATH)
	@echo LIBS: $(LIBS)
	@echo LFLAGS: $(LFLAGS)
	@echo

$(BUILD_DIRS):
	mkdir -p $@

compile: $(OBJS)
	$(CC) $(OBJS) $(INCLUDEPATH) $(LIBSPATH) $(LIBS) $(LFLAGS) -o $(BIN)/$(PROJECT_NAME)

build/%.o: $(SRC)/%.cpp
	$(CC) $(CFLAGS) $(INCLUDEPATH) $< -o $@

$(APP_RESOURCES):
	cp -R $(RESOURCES_DIR)/$@ $(BIN)

ifeq ($(OS),Windows_NT)

mingw_resources:
	cp $(MINGW_HOME)/bin/libstdc++-6.dll $(BIN)
	cp $(MINGW_HOME)/bin/libgcc_s_dw2-1.dll $(BIN)

endif

clean:
	rm -rf $(BUILD)
	rm -rf doc

run: all
	cd build/bin && ./Tanks


bump-minor:
	git tag -a $(shell echo $(VERSION) | awk -F. -v OFS=. '{$$2++;print}') -m "Bump minor version to $(shell echo $(VERSION) | awk -F. -v OFS=. '{$$2++;print}')"
	git push --tags

bump-patch:
	git tag -a $(shell echo $(VERSION) | awk -F. -v OFS=. '{$$3++;print}') -m "Bump patch version to $(shell echo $(VERSION) | awk -F. -v OFS=. '{$$3++;print}')"
	git push --tags