-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
93 lines (74 loc) · 2.71 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
#
# Makefile for StarWars game
#
# It is likely that default C compiler is already gcc, but explicitly
# set, just to be sure
CC = g++
# The Target Binary Program
TARGET = StarWars
# The Directories, Source, Includes, Objects, Binary and Resources
SRCDIR = src
INCDIR = inc
OBJDIR = obj
TARGETDIR = bin
RESDIR = res
SRCEXT = cpp
DEPEXT = d
OBJEXT = o
# Flags, Libraries and Includes
# The CFLAGS variable sets compile flags for g++:
# -g Compile with debug information
# -Wall Give verbose compiler warnings
# -std=c++0x Use the C++0x standard definition language
CFLAGS = -g -Wall -std=c++0x
# The LDFLAGS variable sets flags for linker
LFLAGS =
# Libraries and Includes
# -I$(INCDIR) Tells compiler where to look for include files
LIB =
INC = -I$(INCDIR)
INCDEP = -I$(INCDIR)
#---------------------------------------------------------------------------------
#DO NOT EDIT BELOW THIS LINE
#---------------------------------------------------------------------------------
# Source files are detected via shell find command
SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
OBJECTS := $(patsubst $(SRCDIR)/%,$(OBJDIR)/%,$(SOURCES:.$(SRCEXT)=.$(OBJEXT)))
# Default Make
all: resources $(TARGET)
# Remake (Cleaner + Make)
remake: cleaner all
# Copy Resources from Resources Directory to Target Directory
resources: directories
#@cp $(RESDIR)/* $(TARGETDIR)/
# Make the Directories
directories:
@mkdir -p $(TARGETDIR)
@mkdir -p $(OBJDIR)
# Clean only Objects
clean:
@$(RM) -rf $(OBJDIR)
# Full Clean, Objects and Binaries
cleaner: clean
@$(RM) -rf $(TARGETDIR)
# Pull in dependency info for *existing* .o files
-include $(OBJECTS:.$(OBJEXT)=.$(DEPEXT))
# Link
$(TARGET): $(OBJECTS)
$(CC) -o $(TARGETDIR)/$(TARGET) $^ $(LIB)
# Compile project and automatically generate a dependency file for each
# object. This means that modification of headers and inline files will trigger
# recompilation of files which are dependent.
$(OBJDIR)/%.$(OBJEXT): $(SRCDIR)/%.$(SRCEXT)
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(INC) -c -o $@ $<
@$(CC) $(CFLAGS) $(INCDEP) -MM $(SRCDIR)/$*.$(SRCEXT) > $(OBJDIR)/$*.$(DEPEXT)
@cp -f $(OBJDIR)/$*.$(DEPEXT) $(OBJDIR)/$*.$(DEPEXT).tmp
@sed -e 's|.*:|$(OBJDIR)/$*.$(OBJEXT):|' < $(OBJDIR)/$*.$(DEPEXT).tmp > $(OBJDIR)/$*.$(DEPEXT)
@sed -e 's/.*://' -e 's/\\$$//' < $(OBJDIR)/$*.$(DEPEXT).tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $(OBJDIR)/$*.$(DEPEXT)
@rm -f $(OBJDIR)/$*.$(DEPEXT).tmp
# Non-File Targets
.PHONY: all remake clean cleaner resources
# Sources
# https://stackoverflow.com/questions/5178125/how-to-place-object-files-in-separate-subdirectory
# http://scottmcpeak.com/autodepend/autodepend.html