-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
164 lines (126 loc) · 3.82 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
include ./config.mk
# Program wide settings
EXE := yabr
EXEC := YABR
PROG := $(BIN)/$(EXE)
YABR_VERSION := 0
YABR_SUBLEVEL := 8
YABR_PATCH := 0
YABR_VERSION_N := $(YABR_VERSION).$(YABR_SUBLEVEL).$(YABR_PATCH)
LIBFLAGS := `pkg-config --libs i3ipc-glib-1.0` \
-lasound \
-lm \
`pkg-config --libs libmpdclient` \
`pkg-config --libs dbus-1`
CFLAGS += -I'./include' `pkg-config --cflags i3ipc-glib-1.0` \
`pkg-config --cflags libmpdclient` \
`pkg-config --cflags dbus-1` \
-DYABR_VERSION_N="$(YABR_VERSION_N)"
# 'tree' references the current directory later-on
tree := .
# This is our default target - The default is the first target in the file so
# we need to define this fairly high-up.
all: real-all
.PHONY: all install clean dist real-all configure
# Predefine this variable. It contains a list of extra files to clean. Ex.
CLEAN_LIST :=
# List of files that dependency files should be generated for
DEPS :=
# Current project being compiled - Blank for core
PROJ :=
EXES :=
SRC_OBJS :=
# Set configuration options
Q := @
ifdef V
Q :=
endif
define create_link_rule
$(1): $(2)
@echo " LD $$@"
$$(Q)$$(LD) -r $(2) -o $$@
endef
# Traverse into tree
#
# For those confused, this does a few things:
# 1. Initalizes some variables for the current directory
# 2. 'Include's the current directory's Makefile, to get it's object information
# 3. Updates the clean-list, dependency list
# 4. Creates a rule that links all the objects in that directory into a
# single .o file (Including sub-directory objects)
# 5. Recurses into subdirectories listed in the included Makefile
define subdir_inc
tree := $$(tree)/$(1)
subdir-y :=
objs-y :=
clean-list-y :=
include $$(tree)/Makefile
# Prepend 'tree' to everything in the lists - the lists are relative to their directory
CLEAN_LIST += $$(patsubst %,$$(tree)/%,$$(objs-y)) $$(patsubst %,$$(tree)/%,$$(clean-list-y)) $$(tree).o
DEPS += $$(patsubst %,$$(tree)/%,$$(objs-y))
objs := $$(patsubst %,$$(tree)/%,$$(objs-y)) $$(patsubst %,$$(tree)/%.o,$$(subdir-y))
$$(eval $$(call create_link_rule,$$(tree).o,$$(objs)))
$$(foreach subdir,$$(subdir-y),$$(eval $$(call subdir_inc,$$(subdir))))
# Reduce 'tree' by one directory level
tree := $$(patsubst %/$(1),%,$$(tree))
endef
ifeq ($(CONFIG_DEBUG),y)
CFLAGS += -g -DCONFIG_DEBUG
ASFLAGS += -g
LDFLAGS += -g
endif
ifeq ($(CONFIG_PROF),y)
CFLAGS += -pg
LDFLAGS += -pg
endif
$(eval $(call subdir_inc,src))
CLEAN_LIST += $(BIN)
CLEAN_LIST += $(PROG)
# Actual entry
real-all: $(PROG)
$(PROG): ./src.o | $(BIN)
@echo " CCLD $@"
$(Q)$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $< $(LIBFLAGS)
install:
$(Q)mkdir -p $(BINDIR)
@echo " INSTALL yabr"
$(Q)install -m 775 ./bin/yabr $(BINDIR)
@echo " INSTALL doc"
$(Q)install -m 775 ./doc/yabr.1 $(MAN1DIR)
@echo " yabr Installation done"
dist: clean
$(Q)mkdir -p $(EXE)-$(YABR_VERSION_N)
$(Q)cp -R Makefile README.md config.mk LICENSE ./default_yabrrc ./include ./src $(EXE)-$(YABR_VERSION_N)
$(Q)tar -cf $(EXE)-$(YABR_VERSION_N).tar $(EXE)-$(YABR_VERSION_N)
$(Q)gzip $(EXE)-$(YABR_VERSION_N).tar
$(Q)rm -fr $(EXE)-$(YABR_VERSION_N)
@echo " Created $(EXE)-$(YABR_VERSION_N).tar.gz"
clean:
$(Q)for file in $(CLEAN_LIST); do \
if [ -e $$file ]; then \
echo " RM $$file"; \
rm -rf $$file; \
fi \
done
$(BIN):
@echo " MKDIR $@"
$(Q)$(MKDIR) $@
%.o: %.c
@echo " CC $@"
$(Q)$(CC) $(CFLAGS) -c $< -o $@
.%.d: %.c
@echo " CCDEP $@"
$(Q)$(CC) -MM -MP -MF $@ $(CFLAGS) $< -MT ./$*.o -MT $@
%.c: %.l
@echo " LEX $@"
$(Q)$(LEX) $(LFLAGS) -o $@ $<
%.tab.c %.tab.h: %.y
@echo " YACC $@"
$(Q)$(YACC) $(YFLAGS) -d -b $* $<
DEP_LIST := $(foreach dep,$(DEPS),$(dir $(dep)).$(notdir $(dep)))
DEP_LIST := $(DEP_LIST:.o=.d)
real-all: $(DEP_LIST)
ifeq (,$(filter $(MAKECMDGOALS),clean dist))
-include $(DEP_LIST)
endif
CLEAN_LIST += $(DEP_LIST)