forked from ssut/payload-dumper-go
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
73 lines (54 loc) · 1.68 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
BUILD_DIR ?= .build
PROG ?= ota-tool
#PROTOC ?= $(shell which protoc)
include lib/libs.mk
###
# ota-tool
#
INCLUDE += src $(BUILD_DIR)/src
SRC += $(wildcard src/*.cc) src/update_metadata.pb.cc
OBJ = $(addprefix $(BUILD_DIR)/,$(SRC:=.o))
PROG_DEPS = $(OBJ) $(addprefix $(BUILD_DIR)/, $(LIBS))
BUILD_CMD = $(CXX) -flto -w -s $(OBJ) -L$(BUILD_DIR) -llzma -lcrypto $(addprefix -l:,$(LIBS))
.DEFAULT_GOAL = $(PROG)
$(PROG): $(PROG_DEPS)
@ echo "[LD]\t$@"
@ $(BUILD_CMD) -o $@
$(PROG)-static: $(PROG_DEPS)
@ echo "[LD]\t$@"
@ $(BUILD_CMD) -static -o $@
clean:
rm -rf $(BUILD_DIR) $(PROG)
###
# Protoc generation
#
$(addprefix $(BUILD_DIR)/, $(wildcard src/*.cc)): $(BUILD_DIR)/src/update_metadata.pb.cc
$(BUILD_DIR)/%.pb.cc: %.proto $(PROTOC)
@ echo "[PROTO]\t$<"
@ mkdir -p $(dir $@)
@ $(PROTOC) --cpp_out=$(BUILD_DIR) $<
# We add a phony target for protoc so that if you set PROTOC=protoc (ie
# using the host protoc in path), make doesn't try to build it as a file
# in this directory.
.PHONY: protoc
###
# General C(++)
#
INCLUDE += $(BUILD_DIR)
CFLAGS = $(addprefix -I,$(INCLUDE)) -flto
CXXFLAGS = -std=gnu++17 $(CFLAGS)
LDFLAGS = -Wl,--copy-dt-needed-entries
# Need to replace the LOG statement with a single ; so that a statement
# still exists. This is because some LOG calls are in an if/else block
# without brackets.
$(BUILD_DIR)/%.cc: %.cc
@ mkdir -p $(dir $@)
@ sed -z 's/\(\n *\)[A-Z_]*LOG[^;]*;\n/\1;\n/g' $< > $@
$(BUILD_DIR)/%.cc.o: $(BUILD_DIR)/%.cc
@ echo "[CPP]\t$@"
@ mkdir -p $(dir $@)
@ $(CXX) $(CXXFLAGS) -c -o $@ $< $(LDFLAGS)
$(BUILD_DIR)/%.c.o: %.c
@ echo "[CC]\t$@"
@ mkdir -p $(dir $@)
@ $(CC) $(CFLAGS) -c -o $@ $< $(LDFLAGS)