-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile
More file actions
94 lines (74 loc) · 2.63 KB
/
Copy pathMakefile
File metadata and controls
94 lines (74 loc) · 2.63 KB
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
#
# Copyright (C) 2012 CompuLab, Ltd.
# Authors: Nikita Kiryanov <nikita@compulab.co.il>
# Igor Grinberg <grinberg@compulab.co.il>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
VERSION = 3
MINORVER = 2
PATCHLEVEL = 0
EEPROM_UTIL_VERSION = $(VERSION).$(MINORVER).$(PATCHLEVEL)
CROSS_COMPILE ?=
CC ?= $(CROSS_COMPILE)gcc
OBJDIR := obj
DEPDIR := dep
TARGET := eeprom-util
GOAL_FILE := $(OBJDIR)/make_goal
AUTO_GENERATED_FILE := auto_generated.h
CORE := common.o field.o layout.o command.o linux_api.o
MAIN := parser.o
OBJECTS := $(addprefix $(OBJDIR)/,$(CORE))
DEPS := $(addprefix $(DEPDIR)/,$(CORE:.o=.d) $(MAIN:.o=.d))
CFLAGS = -Wall -std=gnu99
DEPFLAGS = -MMD -MF $(DEPDIR)/$(*F).d
WRITEFLAGS = -D ENABLE_WRITE
DEBUGFLAGS = -g -D DEBUG
$(TARGET): $(OBJECTS) $(AUTO_GENERATED_FILE) $(OBJDIR)/$(MAIN)
$(CC) $(LDFLAGS) $(OBJECTS) $(OBJDIR)/$(MAIN) -o $(TARGET)
$(OBJDIR)/%.o : %.c $(GOAL_FILE)
$(CC) $(CFLAGS) $(DEPFLAGS) -c -o $@ $<
# pull in dependency info for *existing* .o files
-include $(DEPS)
static: LDFLAGS += -static
static: $(TARGET) ;
write: CFLAGS += $(WRITEFLAGS)
write: $(TARGET) ;
write_static: LDFLAGS += -static
write_static: write ;
debug: CFLAGS += $(DEBUGFLAGS)
debug: write ;
$(AUTO_GENERATED_FILE): $(OBJECTS) $(MAIN:.o=.c)
@( printf '#define VERSION "%s%s"\n' "$(EEPROM_UTIL_VERSION)" \
'$(shell ./setversion)' ) > $@
@date +'#define BUILD_DATE "%d %b %C%y"' >> $@
@date +'#define BUILD_TIME "%T"' >> $@
# make directory only if they don't exists (prevent unnecessary recompiling)
$(OBJECTS): | $(OBJDIR)
$(DEPS): | $(DEPDIR)
$(OBJDIR):
@mkdir -p $(OBJDIR)
$(DEPDIR):
@mkdir -p $(DEPDIR)
# save goal to file so target will recompile if goal changes
$(GOAL_FILE): .FORCE | $(OBJDIR)
ifneq ($(CROSS_COMPILE)$(MAKECMDGOALS),$(shell cat $(GOAL_FILE) 2>&1))
@echo '$(CROSS_COMPILE)$(MAKECMDGOALS)' > $@
endif
# fix implicit pattern rules to compile without liniking
$(CORE:.o=): % : $(OBJDIR)/%.o ;
$(MAIN:.o=): % : $(AUTO_GENERATED_FILE) $(OBJDIR)/%.o ;
clean:
rm -rf $(TARGET) $(OBJDIR) $(DEPDIR) $(AUTO_GENERATED_FILE)
.PHONY: clean .FORCE