1CC ?= gcc
2AM_CFLAGS = -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2
3CFLAGS ?= -g -O2
4objects = \
5	mmc.o \
6	mmc_cmds.o \
7	3rdparty/hmac_sha/hmac_sha2.o \
8	3rdparty/hmac_sha/sha2.o
9
10CHECKFLAGS = -Wall -Werror -Wuninitialized -Wundef
11
12DEPFLAGS = -Wp,-MMD,$(@D)/.$(@F).d,-MT,$@
13
14override CFLAGS := $(CHECKFLAGS) $(AM_CFLAGS) $(CFLAGS)
15
16INSTALL = install
17prefix ?= /usr/local
18bindir = $(prefix)/bin
19LIBS=
20RESTORE_LIBS=
21
22progs = mmc
23
24# make C=1 to enable sparse
25ifdef C
26	check = sparse $(CHECKFLAGS)
27endif
28
29all: $(progs) manpages
30
31.c.o:
32ifdef C
33	$(check) $<
34endif
35	$(CC) $(CPPFLAGS) $(CFLAGS) $(DEPFLAGS) -c $< -o $@
36
37mmc: $(objects)
38	$(CC) $(CFLAGS) -o $@ $(objects) $(LDFLAGS) $(LIBS)
39
40manpages:
41	$(MAKE) -C man
42
43install-man:
44	$(MAKE) -C man install
45
46clean:
47	rm -f $(progs) $(objects)
48	$(MAKE) -C man clean
49
50install: $(progs) install-man
51	$(INSTALL) -m755 -d $(DESTDIR)$(bindir)
52	$(INSTALL) $(progs) $(DESTDIR)$(bindir)
53
54.PHONY: all clean install manpages install-man
55