libparanut
A Hardware Abstraction Layer for ParaNut Architectures.
Makefile File Reference

Makefile of the libparanut. More...

Detailed Description

Makefile of the libparanut.

This Makefile is supposed to make (ha!) the compilation of libparanut more handy. To check out exactly how this works, see the section HOWTO in the mainpage!

1 ####################################################################################################
2 # Copyright (C) 2019-2022 Alexander Bahle <alexander.bahle@hs-augsburg.de>
3 # Anna Pfuetzner <annakerstin.pfuetzner@gmail.com>
4 # Michael Schaeferling <michael.schaeferling@hs-augsburg.de>
5 #
6 # Redistribution and use in source and binary forms, with or without modification, are permitted
7 # provided that the following conditions are met:
8 #
9 # 1. Redistributions of source code must retain the above copyright notice, this list of conditions
10 # and the following disclaimer.
11 #
12 # 2. Redistributions in binary form must reproduce the above copyright notice, this list of
13 # conditions and the following disclaimer in the documentation and/or other materials provided with
14 # the distribution.
15 #
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
17 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
18 # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
19 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22 # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
23 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 ####################################################################################################
25 
26 #Target Configuration###############################################################################
27 
28 # Build path configuration:
29 BUILD_DIR = ./build
30 LIB_BUILD_DIR = $(BUILD_DIR)/lib
31 INC_BUILD_DIR = $(BUILD_DIR)/include
32 
33 
34 
35 PYTHON := python3
36 
37 #System Configuration###############################################################################
38 
39 # Call clean when changing these!
40 
41 # System Parameters
42 # Cache Linesize in Bits, Default: auto
43 # auto means all power of two linesizes from 32 to 2048
44 PN_CACHE_LINESIZE = auto
45 # Register Width in Bits, Default: 32
46 PN_RWIDTH = 32
47 
48 # Switch for raw compilation (optimized for performance, will drop security checks)
49 # Default: 0
50 PN_COMPILE_RAW = 0
51 
52 # Chose modules - Set to 0 to switch off
53 # Default: 1
54 PN_WITH_BASE = 1
55 PN_WITH_CACHE = 1
56 PN_WITH_LINK = 1
57 PN_WITH_THREAD = 1
58 PN_WITH_EXCEPTION = 1
59 PN_WITH_SPINLOCK = 1
60 
61 #Compiler Configuration#############################################################################
62 
63 # Instruction Set Architecture
64 # Currently available:
65 # 1. RISCV 32 bit - Set to RV32I
66 # Don't forget to change compiler when touching this!
67 PN_ISA = RV32I
68 
69 # Compiler
70 # Currently available:
71 # 1. GCC - Available GCC for chosen ISA
72 PN_COMPILER = GCC
73 
74 # Compile with Debug Symbols
75 # Default: 1
76 PN_DEBUG = 1
77 
78 #Compiler and Assembler Flags#######################################################################
79 
80 ifeq ($(PN_ISA),RV32I)
81 
82  ifeq ($(PN_COMPILER),GCC)
83 
84  # Set the list of system parameters together
85  PN_CONFIG_DEFINES = -D PN_CACHE_LINESIZE=$(PN_CACHE_LINESIZE) -D PN_RWIDTH=$(PN_RWIDTH)
86  PN_CONFIG_DEFINES += -D PN_JOBQUEUE_SIZE=$(PN_JOBQUEUE_SIZE)
87 
88  # Put in define for raw compilation if it was set before
89  ifeq ($(PN_COMPILE_RAW),1)
90  PN_CONFIG_DEFINES += -D PN_COMPILE_RAW
91  endif
92 
93  # Actual Compiler and Assembler
94  CROSS_COMPILE ?= riscv64-unknown-elf
95  AS := $(CROSS_COMPILE)-as
96  CC := $(CROSS_COMPILE)-gcc
97  GXX := $(CROSS_COMPILE)-g++
98  OBJDUMP := $(CROSS_COMPILE)-objdump
99  OBJCOPY := $(CROSS_COMPILE)-objcopy
100  GDB := $(CROSS_COMPILE)-gdb
101  AR := $(CROSS_COMPILE)-ar
102  SIZE := $(CROSS_COMPILE)-size
103 
104  # Compiler Flags
105  CFLAGS = -c -ansi -O3 -Wall -Werror -I./ -I./common
106 #~ CFLAGS = -c -ansi -O3 -Wall -Werror -I./ -I./common $(PN_CONFIG_DEFINES)
107  CFLAGS += -mabi=ilp32
108 
109  ifeq ($(PN_WITH_SPINLOCK),0)
110  ifeq ($(PN_WITH_LINK),0)
111  CFLAGS += -march=rv32i
112  else
113  CFLAGS += -march=rv32im
114  endif
115  else
116  ifeq ($(PN_WITH_LINK),0)
117  CFLAGS += -march=rv32ia
118  else
119  CFLAGS += -march=rv32ima
120  endif
121  endif
122 
123  ifeq ($(PN_DEBUG),1)
124  CFLAGS += -g
125  endif
126 
127  CFLAGS += -o
128 
129  else
130 
131  $(error No valid compiler set for the ISA that you chose.)
132 
133  endif
134 
135 else
136 
137  $(error No valid ISA set.)
138 
139 endif
140 
141 #Lists##############################################################################################
142 
143 # Assemble object list so we know what objects to build
144 OBJECT_LIST =
145 
146 ifeq ($(PN_WITH_BASE),1)
147  PN_CONFIG_DEFINES += -D PN_WITH_BASE
148  BPATH = ./pn_base/pn_base
149  OBJECT_LIST += $(BPATH).o $(BPATH)_$(PN_ISA).o
150 endif
151 
152 ifeq ($(PN_WITH_LINK),1)
153  PN_CONFIG_DEFINES += -D PN_WITH_LINK
154  LPATH = ./pn_link/pn_link
155  OBJECT_LIST += $(LPATH).o $(LPATH)_$(PN_ISA).o
156 endif
157 
158 ifeq ($(PN_WITH_THREAD),1)
159  PN_CONFIG_DEFINES += -D PN_WITH_THREAD
160  TPATH = ./pn_thread/pn_thread
161  OBJECT_LIST += $(TPATH).o $(TPATH)_$(PN_ISA).o
162 endif
163 
164 ifeq ($(PN_WITH_CACHE),1)
165  PN_CONFIG_DEFINES += -D PN_WITH_CACHE
166  CPATH = ./pn_cache/pn_cache
167  OBJECT_LIST += $(CPATH).o ./$(CPATH)_$(PN_ISA)_$(strip $(PN_CACHE_LINESIZE)).o
168 endif
169 
170 ifeq ($(PN_WITH_EXCEPTION),1)
171  PN_CONFIG_DEFINES += -D PN_WITH_EXCEPTION
172  EPATH = ./pn_exception/pn_exception
173  OBJECT_LIST += $(EPATH).o $(EPATH)_$(PN_ISA).o
174 endif
175 
176 ifeq ($(PN_WITH_SPINLOCK),1)
177  PN_CONFIG_DEFINES += -D PN_WITH_SPINLOCK
178  SPATH = ./pn_spinlock/pn_spinlock
179  OBJECT_LIST += $(SPATH).o $(SPATH)_$(PN_ISA).o
180 endif
181 
182 # Check if object list is empty because it would not make any sense to build the library then
183 ifeq ($(strip $(OBJECT_LIST)),)
184  $(error No modules enabled.)
185 endif
186 
187 # Add the objects for the common part
188 OBJECT_LIST += ./common/common_$(PN_ISA).o
189 
190 
191 # Everything in this list will be built to the $BUILD_DIR directory
192 BUILD_LIST = $(LIB_BUILD_DIR)/libparanut.a
193 BUILD_LIST += $(INC_BUILD_DIR)/paranut.h
194 BUILD_LIST += $(INC_BUILD_DIR)/pn_config.h
195 
196 
197 #Target Magic#######################################################################################
198 
199 # Creates everything for usage of libparanut
200 .PHONY: all
201 all: build
202 
203 
204 ### Build targets ###
205 
206 
207 # Build the libparanut to the BUILD_DIR directory
208 .PHONY: build
209 build: $(BUILD_LIST)
210 
211 
212 # Creates all cache files for RV32I anew in case of changes in buildscript.
213 # For development only.
214 .PHONY: build_cache_all
215 build_cache_all: ./pn_cache/pn_cache_RV32I_buildscript.py
216  $(PYTHON) $< 32
217  $(PYTHON) $< 64
218  $(PYTHON) $< 128
219  $(PYTHON) $< 256
220  $(PYTHON) $< 512
221  $(PYTHON) $< 1024
222  $(PYTHON) $< 2048
223  $(PYTHON) $< auto
224 
225 
226 # Cache Module Assembly Code for RV32I is generated at compile time
227 ./pn_cache/pn_cache_RV32I_$(PN_CACHE_LINESIZE).S: ./pn_cache/pn_cache_RV32I_buildscript.py
228  $(PYTHON) $< $(strip $(PN_CACHE_LINESIZE))
229 
230 
231 # Builds objects from C source code
232 %.o:: %.c paranut.h pn_config.h
233  $(CC) $(CFLAGS) $@ $<
234 
235 # Builds objects from assembler source code
236 %.o:: %.S paranut.h pn_config.h
237  $(CC) $(CFLAGS) $@ $<
238 
239 
240 
241 $(LIB_BUILD_DIR)/libparanut.a: $(OBJECT_LIST)
242  mkdir -p $(LIB_BUILD_DIR)
243  $(AR) cr $(notdir $@) $(OBJECT_LIST)
244  mv $(notdir $@) $(LIB_BUILD_DIR)
245 
246 
247 $(INC_BUILD_DIR)/paranut.h: paranut.h
248  mkdir -p $(INC_BUILD_DIR)
249  cp paranut.h $(INC_BUILD_DIR)
250 
251 
252 $(INC_BUILD_DIR)/pn_config.h: pn_config.h
253  mkdir -p $(INC_BUILD_DIR)
254  cp pn_config.h $(INC_BUILD_DIR)
255 
256 
257 # Generate pn_config header from system parameters ...
258 pn_config.h: update-config
259 
260 .PHONY: update-config
261 update-config:
262  @echo "Updating 'pn_config.h' ..."
263  @mkdir -p $(INC_BUILD_DIR)
264  @echo "/* Automatically generated file. See Makefile. No edits here! */" > pn_config.h.new
265  @echo "#define PN_CACHE_LINESIZE $(PN_CACHE_LINESIZE)" >> pn_config.h.new
266  @echo "#define PN_RWIDTH $(PN_RWIDTH)" >> pn_config.h.new
267  @if [ $(PN_COMPILE_RAW) -eq 1 ]; \
268  then echo "#define PN_COMPILE_RAW" >> pn_config.h.new; fi
269  @if [ $(PN_WITH_BASE) -eq 1 ]; \
270  then echo "#define PN_WITH_BASE" >> pn_config.h.new; fi
271  @if [ $(PN_WITH_CACHE) -eq 1 ]; \
272  then echo "#define PN_WITH_CACHE" >> pn_config.h.new; fi
273  @if [ $(PN_WITH_EXCEPTION) -eq 1 ]; \
274  then echo "#define PN_WITH_EXCEPTION" >> pn_config.h.new; fi
275  @if [ $(PN_WITH_LINK) -eq 1 ]; \
276  then echo "#define PN_WITH_LINK" >> pn_config.h.new; fi
277  @if [ $(PN_WITH_THREAD) -eq 1 ]; \
278  then echo "#define PN_WITH_THREAD" >> pn_config.h.new; fi
279  @if [ $(PN_WITH_SPINLOCK) -eq 1 ]; \
280  then echo "#define PN_WITH_SPINLOCK" >> pn_config.h.new; fi
281  @diff -q pn_config.h pn_config.h.new > /dev/null 2>&1 || mv pn_config.h.new pn_config.h
282  @rm -f pn_config.h.new
283 
284 
285 
286 ### Install documentation ###
287 
288 # Doxygen targets (only needed in source repository)
289 # Target 'install-doc' is provided in the Doxygen Makefile fragment:
290 -include Documentation/Doxygen.mk
291 
292 
293 ### Install lib and includes ###
294 .PHONY: install
295 install: $(BUILD_LIST)
296  @test "$(PREFIX)" != "" || ( echo "ERROR: Make variable PREFIX must be set for the 'install' target."; exit 3; )
297  mkdir -p $(PREFIX)/lib/$(SUFFIX)
298  cp -ar $(LIB_BUILD_DIR)/* $(PREFIX)/lib/$(SUFFIX)
299  mkdir -p $(PREFIX)/include/$(SUFFIX)
300  cp -ar $(INC_BUILD_DIR)/* $(PREFIX)/include/$(SUFFIX)
301 
302 
303 ### Clean target(s) ###
304 
305 # Removes library, object files, and auto generated files (double colons for composition with Doxygen.mk)
306 .PHONY: clean
307 clean::
308  find . -name '*.o' -delete
309  rm -f pn_cache/*.S
310  rm -rf $(BUILD_DIR) pn_config.h
311 
312 #EOF################################################################################################