forked from frenchbakery/dev_template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
109 lines (83 loc) · 3 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
# the default env configuration that is used when not
# specified in env.mk
CARG =
LARG =
USER = access
HOST = 10.42.0.149
# include environment configuration that includes deployment
# host and user name, compiler flags and other config
include env.mk
# project structure
SRC_DIR = src
INCLUDE_DIR = include
OBJ_DIR = obj
RUN_DIR = run
MOUNT_FOLDER = mount
WORKSPACE_NAME = $(shell basename ${PWD})
# C++ configuration
CC = g++
CFLAGS = -g -I$(INCLUDE_DIR) -I$(SRC_DIR) $(CARG) -std=c++11
LIBS = -lpthread -lwallaby $(LARG)
# files and compliation results
SRC_SOURCES = $(shell find $(SRC_DIR) -name '*.cpp')
SRC_OBJECTS_TEMP = $(patsubst %.cpp,%.o,$(SRC_SOURCES))
SRC_OBJECTS = $(patsubst $(SRC_DIR)/%,$(OBJ_DIR)/src/%,$(SRC_OBJECTS_TEMP))
INCLUDE_SOURCES = $(shell find $(INCLUDE_DIR) -name '*.cpp')
INCLUDE_OBJECTS_TEMP = $(patsubst %.cpp,%.o,$(INCLUDE_SOURCES))
INCLUDE_OBJECTS = $(patsubst $(INCLUDE_DIR)/%,$(OBJ_DIR)/include/%,$(INCLUDE_OBJECTS_TEMP))
EXECUTABLE = $(RUN_DIR)/main
## == Compilation
# create executable file from all object files
$(EXECUTABLE): $(SRC_OBJECTS) $(INCLUDE_OBJECTS)
mkdir -p $(RUN_DIR)
$(CC) $(SRC_OBJECTS) $(INCLUDE_OBJECTS) -o $@ $(LIBS)
# create object file for every source file in source
$(OBJ_DIR)/src/%.o: $(SRC_DIR)/%.cpp
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
# create object file for every source file in include
$(OBJ_DIR)/include/%.o: $(INCLUDE_DIR)/%.cpp
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
## == Remote target management
# run main binary remote target
remote_start:
ssh -t $(USER)@$(HOST) "cd projects/$(WORKSPACE_NAME); $(RUN_DIR)/main"
# envoke build on remote target
remote_build:
ssh $(USER)@$(HOST) "bash -c \"cd projects/$(WORKSPACE_NAME) && make -j2\""
# copy sources and Makefile to remote target
copy_files:
ssh $(USER)@$(HOST) "rm -rf projects/$(WORKSPACE_NAME)/* && mkdir -p projects/$(WORKSPACE_NAME)/$(SRC_DIR) && mkdir -p projects/$(WORKSPACE_NAME)/$(INCLUDE_DIR)"
scp -r ../$(WORKSPACE_NAME)/$(SRC_DIR) $(USER)@$(HOST):projects/$(WORKSPACE_NAME)/
scp -r ../$(WORKSPACE_NAME)/$(INCLUDE_DIR) $(USER)@$(HOST):projects/$(WORKSPACE_NAME)/
scp -r ../$(WORKSPACE_NAME)/Makefile $(USER)@$(HOST):projects/$(WORKSPACE_NAME)/Makefile
scp -r ../$(WORKSPACE_NAME)/env.mk $(USER)@$(HOST):projects/$(WORKSPACE_NAME)/env.mk
# open shell on remote target
shell:
ssh -t $(USER)@$(HOST) "cd projects/$(WORKSPACE_NAME); exec '$$SHELL'"
# invokes ssh-keygen
keygen:
ssh-keygen
# invokes ssh copy ID for the remote host
keycopy:
ssh-copy-id $(USER)@$(HOST)
## == shortcuts and convenience features
# quickly copy files to target, compile and start on target
start:
make copy_files
make remote_build
make remote_start
# quickly copy files to target and compile them
build:
make copy_files
make remote_build
# mount the
mount:
mkdir -p $(MOUNT_FOLDER)
sshfs -o allow_other $(USER)@$(HOST):/ $(MOUNT_FOLDER)
unmount:
sudo umount $(MOUNT_FOLDER)
# remove all subfolders and files of the object dir and the executable
clean:
rm -rf $(EXECUTABLE) $(OBJ_DIR)/*