forked from osresearch/LEDscape
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile.common
168 lines (133 loc) · 3.51 KB
/
Makefile.common
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
164
165
166
167
#########
#
# Common build targets
#
#
TOP ?= ../..
OBJDIR ?= $(TOP)/obj
LIBDIR ?= $(TOP)/lib
BINDIR ?= $(TOP)/bin
all: \
$(TARGETS-y) \
$(foreach O,$(BIN-y),$(BINDIR)/$O) \
$(foreach O,$(LIB-y),$(LIBDIR)/$O) \
ifeq ($(shell uname -m),armv7l)
# We are on the BeagleBone Black itself;
# do not cross compile.
export CROSS_COMPILE:=
else
# We are not on the BeagleBone and might be cross compiling.
# If the environment does not set CROSS_COMPILE, set our
# own. Install a cross compiler with something like:
#
# sudo apt-get install gcc-arm-linux-gnueabi
#
export CROSS_COMPILE?=arm-linux-gnueabi-
endif
GENERIC_CFLAGS += \
-g \
-W \
-Wall \
-D_BSD_SOURCE \
-Wp,-MMD,$(dir $@).$(notdir $@).d \
-Wp,-MT,$@ \
-I. \
-I$(TOP)/src/ledscape \
-O2 \
-mtune=cortex-a8 \
-march=armv7-a \
CFLAGS += \
-std=c99 \
$(GENERIC_CFLAGS) \
CPPFLAGS += \
$(GENERIC_CFLAGS) \
LDFLAGS += \
LDLIBS += \
-L$(LIBDIR) \
-lledscape \
-lpthread \
-lm \
COMPILE.c-o = $(CROSS_COMPILE)gcc $(CFLAGS) -c -o $@ $<
COMPILE.cpp-o = $(CROSS_COMPILE)g++ $(CPPFLAGS) -c -o $@ $<
COMPILE.a = $(CROSS_COMPILE)ar crv $@ $^
COMPILE.link = $(CROSS_COMPILE)g++ $(LDFLAGS) -o $@ $^ $(LDLIBS)
$(OBJDIR)/%.o: %.c
$(COMPILE.c-o)
$(OBJDIR)/%.o: %.cpp
$(COMPILE.cpp-o)
$(LIBDIR)/%.a:
$(RM) $@
$(COMPILE.a)
$(BINDIR)/%:
$(COMPILE.link)
#####
#
# The TI "app_loader" is the userspace library for talking to
# the PRU and mapping memory between it and the ARM.
#
APP_LOADER_DIR ?= $(TOP)/am335x/app_loader
APP_LOADER_LIB := $(APP_LOADER_DIR)/lib/libprussdrv.a
CFLAGS += -I$(APP_LOADER_DIR)/include
LDLIBS += $(APP_LOADER_LIB)
#####
#
# The TI PRU assembler looks like it has macros and includes,
# but it really doesn't. So instead we use cpp to pre-process the
# file and then strip out all of the directives that it adds.
# PASM also doesn't handle multiple statements per line, so we
# insert hard newline characters for every ; in the file.
#
PASM_DIR ?= $(TOP)/am335x/pasm
PASM := $(PASM_DIR)/pasm
$(LIBDIR)/%.bin: %.p $(PASM)
$(CPP) - < $< | perl -p -e 's/^#.*//; s/;/\n/g; s/BYTE\((\d+)\)/t\1/g' > /tmp/$(basename $<).i
$(PASM) -V3 -b /tmp/$(basename $<).i $(basename $@)
$(RM) /tmp/$(basename $<).i
#
# Generate a target for each of the binaries, with dependencies on
# object files for that source.
#
$(foreach O,$(BIN-y),\
$(eval $(BINDIR)/$O: $(foreach s,$($O.srcs),$(OBJDIR)/$(basename $s).o) $(LIBDIR)/libledscape.a))
$(foreach O,$(LIB-y),\
$(eval $(LIBDIR)/$O: $(foreach s,$($(basename $O).srcs),$(OBJDIR)/$(basename $s).o) $(APP_LOADER_LIB)))
#$(TARGETS):
#$(COMPILE.link)
.PHONY: clean
# Include all of the generated dependency files
-include $(OBJDIR)/.*.o.d
clean:
rm -rf \
$(OBJDIR)/*.o \
$(LIBDIR)/*.a \
$(OBJDIR)/.*.o.d \
$(LIBDIR)/*.bin \
###########
#
# The correct way to reserve the GPIO pins on the BBB is with the
# capemgr and a Device Tree file. But it doesn't work.
#
SLOT_FILE=/sys/devices/bone_capemgr.9/slots
DTS=CAPE-BONE-OCTO
DTB=/lib/firmware/$(DTS)-00A0.dtbo
dts: LEDscape.dts
@SLOT="`grep LEDSCAPE $(SLOT_FILE) | cut -d: -f1`"; \
if [ ! -z "$$SLOT" ]; then \
echo "Removing slot $$SLOT"; \
echo -$$SLOT > $(SLOT_FILE); \
fi
dtc -O dtb -o /lib/firmware/BB-LEDSCAPE-00A0.dtbo -b 0 -@ LEDscape.dts
echo BB-LEDSCAPE > $(SLOT_FILE)
firmware: $(DTB)
echo $(DTS) > $(SLOT_FILE)
$(DTB): cape-bone-octo.dts FORCE
dtc -O dtb -o $@ -b 0 -@ $<
FORCE:
###########
#
# PRU Libraries and PRU assembler are build from their own trees.
#
$(APP_LOADER_LIB):
$(MAKE) -C $(APP_LOADER_DIR)/interface
$(PASM):
$(MAKE) -C $(PASM_DIR)