-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.testbed.windows.mak
46 lines (35 loc) · 1.54 KB
/
Makefile.testbed.windows.mak
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
DIR := $(subst /,\,${CURDIR})
BUILD_DIR := bin
OBJ_DIR := obj
ASSEMBLY := testbed
EXTENSION := .exe
COMPILER_FLAGS := -g -MD -Werror=vla -Wno-missing-braces -fdeclspec #-fPIC
INCLUDE_FLAGS := -Iengine\src -Itestbed\src
LINKER_FLAGS := -g -lengine.lib -L$(OBJ_DIR)\engine -L$(BUILD_DIR) #-Wl,-rpath,.
DEFINES := -D_DEBUG -DLIMPORT
# Make does not offer a recursive wildcard function, so here's one:
rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
SRC_FILES := $(call rwildcard,$(ASSEMBLY)/,*.c) # Get all .c files
DIRECTORIES := \$(ASSEMBLY)\src $(subst $(DIR),,$(shell dir $(ASSEMBLY)\src /S /AD /B | findstr /i src)) # Get all directories under src.
OBJ_FILES := $(SRC_FILES:%=$(OBJ_DIR)/%.o) # Get all compiled .c.o objects for tesbed
all: scaffold compile link
.PHONY: scaffold
scaffold: # create build directory
@echo Scaffolding folder structure...
-@setlocal enableextensions enabledelayedexpansion && mkdir $(addprefix $(OBJ_DIR), $(DIRECTORIES)) 2>NUL || cd .
@echo Done.
.PHONY: link
link: scaffold $(OBJ_FILES) # link
@echo Linking $(ASSEMBLY)...
@clang $(OBJ_FILES) -o $(BUILD_DIR)/$(ASSEMBLY)$(EXTENSION) $(LINKER_FLAGS)
.PHONY: compile
compile: #compile .c files
@echo Compiling...
.PHONY: clean
clean: # clean build directory
if exist $(BUILD_DIR)\$(ASSEMBLY)$(EXTENSION) del $(BUILD_DIR)\$(ASSEMBLY)$(EXTENSION)
rmdir /s /q $(OBJ_DIR)\$(ASSEMBLY)
$(OBJ_DIR)/%.c.o: %.c # compile .c to .c.o object
@echo $<...
@clang $< $(COMPILER_FLAGS) -c -o $@ $(DEFINES) $(INCLUDE_FLAGS)
-include $(OBJ_FILES:.o=.d)