-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile_defs
35 lines (26 loc) · 1.25 KB
/
Makefile_defs
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
# This Makefile defines a bunch of stuff used by the lower-level Makefiles
# all file paths are from their perspective!
CC = gcc
BIN = ../bin
BUILD = ../build
OBJ = $(BUILD)/obj
# this is the name of the lower level directory (e.g. THIS_DIR in the dev_handler folder is "dev_handler")
THIS_DIR = $(strip $(shell pwd | xargs basename -z))
# list of runtime component directories
COMPONENT_DIRS = dev_handler net_handler executor network_switch shm_wrapper runtime_util logger
# list of subfolders in $(OBJ) for runtime object files
OBJ_SUBDIR = $(foreach dir,$(COMPONENT_DIRS),$(OBJ)/$(dir))
# list of folders to include in compilation commands
INCLUDE += $(foreach dir,$(COMPONENT_DIRS),-I../$(dir))
# list of all object files this executable is dependent on relative to this Makefile
OBJS = $(patsubst %.c,$(OBJ)/$(THIS_DIR)/%.o,$(SRCS))
# list of build folders
BUILD_DIR += $(OBJ) $(BIN) $(BUILD) $(OBJ_SUBDIR)
# append -MMD and -MP to CFLAGS to get the dependency files built for the object files
CFLAGS += -MMD -MP
# general rule for compiling a list of source files to object files in the $(OBJ) directory
$(OBJ)/$(THIS_DIR)/%.o: %.c | $(OBJ_SUBDIR)
$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
# general rule for making a build directory
$(BUILD_DIR):
mkdir -p $@