forked from jivanpal/drat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
63 lines (54 loc) · 1.63 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
### Compiler/linker definitions ###
FLAGS=-std=c99 -Werror -Wall -Wextra -Wno-incompatible-pointer-types -Wno-multichar \
-Wno-unused-variable -Wno-unused-parameter
CC=gcc
CFLAGS=$(FLAGS)
LD=gcc
LDFLAGS=$(FLAGS)
### Directory definitions ###
SRCDIR=src
OBJDIR=obj
BINDIR=bin
### Target paths ###
TARGETS := \
apfs-read \
apfs-inspect \
apfs-explore-omap-tree \
apfs-explore-fs-tree \
apfs-search \
apfs-search-last-btree-node \
apfs-resolver \
apfs-modify \
apfs-list \
apfs-recover \
apfs-list-raw \
apfs-recover-raw
SOURCES := $(wildcard $(SRCDIR)/*.c)
HEADERS := $(wildcard $(SRCDIR)/*.h) $(wildcard $(SRCDIR)/*/*.h) $(wildcard $(SRCDIR)/*/*/*.h)
OBJECTS := $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
BINARIES := $(TARGETS:%=$(BINDIR)/%)
### Targets ###
# Makes all targets (binaries)
.PHONY: all
all: $(TARGETS)
@echo "All done. The binaries are in the \`$(BINDIR)\` directory."
# Removes all binaries and object files
.PHONY: clean
clean:
rm -rf $(BINDIR) $(OBJDIR)
find . -name '*.gch' -delete
# Makes the target `binary-name` an alias of `bin/binary-name`
.PHONY: $(TARGETS)
$(TARGETS): %: $(BINDIR)/%
$(BINARIES): $(BINDIR)/%: $(OBJDIR)/%.o
@[ -d $(BINDIR) ] || (mkdir -p $(BINDIR) && echo "Created directory \`$(BINDIR)/\`.")
@$(LD) $^ $(LDFLAGS) -o $@
@echo "$^\t==> $@"
$(OBJECTS): $(OBJDIR)/%.o: $(SRCDIR)/%.c $(HEADERS)
@[ -d $(OBJDIR) ] || (mkdir -p $(OBJDIR) && echo "Created directory \`$(OBJDIR)\`.")
@$(CC) $(CFLAGS) -c $< -o $@
@echo "$<\t==> $@ "
# This target exists to allow test compilation of
# headers, e.g. `make src/apfs/struct/object.gch`
$(HEADERS:%.h=%.gch): %.gch: %.h
@$(CC) $(CFLAGS) -c $< -o $@