-
Notifications
You must be signed in to change notification settings - Fork 10
/
Makefile
75 lines (56 loc) · 1.49 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
# SPDX-FileCopyrightText: © 2020 Foundation Devices, Inc. <[email protected]>
# SPDX-License-Identifier: GPL-3.0-or-later
SOURCES = add-secrets.c
VPATH =
ARCH ?= x86
CFLAGS = -Wall -fno-strict-aliasing
CFLAGS += -fno-omit-frame-pointer
LDFLAGS = -Wl,-Map,$(MAP)
LIBS =
CROSS_COMPILE ?=
CC = $(CROSS_COMPILE)gcc
EXECUTABLE = add-secrets
TARGETDIR = x86
ifeq ($(findstring debug,$(MAKECMDGOALS)),debug)
OBJDIR = $(TARGETDIR)/debug
CFLAGS += -g -DDEBUG
LDFLAGS += -g
STRIP =
else
OBJDIR = $(TARGETDIR)/release
CFLAGS += -O2
STRIP = $(CROSS_COMPILE)strip
endif
PROGRAMDIR = $(OBJDIR)
INSTALL_DIR = $(HOME)/bin
PROGRAM = $(PROGRAMDIR)/$(EXECUTABLE)
MAP = $(PROGRAMDIR)/$(EXECUTABLE).map
OBJECTS = $(addprefix $(OBJDIR)/,$(SOURCES:.c=.o))
RM := rm -rf
all: $(PROGRAM)
debug: $(PROGRAM)
# Tool invocations
$(PROGRAM): $(OBJECTS) FORCE
@echo 'Building target: $@'
@echo 'Invoking: GCC C Linker'
@[ -d $(dir $@) ] || mkdir -p $(dir $@)
$(CC) $(LDFLAGS) -o $@ $(OBJECTS) $(LIBS)
@echo 'Finished building target: $@'
@echo ' '
# Other Targets
clean: FORCE
@$(RM) $(TARGETDIR)
$(OBJDIR)/%.o: %.c
@rm -f $@
@[ -d $(dir $@) ] || mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c -MMD -MP -o $@ $<
ifneq ($(MAKECMDGOALS),clean)
-include $(OBJECTS:.o=.d)
endif
install: $(PROGRAM)
@echo 'Installing $(PROGRAM)...'
@cp -f $(PROGRAM) $(INSTALL_DIR)
@[ -z $(STRIP) ] || $(STRIP) $(INSTALL_DIR)/$(EXECUTABLE)
@echo 'Installation complete'
.PHONY: all clean install FORCE
.SECONDARY: