-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
72 lines (50 loc) · 1.32 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
TOPDIR = $(shell pwd)
VERSION := 0.4
CROSS_COMPILE ?=
O ?= $(TOPDIR)
o := $(O)/
CC ?= $(CROSS_COMPILE)gcc
AR ?= $(CROSS_COMPILE)ar
INSTALL ?= install
# install directories
PREFIX ?= /usr
BINDIR ?= $(PREFIX)/sbin
INCLUDEDIR ?= $(PREFIX)/include
LIBDIR ?= $(PREFIX)/lib
ALL_TARGETS :=
CLEAN_TARGETS :=
IS_GIT := $(shell if [ -d .git ] ; then echo yes ; else echo no; fi)
ifeq ($(IS_GIT),yes)
VERSION := $(shell git describe --abbrev=8 --dirty --always --tags --long)
endif
# let the user override the default CFLAGS/LDFLAGS
CFLAGS ?= -O2
LDFLAGS ?=
MY_CFLAGS := $(CFLAGS)
MY_LDFLAGS := $(LDFLAGS)
MY_CFLAGS += -DVERSION=\"$(VERSION)\"
define compile_tgt
@mkdir -p $(dir $@)
$(CC) -MD -MT $@ -MF $(@:.o=.d) $(CPPFLAGS) $($(1)_CPPFLAGS) $(MY_CFLAGS) $($(1)_CFLAGS) -c -o $@ $<
endef
define link_tgt
$(CC) $(MY_LDFLAGS) $($(1)_LDFLAGS) -o $@ $(filter-out %.a,$^) -L/ $(addprefix -l:,$(filter %.a,$^)) $(LIBS) $($(1)_LIBS)
endef
MY_CFLAGS += -Wall -W -Werror
ifeq ($(DEBUG),1)
MY_CFLAGS += -g -O0
endif
ifeq ($(COVERAGE),1)
MY_CFLAGS += --coverage
MY_LDFLAGS += --coverage
endif
DEPS := $(shell find $(o) -name '*.d')
all: real-all
include tsnic-flash.mk
real-all: $(ALL_TARGETS)
.PHONY: $(CLEAN_TARGETS) clean
clean: $(CLEAN_TARGETS)
rm -f $(DEPS)
.PHONY: $(INSTALL_TARGETS) install
install: $(INSTALL_TARGETS)
-include $(DEPS)