-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClientMakefile
More file actions
82 lines (68 loc) · 2.53 KB
/
ClientMakefile
File metadata and controls
82 lines (68 loc) · 2.53 KB
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
# @file ClientMakefile
#
# @author Claus Aranha (caranha@cs.tsukuba.ac.jp)
# @author Guilherme N. Ramos (gnramos@unb.br)
#
# Builds the controller specified by DRIVER argument. This assumes a few things:
# 1) The files are set in the src/DRIVER directory.
# 2) The controller files are DRIVER.h & DRIVER.cpp (extra .h files within the
# folder should work, but any more .cpp files will break things).
#
# The idea is to create .o files and the executable file in the /bin directory.
# After all is done, just start the TORCS server and run the executable to see
# your client race. In theory, everything should work automagically...
#
# Example (assuming you have TORCS running with a race waiting for the clients:
# make -f ClientMakefile DRIVER=SimpleDriver
# ./bin/SimpleDriver
# Set the compiler.
CC = g++
# Set compilation flags.
CXXFLAGS = -Wall
#CXXFLAGS = -Wall -g -D __UDP_CLIENT_VERBOSE__
# UDP Client (in client.cpp) flags.
EXTFLAGS = -D __DRIVER_CLASS__=$(DRIVER) -D __DRIVER_INCLUDE__='"$(DRIVER).h"'
# Set source and target dirs.
TARGET_DIR = bin
SRC_DIR = src
# Client source files.
UDP_CLIENT_DIR = $(SRC_DIR)/client
UDP_CLIENT_SRC = $(wildcard $(UDP_CLIENT_DIR)/*.cpp)
UDP_CLIENT_MAIN = $(UDP_CLIENT_DIR)/client.cpp
UDP_CLIENT_SRC := $(filter-out $(UDP_CLIENT_MAIN), $(UDP_CLIENT_SRC))
# Driver source files.
DRIVER ?= SimpleDriver
DRIVER_DIR = $(SRC_DIR)/$(DRIVER)
DRIVER_SRC = $(wildcard $(DRIVER_DIR)/*.cpp)
DRIVER_SRC := $(DRIVER_SRC) $(UDP_CLIENT_MAIN)
# Auxiliary source files.
UTILS_DIR = $(SRC_DIR)/utils
UTILS_SRC = $(wildcard $(UTILS_DIR)/*.cpp)
# Setup objects.
UDP_CLIENT_OBJS := $(notdir $(UDP_CLIENT_SRC:.cpp=.o))
UTILS_OBJS := $(notdir $(UTILS_SRC:.cpp=.o))
DRIVER_OBJS = $(UDP_CLIENT_OBJS) $(UTILS_OBJS)
DRIVER_OBJS := $(addprefix $(TARGET_DIR)/,$(DRIVER_OBJS))
###########
# Targets #
###########
# Build driver client.
all: target_dir $(DRIVER)
# Build UDP client objects.
$(UDP_CLIENT_OBJS): %.o : $(UDP_CLIENT_DIR)/%.cpp
$(CC) -c $(CXXFLAGS) $< -o $(TARGET_DIR)/$@
# Build auxiliary objects.
$(UTILS_OBJS): %.o : $(UTILS_DIR)/%.cpp
$(CC) -c $(CXXFLAGS) $< -o $(TARGET_DIR)/$@
# Build driver object.
$(DRIVER): $(DRIVER_SRC) $(UDP_CLIENT_OBJS) $(UTILS_OBJS)
$(info Creating $(DRIVER).)
$(CC) $(CXXFLAGS) $(EXTFLAGS) $(DRIVER_SRC) -I$(UDP_CLIENT_DIR) -I$(UTILS_DIR) -I$(DRIVER_DIR) -o $(TARGET_DIR)/$(DRIVER) $(DRIVER_OBJS)
# Build target directory.
target_dir:
@mkdir -p $(TARGET_DIR)
# Cleanup.
clean:
rm -rf $(TARGET_DIR)
find . -name "*~" -exec rm {} \;
find . -name "*.o" -exec rm {} \;