forked from frenchbakery/dev_template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
145 lines (112 loc) · 4.31 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
# the default env configuration that is used when not
# specified in env.mk
CARG =
LARG =
USER = access
HOST = 10.42.0.149
LCORES =-j4
RCORES =-j2
# 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
DEV_INCLUDE = devinclude
OBJ_DIR = obj
RUN_DIR = run
MOUNT_FOLDER = mount
WORKSPACE_NAME = $(shell basename ${PWD})
# C++ configurations
CC = aarch64-linux-gnu-g++
CFLAGS = -g $(ADDINC) -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/el-std/include -I$(SRC_DIR) $(CARG) -std=c++17 -D__CROISSANT
LIBS = -lpthread -lkipr $(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
REMOTE_OBJECTS = $(shell find $(OBJ_DIR) -name '*.o')
## == 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 $@
# links pre-copied objects on the remote target (hybrid link)
hlink: $(REMOTE_OBJECTS)
mkdir -p $(RUN_DIR)
$(CC) $(REMOTE_OBJECTS) -o $(EXECUTABLE) $(LIBS)
## == Local object compilation
local_compile: $(SRC_OBJECTS) $(INCLUDE_OBJECTS)
## == 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 $(RCORES)\""
# envoke hlink on remote target
remote_hlink:
ssh $(USER)@$(HOST) "bash -c \"cd projects/$(WORKSPACE_NAME) && make hlink\""
# copy sources and Makefile to remote target
copy_sources:
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
# copy compiled objects and Makefile to remote target
copy_objects:
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)/$(OBJ_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_sources
make remote_build
make remote_start
hstart:
make local_compile $(LCORES) ADDINC=-I$(DEV_INCLUDE)
make copy_objects
make remote_hlink
make remote_start
# quickly copy files to target and compile them
build:
make copy_sources
make remote_build
# localy builds objects, then copies them to the target and links them there
hbuild:
make local_compile $(LCORES) ADDINC=-I$(DEV_INCLUDE)
make copy_objects
make remote_hlink
# 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)/*