forked from lukaus/antfarm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
189 lines (157 loc) · 4.29 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
CFLAGS =
CXXFLAGS = -Wpedantic -Wall -Wextra -g -std=c++17
CPPFLAGS = -DSFML
LDFLAGS = -static-libstdc++
LDLIBS = -lsfml-system -lsfml-window -lsfml-graphics
# source directory
SRC := src
# where to find additional c++ source and header files
# make sure to use the $(SLASH) variable for the directory seperator if
# a subdirectory is included
# example: dir$(SLASH)nextdir
cppdirs =
# a list of headers to pre-compile
pchfiles =
# output directory
BUILD := build
# name of output program
program = antfarm
# autodetect os
OSTARGET ?= UNKNOWN
ifeq ($(OSTARGET),UNKNOWN)
ifeq ($(OS),Windows_NT)
OSTARGET := WINDOWS
else
UNAME := $(shell uname -s)
ifeq ($(UNAME),Linux)
OSTARGET := LINUX
endif
ifeq ($(UNAME),Darwin)
OSTARGET := MACOSX
endif
endif
endif
ifeq ($(OSTARGET),LINUX)
# OS specific options
CFLAGS +=
CXXFLAGS += -I/usr/include $(addprefix -I,$(INCDIRS))
CPPFLAGS +=
LDFLAGS += -L/usr/lib
LDLIBS +=
RM := rm -f
RMDIR := rm -rf
MKDIR := mkdir -p
SLASH = /
CP := cp
PREFIX ?= /usr/local
# compiler/linker programs
CC := gcc
CXX := g++
CPP := g++
LD := g++
# extension of output program
#program +=
endif
ifeq ($(OSTARGET),MACOSX)
# OS specific options
CFLAGS +=
CXXFLAGS += -I/usr/include $(addprefix -I,$(INCDIRS))
CPPFLAGS +=
LDFLAGS += -L/usr/lib
LDLIBS +=
RM := rm -f
RMDIR := rm -rf
MKDIR := mkdir -p
CP := cp
SLASH = /
PREFIX ?= /usr/local
# compiler/linker programs
CC := gcc
CXX := g++
CPP := g++
LD := g++
# extension of output program
#program +=
endif
ifeq ($(OSTARGET),WINDOWS)
# OS specific options
CFLAGS +=
CXXFLAGS += -Iinclude $(addprefix -I,$(INCDIRS))
CPPFLAGS +=
LDFLAGS += -Llib
LDLIBS += -lmingw32
RM := del /F/Q
RMDIR := rmdir /S/Q
MKDIR := mkdir
CP := robocopy
SLASH = \\
PREFIX ?=
# compiler/linker programs
CC := gcc
CXX := g++
CPP := g++
LD := g++
# extension of output program
program := $(addsuffix .exe,$(program))
endif
INCDIRS = $(SRC) $(addprefix $(SRC)/,$(cppdirs))
VPATH = $(INCDIRS)
cppsrc = $(wildcard $(SRC)/*.cpp $(addsuffix /*.cpp,$(INCDIRS)))
objects = $(patsubst $(SRC)/%.o,$(BUILD)/%.o,$(cppsrc:.cpp=.o))
depends = $(objects:.o=.d)
gchfiles = $(addsuffix .gch, $(pchfiles))
DESTDIR =
all: $(BUILD)/$(program)
@echo build complete!
# build single file
single: $(BUILD)/$(in).o
$(BUILD)/$(program): $(objects)
@$(LD) -o $@ $^ $(LDFLAGS) $(LDLIBS)
@echo linking "$^" into "$@" using these libraries: "$(LDLIBS)"
$(objects): $(gchfiles)
$(BUILD)/%.o: %.cpp
@$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
@echo compiling "$<" to "$@" with $(CXX)
%.hpp.gch: %.hpp
@$(CXX) $(CPPFLAGS) $(CXXFLAGS) $<
@echo precompiling header "$<" to "$@" with $(CXX)
$(objects) $(depends): | $(BUILD)
$(BUILD):
@$(MKDIR) $(BUILD) $(addprefix $(BUILD)$(SLASH),$(cppdirs))
@echo creating directories
# rule to generate a dependency file
$(BUILD)/%.d: %.cpp
@$(CPP) $(CXXFLAGS) $< -MM -MT $(@:.d=.o) >$@
@echo generating dependencies for "$<"
# include all dependency files in the makefile
-include $(depends)
.PHONY: clean install uninstall
clean:
# $(RM) $(subst /,$(SLASH),$(objects)) $(subst /,$(SLASH),$(depends)) $(subst /,$(SLASH),$(BUILD)/$(program))
@echo cleaning...
@$(RMDIR) $(BUILD)
@$(RM) $(SRC)$(SLASH)*.gch
@echo done.
install: $(BUILD)/$(program)
ifeq ($(OSTARGET),WINDOWS)
-$(CP) /S $(BUILD) $(DESTDIR)$(PREFIX)bin $(program)
-$(CP) /S data $(DESTDIR)$(PREFIX)bin$(SLASH)data
-$(CP) ./ $(DESTDIR)$(PREFIX)bin *.dll
else
$(MKDIR) $(DESTDIR)$(PREFIX)/bin/$(program)
$(CP) $< $(DESTDIR)$(PREFIX)/bin/$(program)
$(CP) -r ./data $(DESTDIR)$(PREFIX)/bin/$(program)
endif
uninstall:
ifeq ($(OSTARGET), WINDOWS)
$(RMDIR) $(DESTDIR)$(PREFIX)bin
else
$(RMDIR) $(DESTDIR)$(PREFIX)$(SLASH)bin$(SLASH)$(program)
endif
help:
@echo Commands:
@echo make all ---------------------------------- builds the program and puts all the output files in a directory called build
@echo make single in="<path-to-file/file>" ------ builds only a single file (omit the .cpp or .c extension and ignore the quotes as well)
@echo make install ------------------------------ builds the program just like make all and installs the final files to a directory
@echo make uninstall ---------------------------- will remove all the files from the install directory
@echo make clean -------------------------------- will remove the build directory