Makefile 3.96 KB
Newer Older
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
# Configuration section
#
# Use environment variables if found, otherwise fallback to sane defaults
RTEMS_MAKEFILE_PATH ?= /opt/rtems-4.12-2016.03.18.NONFPU/sparc-rtems4.12/leon3
RTEMS_LIB=${RTEMS_MAKEFILE_PATH}/lib
CROSS_PREFIX=sparc-rtems4.12

# Detect the platform (last part of the path of RTEMS_MAKEFILE_PATH - e.g. leon3, leon2, etc)
PLATFORM = $(shell sh -c "echo ${RTEMS_MAKEFILE_PATH} | sed 's,^.*/,,'")

# The directories containing the source files, separated by ':'
VPATH=src

# If not selected, compile debug version of binary (no optimizations)
ifeq ($(CFG),)
CFG=debug
endif

# If not explicitely selected (with 'make FPU=1'), compile for FPU emulation
ifeq ($(FPU),)
FPU=0
endif

# Your source files: regardless of where they reside in the source tree,
# VPATH will locate them...
NONFPU_SRC=              \
	init.c

FPU_SRC=              \
	task1.c

# Build a Dependency list and an Object list, by replacing the .c
# extension to .d for dependency files, and .o for object files.
NONFPU_DEP = $(patsubst %.c, deps.$(CFG)/NONFPU_%.d, ${NONFPU_SRC})
FPU_DEP = $(patsubst %.c, deps.$(CFG)/FPU_%.d, ${FPU_SRC})
NONFPU_OBJ = $(patsubst %.c, objs.$(CFG)/NONFPU_%.o, ${NONFPU_SRC})
FPU_OBJ = $(patsubst %.c, objs.$(CFG)/FPU_%.o, ${FPU_SRC})

# Your final binary
TARGET=fputest

# What compiler to use for generating dependencies: 
# it will be invoked with -MM -MP
CC = ${CROSS_PREFIX}-gcc
CDEP = ${CC}

# What include flags to pass to the compiler
INCLUDEFLAGS= -I src

# Compilation flags (common)
COMMON += -B${RTEMS_LIB} -specs bsp_specs -qrtems \
	  -mcpu=leon3 -DBSP_leon3 \
	  -ffunction-sections -fdata-sections -Wall \
	  -Wmissing-prototypes -Wimplicit-function-declaration \
	  -Wstrict-prototypes -Wnested-externs

# Separate compile options per configuration
ifeq ($(CFG),debug)
CFLAGS += ${COMMON} -g -D_DEBUG ${INCLUDEFLAGS} -msoft-float
else
CFLAGS += ${COMMON} -g -O2 ${INCLUDEFLAGS} -msoft-float
endif

# Should we generate native FPU instructions for the FPU_SRC?
ifeq ($(FPU),1)
CFLAGS:=$(shell bash -c "echo ${CFLAGS} | sed 's,-msoft-float,,'")
CFLAGS_FPU:=${CFLAGS}
else
CFLAGS_FPU:=${CFLAGS}
LDFLAGS += -msoft-float
endif

# A common link flag for all configurations
LDFLAGS += ${COMMON} -Wl,--gc-sections

all:	inform bin.$(CFG)/${TARGET}

inform:
ifneq ($(CFG),release)
ifneq ($(CFG),debug)
	@echo "Invalid configuration "$(CFG)" specified."
	@echo "You must specify a configuration when running make, e.g."
	@echo  "make CFG=debug"
	@echo  
	@echo  "Possible choices for configuration are 'release' and 'debug'"
	@exit 1
endif
endif


bin.$(CFG)/${TARGET}: ${NONFPU_OBJ} ${FPU_OBJ} | inform
	@mkdir -p $(dir $@)
ifeq ($(V),1)
	$(CC) -g -o $@ $^ ${LDFLAGS}
else
	@echo [LD] $@
	@$(CC) -g -o $@ $^ ${LDFLAGS}
endif
ifeq ($(CFG),release)
	@${CROSS_PREFIX}-objcopy --only-keep-debug $@ ${@}.debug
	@${CROSS_PREFIX}-strip $@
endif
	@echo Built with RTEMS at ${RTEMS_LIB} for ${PLATFORM}.

objs.$(CFG)/NONFPU_%.o: %.c
	@mkdir -p $(dir $@)
ifeq ($(V),1)
	$(CC) -c $(CFLAGS) -o $@ $<
else
	@echo [CC] $@
	@$(CC) -c $(CFLAGS) -o $@ $<
endif

objs.$(CFG)/FPU_%.o: %.c
	@mkdir -p $(dir $@)
ifeq ($(V),1)
	$(CC) -c $(CFLAGS_FPU) -o $@ $<
else
	@echo [CC] $@
	@$(CC) -c $(CFLAGS_FPU) -o $@ $<
endif

deps.$(CFG)/NONFPU_%.d: %.c
	@mkdir -p $(dir $@)
	@echo Generating dependencies for $<
	@set -e ; $(CDEP) -MM -MP $(INCLUDEFLAGS) $< > $@.$$$$; \
	sed 's,\($*\)\.o[ :]*,objs.$(CFG)\/NONFPU_\1.o $@ : ,g' < $@.$$$$ > $@; \
	rm -f $@.$$$$

deps.$(CFG)/FPU_%.d: %.c
	@mkdir -p $(dir $@)
	@echo Generating dependencies for $<
	@set -e ; $(CDEP) -MM -MP $(INCLUDEFLAGS) $< > $@.$$$$; \
	sed 's,\($*\)\.o[ :]*,objs.$(CFG)\/NONFPU_\1.o $@ : ,g' < $@.$$$$ > $@; \
	rm -f $@.$$$$

clean:
	@rm -rf \
	deps.debug objs.debug bin.debug \
	deps.release objs.release bin.release

# Unless "make clean" is called, include the dependency files
# which are auto-generated. Don't fail if they are missing
# (-include), since they will be missing in the first invocation!
ifneq ($(MAKECMDGOALS),clean)
-include ${NONFPU_DEP}
-include ${FPU_DEP}
endif