-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
97 lines (76 loc) · 2.53 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
#!/bin/make
export PREFIX :=
export CC := $(PREFIX)gcc
export LD := $(CC)
export OBJCOPY := $(PREFIX)objcopy
export NM := $(PREFIX)nm
export SIZE := $(PREFIX)size
export BIN2O := bin2o
export GLSLANG := glslangValidator
export NDEBUG
#-------------------------------------------------------------------------------
.SUFFIXES:
#-------------------------------------------------------------------------------
TARGET := veles
INCLUDES := include
SOURCES := src
GLSLSOURCES := glsl
BUILD := build
ASAN := #-fsanitize=address
OPT := -O3 -g
ifdef NDEBUG
DEBUG := -DNDEBUG
else
DEBUG :=
endif
CFLAGS := $(OPT) -Wall -std=gnu99 \
-ffunction-sections -fdata-sections \
$(INCLUDE) -DUNIX \
-D_XOPEN_SOURCE=600 -D_DEFAULT_SOURCE \
-DGL_GLEXT_PROTOTYPES -DVT240_NO_BUFFER \
$(DEBUG) $(ASAN)
LIBS := -lGL -lglut -lm
LDFLAGS := -Wl,-x -Wl,--gc-sections $(OPT) $(ASAN)
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
GLSLFILES := $(foreach dir,$(GLSLSOURCES),$(notdir $(wildcard $(dir)/*.glsl)))
ifneq ($(BUILD),$(notdir $(CURDIR)))
#-------------------------------------------------------------------------------
export DEPSDIR := $(CURDIR)/$(BUILD)
export OFILES := $(CFILES:.c=.o) $(GLSLFILES:.glsl=.o)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(GLSLSOURCES),$(CURDIR)/$(dir)) $(CURDIR)
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
-I$(CURDIR)/$(BUILD)
export OUTPUT := $(CURDIR)/$(TARGET)
.PHONY: $(BUILD) clean all
$(BUILD):
@echo compiling...
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
clean:
@echo "[CLEAN]"
@rm -rf $(BUILD) $(TFILES) $(OFILES) demo
$(TARGET): $(TFILES)
else
#-------------------------------------------------------------------------------
# main target
#-------------------------------------------------------------------------------
.PHONY: all
all: $(OUTPUT)
$(OUTPUT): $(TARGET).elf
@cp $(TARGET).elf $(OUTPUT)
%.o: %.c
@echo "[CC] $(notdir $@)"
@$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d $(CFLAGS) -c $< -o $@
@#$(CC) -S $(CFLAGS) -o $(@:.o=.s) $< # create assembly file
%.o: %.glsl
@echo "[GLSL] $(notdir $@)"
@$(GLSLANG) $<
@$(BIN2O) -t -l$(subst .,_,$(basename $@)) -i$< -o$@
$(TARGET).elf: $(OFILES)
@echo "[LD] $(notdir $@)"
@$(LD) $(LDFLAGS) $(OFILES) $(LIBS) -o $@ -Wl,-Map=$(@:.elf=.map)
-include $(DEPSDIR)/*.d
#-------------------------------------------------------------------------------
endif
#-------------------------------------------------------------------------------