summaryrefslogtreecommitdiff
path: root/Makefile
blob: 142a58e8835570d9b381c9023458203c530a2223 (plain)
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
# set up environment for building outside bitbake
# run: make MANUAL_BUILD=1
# run: make strip MANUAL_BUILD=1
ifdef MANUAL_BUILD

ifndef OETREE
$(error Please set OETREE variable)
endif

HOST_ARCH=$(shell uname -m)
CCDIR = $(OETREE)/build/tmp/sysroots/$(HOST_ARCH)-linux/usr/arm926ejste/bin
INCDIR = $(OETREE)/build/tmp/sysroots/arm926ejste-mlinux-linux-gnueabi/usr/include
CROSS_COMPILE=$(CCDIR)/arm-mlinux-linux-gnueabi-

export AS = $(CROSS_COMPILE)as
export LD = $(CROSS_COMPILE)ld
export CC = $(CROSS_COMPILE)gcc
export CPP = $(CROSS_COMPILE)g++
export CXX = $(CROSS_COMPILE)g++
export AR = $(CROSS_COMPILE)ar
export NM = $(CROSS_COMPILE)nm
export STRIP = $(CROSS_COMPILE)strip
export OBJCOPY = $(CROSS_COMPILE)objcopy
export OBJDUMP = $(CROSS_COMPILE)objdump
export RANLIB = $(CROSS_COMPILE)ranlib
export CFLAGS += -march=arm926ejste -mtune=arm926ej-s -mthumb-interwork -mno-thumb -fexpensive-optimizations -fomit-frame-pointer -frename-registers -O2 -ggdb2
endif

BUILDDIR=build
SOURCEDIR=src

# -g -pg  | profiling options

CFLAGS += -Werror -Wno-unused-function

CXXFLAGS += -std=c++14 -Wno-unused-function

LIBS := -lmts -lrt -lssl -lcrypto -lgpiod

INC=-Iinclude -Iinclude/Utility -Iinclude/AccessoryCards -Iinclude/Device -Iinclude/Fpga
INCLUDES = $(wildcard include/*.h)
SOURCES = $(wildcard $(SOURCEDIR)/**/*.cpp)
SOURCES += $(SOURCEDIR)/Version.cpp
OBJS1 = $(patsubst $(SOURCEDIR)/%.cpp,$(BUILDDIR)/%.o,$(SOURCES))
OBJS = $(patsubst $(SOURCEDIR)/%.c,$(BUILDDIR)/%.o,$(OBJS1))
CPP_DEPPS = $(patsubst $(SOURCEDIR)/%.cpp,$(BUILDDIR)/**/%.d,$(SOURCES))
CPP_DEPPS += $(BUILDDIR)/*.o $(BUILDDIR)/*.d $(BUILDDIR)/**/*.o $(BUILDDIR)/**/*.d
JS_OBJS = $(BUILDDIR)/Version.o
OUT_DIRS=build/AccessoryCards build/Device build/Fpga
MKDIR_P = mkdir -p

ifndef MTS_CHECK
MTS_CHECK := 1
endif



.PHONY: all clean

all: postbuild

prebuild:
	@echo PRE-BUILD
	@echo 'Removing previous version components started'
	-$(RM) $(BUILDDIR)/Version.o
	-$(RM) $(BUILDDIR)/Version.d
	-$(RM) $(SOURCEDIR)/Version.cpp
	@echo 'Removing previous version components complete'
	${MKDIR_P} ${OUT_DIRS}
	@echo ' '
	
postbuild: mainbuild
	@echo POST-BUILD
	@echo ' '

mainbuild: prebuild
	@echo MAIN-BUILD
	@$(MAKE) --no-print-directory mts-io-sysfs

mts-io-sysfs: $(OBJS) $(BUILDDIR)/MtsIoSysfs.o
	@echo 'Building target: $@'
	$(CXX) $(CFLAGS) $(INC) $(LDFLAGS) -o $(BUILDDIR)/mts-io-sysfs $(OBJS) $(BUILDDIR)/MtsIoSysfs.o $(LIBS)
	@echo 'Finished building target: $@'
	@echo ' '

$(BUILDDIR)/%.o: $(SOURCEDIR)/%.cpp
	@echo 'Building file: $<'
	$(CXX) $(CFLAGS) $(INC) -Wall -std=c++14 -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
	@echo 'Finished building: $<'
	@echo ' '

$(BUILDDIR)/Version.o: $(SOURCEDIR)/Version.cpp
	@echo 'Building file: $<'
	$(CXX) $(CFLAGS) $(INC) -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
	@echo 'Finished building: $<'
	@echo ' '

$(SOURCEDIR)/Version.cpp:
	@echo 'Creating file: Version.cpp'
	/bin/echo -e "//Pre-Build Auto-Generated Source\n#include \"Version.h\"\n\nconst std::string Version::version(\"$(shell git describe)\");" > $(SOURCEDIR)/Version.cpp
	@echo 'Finished creating: Version.cpp'
	@echo ' '

$(BUILDDIR)/MtsIo.o: $(SOURCEDIR)/MtsIo.cpp
	@echo 'Building file: $<'
	$(CXX) $(CFLAGS) $(INC) -Wall -std=c++14 -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" -DENABLE_MTS_CHECK=${MTS_CHECK}
	@echo 'Finished building: $<'
	@echo ' '

strip:
	$(STRIP) -S --strip-unneeded --remove-section=.note.gnu.gold-version --remove-section=.comment --remove-section=.note --remove-section=.note.gnu.build-id --remove-section=.note.ABI-tag $(BUILDDIR)/mts-io-sysfs

clean:
	-$(RM) $(OBJS) $(CPP_DEPPS) $(BUILDDIR)/mts-io-sysfs
	-@echo ' '

.PHONY: all clean dependents
.SECONDARY: