1#! /usr/bin/env bash
2# ==============================================================================
3#  Authors:
4#    Patrick Lehmann
5#
6#  Bash Script (executable):
7#    Script to compile the simulation libraries from Altera Quartus for GHDL on
8#    Linux
9#
10# Description:
11#    - Creates a subdirectory in the current working directory
12#    - Compiles all Altera Quartus-II simulation libraries and packages
13#
14# ==============================================================================
15#  Copyright (C) 2017-2021 Patrick Lehmann - Boetzingen, Germany
16#  Copyright (C) 2015-2016 Patrick Lehmann - Dresden, Germany
17#
18#  This program is free software: you can redistribute it and/or modify
19#  it under the terms of the GNU General Public License as published by
20#  the Free Software Foundation, either version 2 of the License, or
21#  (at your option) any later version.
22#
23#  This program is distributed in the hope that it will be useful,
24#  but WITHOUT ANY WARRANTY; without even the implied warranty of
25#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26#  GNU General Public License for more details.
27#
28#  You should have received a copy of the GNU General Public License
29#  along with this program.  If not, see <gnu.org/licenses>.
30# ==============================================================================
31
32# Work around for Darwin (Mac OS)
33test greadlink --version > /dev/null 2>&1 && READLINK=greadlink || READLINK=readlink
34
35# Save working directory
36WorkingDir=$(pwd)
37ScriptDir="$(dirname $0)"
38ScriptDir="$($READLINK -f $ScriptDir)"
39
40# Source Bash utilities
41source $ScriptDir/../ansi_color.sh
42if [[ $? -ne 0 ]]; then echo 1>&2 -e "${COLORED_ERROR} While loading Bash utilities.${ANSI_NOCOLOR}"    ; exit 1; fi
43
44
45# Command line argument processing
46COMMAND=1
47CLEAN=0
48COMPILE_ALTERA=0
49COMPILE_MAX=0
50COMPILE_CYCLONE=0
51COMPILE_ARRIA=0
52COMPILE_STRATIX=0
53COMPILE_NM=0
54VERBOSE=0
55DEBUG=0
56FILTERING=1
57SKIP_LARGE_FILES=0
58SUPPRESS_WARNINGS=0
59HALT_ON_ERROR=0
60VHDLStandard=93
61DestDir=""
62SrcDir=""
63while [[ $# -gt 0 ]]; do
64	case "$1" in
65		-c|--clean)
66			COMMAND=3
67			CLEAN=1
68			;;
69		-a|--all)
70			COMMAND=2
71			;;
72		--altera)
73			COMMAND=3
74			COMPILE_ALTERA=1
75			;;
76		--max)
77			COMMAND=3
78			COMPILE_MAX=1
79			;;
80		--cyclone)
81			COMMAND=3
82			COMPILE_CYCLONE=1
83			;;
84		--arria)
85			COMMAND=3
86			COMPILE_ARRIA=1
87			;;
88		--stratix)
89			COMMAND=3
90			COMPILE_STRATIX=1
91			;;
92		--nanometer)
93			COMMAND=3
94			COMPILE_NM=1
95			;;
96		-S|--skip-largefiles)
97			SKIP_LARGE_FILES=1
98			;;
99		--vhdl93)
100			VHDLStandard=93
101			;;
102		--vhdl2008)
103			VHDLStandard=2008
104			;;
105		-v|--verbose)
106			VERBOSE=1
107			;;
108		-d|--debug)
109			VERBOSE=1
110			DEBUG=1
111			;;
112		-h|--help)
113			COMMAND=0
114			break
115			;;
116		-n|--no-filter)
117			FILTERING=0
118			;;
119		-N|--no-warnings)
120			SUPPRESS_WARNINGS=1
121			;;
122		-H|--halt-on-error)
123			HALT_ON_ERROR=1
124			;;
125		--ghdl)
126			GHDL="$2"				# overwrite a potentially existing GHDL environment variable
127			shift						# skip argument
128			;;
129		--source)
130			SrcDir="$2"
131			shift						# skip argument
132			;;
133		--output)
134			DestDir="$2"
135			shift						# skip argument
136			;;
137		*)		# unknown option
138			echo 1>&2 -e "\n${COLORED_ERROR} Unknown command line option '$1'.${ANSI_NOCOLOR}"
139			COMMAND=0
140			break
141			;;
142	esac
143	shift # parsed argument or value
144done
145
146ERRORCOUNT=0
147Libraries=()
148
149if [[ $COMMAND -le 1 ]]; then
150	test $COMMAND -eq 1 && echo 1>&2 -e "\n${COLORED_ERROR} No command selected.${ANSI_NOCOLOR}"
151	echo ""
152	echo "Synopsis:"
153	echo "  A script to compile the Altera Quartus simulation libraries for GHDL on Linux."
154	echo "  One library folder 'lib/v??' per VHDL library will be created relative to the current"
155	echo "  working directory."
156	echo ""
157	echo "  Use the adv. options or edit 'config.sh' to supply paths and default params."
158	echo ""
159	echo "Usage:"
160	echo "  compile-altera.sh [<verbosity>] <common command>|<library> [<options>] [<adv. options>]"
161	echo ""
162	echo "Common commands:"
163	echo "  -h --help                    Print this help page"
164	echo "  -c --clean                   Remove all generated files"
165	echo ""
166	echo "Libraries:"
167	echo "  -a --all                     Compile all Altera simulation libraries."
168	echo "     --altera                  Compile the Altera standard libraries: lpm, sgate, altera, altera_mf, altera_lnsim."
169	echo "     --max                     Compile the Altera Max device libraries."
170	echo "     --cyclone                 Compile the Altera Cyclone device libraries."
171	echo "     --arria                   Compile the Altera Arria device libraries."
172	echo "     --stratix                 Compile the Altera Stratix device libraries."
173	echo "     --nanometer               Unknown device library."
174	echo ""
175	echo "Library compile options:"
176	echo "     --vhdl93                  Compile the libraries with VHDL-93."
177	echo "     --vhdl2008                Compile the libraries with VHDL-2008."
178	echo "  -S --skip-largefiles         Don't compile large files. Exclude *HSSI* and *HIP* files."
179	echo "  -H --halt-on-error           Halt on error(s)."
180	echo ""
181	echo "Advanced options:"
182	echo "     --ghdl <GHDL binary>      Path to GHDL's executable, e.g. /usr/local/bin/ghdl"
183	echo "     --output <dir name>       Name of the output directory, e.g. altera"
184	echo "     --source <Path to Quartus>Path to the sources."
185	echo ""
186	echo "Verbosity:"
187	echo "  -v --verbose                 Print verbose messages."
188	echo "  -d --debug                   Print debug messages."
189	echo "  -n --no-filter               Disable output filtering scripts."
190	echo "  -N --no-warnings             Suppress all warnings. Show only error messages."
191	echo ""
192	exit $COMMAND
193fi
194
195if [[ $COMMAND -eq 2 ]]; then
196	COMPILE_ALTERA=1
197	COMPILE_MAX=1
198	COMPILE_CYCLONE=1
199	COMPILE_ARRIA=1
200	COMPILE_STRATIX=1
201	COMPILE_NM=1
202fi
203
204
205# Source configuration file from GHDL's 'vendors' library directory
206echo -e "${ANSI_MAGENTA}Loading environment...${ANSI_NOCOLOR}"
207source $ScriptDir/config.sh
208if [[ $? -ne 0 ]]; then echo 1>&2 -e "${COLORED_ERROR} While loading configuration.${ANSI_NOCOLOR}"     ; exit 1; fi
209source $ScriptDir/shared.sh
210if [[ $? -ne 0 ]]; then echo 1>&2 -e "${COLORED_ERROR} While loading further procedures.${ANSI_NOCOLOR}"; exit 1; fi
211
212# Warn that some files might not be VHDL-2008 ready. Thus enabled continue on error.
213if [[ $VHDLStandard -eq 2008 ]]; then
214	echo -e "${ANSI_RED}Not all Altera packages are VHDL-2008 compatible! Setting CONTINUE_ON_ERROR to TRUE.${ANSI_NOCOLOR}"
215	CONTINUE_ON_ERROR=1
216fi
217
218# Search Altera Quartus in default installation locations
219DefaultDirectories=("/opt/Altera" "/opt/altera" "/c/Altera")
220if [ ! -z $QUARTUS_ROOTDIR ]; then
221	EnvSourceDir="$QUARTUS_ROOTDIR/${Altera_Quartus_Settings[SourceDirectory]}"
222else
223	for DefaultDir in "${DefaultDirectories[@]}"; do
224		for Major in 16 15 14 13; do
225			for Minor in 1 0; do
226				Dir=$DefaultDir/${Major}.${Minor}/quartus
227				if [ -d $Dir ]; then
228					EnvSourceDir="$Dir/${Altera_Quartus_Settings[SourceDirectory]}"
229					break 3
230				fi
231			done
232		done
233	done
234fi
235
236
237# <= $VHDLVersion
238# <= $VHDLStandard
239# <= $VHDLFlavor
240GHDLSetup $VHDLStandard
241
242# -> $SourceDirectories
243# -> $DestinationDirectories
244# -> $SrcDir
245# -> $DestDir
246# <= $SourceDirectory
247# <= $DestinationDirectory
248SetupDirectories Altera_Quartus "Altera Quartus"
249
250# create "osvvm" directory and change to it
251# => $DestinationDirectory
252CreateDestinationDirectory
253cd $DestinationDirectory
254
255
256# Extend global GHDL Options TODO: move to GHDLSetup
257Analyze_Parameters+=(
258	-fexplicit
259	-Wbinding
260)
261if [[ $DEBUG -eq 0 ]]; then
262	Analyze_Parameters+=(
263		-Wno-hide
264	)
265fi
266if [[ ! (VERBOSE -eq 1) && ($DEBUG -eq 1) ]]; then
267	Analyze_Parameters+=(
268		-Wno-others
269		-Wno-static
270	)
271fi
272Analyze_Parameters+=(
273	--ieee=$VHDLFlavor
274	--no-vital-checks
275	--std=$VHDLStandard
276	-frelaxed
277	-P$DestinationDirectory
278)
279
280
281# Cleanup directories
282# ==============================================================================
283if [[ $CLEAN -eq 1 ]]; then
284	echo 1>&2 -e "${COLORED_ERROR} '--clean' is not implemented!"
285	exit 1
286	echo -e "${ANSI_YELLOW}Cleaning up vendor directory ...${ANSI_NOCOLOR}"
287	rm *.o 2> /dev/null
288	rm *.cf 2> /dev/null
289fi
290
291
292# Altera standard libraries
293# ==============================================================================
294StructName="LPM"
295Files=(
296	220pack.vhd
297	220model.vhd
298)
299CreateLibraryStruct $StructName "lpm" "." $VHDLVersion "${Files[@]}"
300test $COMPILE_ALTERA -eq 1 && Libraries+=("$StructName")
301
302StructName="SGATE"
303Files=(
304	sgate_pack.vhd
305	sgate.vhd
306)
307CreateLibraryStruct $StructName "sgate" "." $VHDLVersion "${Files[@]}"
308test $COMPILE_ALTERA -eq 1 && Libraries+=("$StructName")
309
310StructName="ALTERA"
311Files=(
312	altera_europa_support_lib.vhd
313	altera_primitives_components.vhd
314	altera_primitives.vhd
315	altera_standard_functions.vhd
316	altera_syn_attributes.vhd
317	alt_dspbuilder_package.vhd
318)
319CreateLibraryStruct $StructName "altera" "." $VHDLVersion "${Files[@]}"
320test $COMPILE_ALTERA -eq 1 && Libraries+=("$StructName")
321
322StructName="ALTERA_MF"
323Files=(
324	altera_mf_components.vhd
325	altera_mf.vhd
326)
327CreateLibraryStruct $StructName "altera_mf" "." $VHDLVersion "${Files[@]}"
328test $COMPILE_ALTERA -eq 1 && Libraries+=("$StructName")
329
330
331StructName="ALTERA_LNSIM"
332Files=(
333	altera_lnsim_components.vhd
334)
335CreateLibraryStruct $StructName "altera_lnsim" "." $VHDLVersion "${Files[@]}"
336test $COMPILE_ALTERA -eq 1 && Libraries+=("$StructName")
337
338
339# Altera device libraries
340# ==============================================================================
341test $VERBOSE -eq 1 && echo -e "  Searching available devices ..."
342
343# Max library
344StructName="MAX"
345Files=(
346	max_atoms.vhd
347	max_components.vhd
348)
349if [[ -f "$SourceDirectory/${Files[0]}" ]]; then
350	test $DEBUG -eq 1 && echo -e "    ${ANSI_DARK_GRAY}Found device 'Max'.${ANSI_NOCOLOR}"
351	CreateLibraryStruct $StructName "max" "." $VHDLVersion "${Files[@]}"
352
353	test $COMPILE_MAX -eq 1 && Libraries+=("$StructName")
354fi
355
356# Max II library
357StructName="MAX_II"
358Files=(
359	maxii_atoms.vhd
360	maxii_components.vhd
361)
362if [[ -f "$SourceDirectory/${Files[0]}" ]]; then
363	test $DEBUG -eq 1 && echo -e "    ${ANSI_DARK_GRAY}Found device 'Max II'.${ANSI_NOCOLOR}"
364	CreateLibraryStruct $StructName "maxii" "." $VHDLVersion "${Files[@]}"
365
366	test $COMPILE_MAX -eq 1 && Libraries+=("$StructName")
367fi
368
369# Max V library
370StructName="MAX_V"
371Files=(
372	maxv_atoms.vhd
373	maxv_components.vhd
374)
375if [[ -f "$SourceDirectory/${Files[0]}" ]]; then
376	test $DEBUG -eq 1 && echo -e "    ${ANSI_DARK_GRAY}Found device 'Max V'.${ANSI_NOCOLOR}"
377	CreateLibraryStruct $StructName "maxv" "." $VHDLVersion "${Files[@]}"
378
379	test $COMPILE_MAX -eq 1 && Libraries+=("$StructName")
380fi
381
382# Arria II library
383StructName="ARRIA_II"
384Files=(
385	arriaii_atoms.vhd
386	arriaii_components.vhd
387)
388if [[ $SKIP_LARGE_FILES -eq 0 ]]; then
389	Files+=(
390		arriaii_hssi_components.vhd
391		arriaii_hssi_atoms.vhd
392	)
393fi
394if [[ -f "$SourceDirectory/${Files[0]}" ]]; then
395	test $DEBUG -eq 1 && echo -e "    ${ANSI_DARK_GRAY}Found device 'Arria II'.${ANSI_NOCOLOR}"
396	CreateLibraryStruct $StructName "arriaii" "." $VHDLVersion "${Files[@]}"
397
398	test $COMPILE_ARRIA -eq 1 && Libraries+=("$StructName")
399fi
400
401# Arria II (PCIe) library
402if [[ $SKIP_LARGE_FILES -eq 0 ]]; then
403	StructName="ARRIA_II_PCIe"
404	Files=(
405		arriaii_pcie_hip_components.vhd
406		arriaii_pcie_hip_atoms.vhd
407	)
408	if [[ -f "$SourceDirectory/${Files[0]}" ]]; then
409		test $DEBUG -eq 1 && echo -e "    ${ANSI_DARK_GRAY}Found device 'Arria II (PCIe)'.${ANSI_NOCOLOR}"
410		CreateLibraryStruct $StructName "arriaii_pcie_hip" "." $VHDLVersion "${Files[@]}"
411
412		test $COMPILE_ARRIA -eq 1 && Libraries+=("$StructName")
413	fi
414fi
415
416# ArriaII GZ library
417StructName="ARRIA_II_GZ"
418Files=(
419	arriaiigz_atoms.vhd
420	arriaiigz_components.vhd
421)
422if [[ $SKIP_LARGE_FILES -eq 0 ]]; then
423	Files+=(
424		arriaiigz_hssi_components.vhd
425	)
426fi
427if [[ -f "$SourceDirectory/${Files[0]}" ]]; then
428	test $DEBUG -eq 1 && echo -e "    ${ANSI_DARK_GRAY}Found device 'Arria II GZ'.${ANSI_NOCOLOR}"
429	CreateLibraryStruct $StructName "arriaiigz" "." $VHDLVersion "${Files[@]}"
430
431	test $COMPILE_ARRIA -eq 1 && Libraries+=("$StructName")
432fi
433
434# ArriaV library
435StructName="ARRIA_V"
436Files=(
437	arriav_atoms.vhd
438	arriav_components.vhd
439)
440if [[ $SKIP_LARGE_FILES -eq 0 ]]; then
441	Files+=(
442		arriav_hssi_components.vhd
443		arriav_hssi_atoms.vhd
444	)
445fi
446if [[ -f "$SourceDirectory/${Files[0]}" ]]; then
447	test $DEBUG -eq 1 && echo -e "    ${ANSI_DARK_GRAY}Found device 'Arria V'.${ANSI_NOCOLOR}"
448	CreateLibraryStruct $StructName "arriav" "." $VHDLVersion "${Files[@]}"
449
450	test $COMPILE_ARRIA -eq 1 && Libraries+=("$StructName")
451fi
452
453# Arria V GZ library
454StructName="ARRIA_V_GZ"
455Files=(
456	arriavgz_atoms.vhd
457	arriavgz_components.vhd
458)
459if [[ $SKIP_LARGE_FILES -eq 0 ]]; then
460	Files+=(
461		arriavgz_hssi_components.vhd
462		arriavgz_hssi_atoms.vhd
463	)
464fi
465if [[ -f "$SourceDirectory/${Files[0]}" ]]; then
466	test $DEBUG -eq 1 && echo -e "    ${ANSI_DARK_GRAY}Found device 'Arria V GZ'.${ANSI_NOCOLOR}"
467	CreateLibraryStruct $StructName "arriavgz" "." $VHDLVersion "${Files[@]}"
468
469	test $COMPILE_ARRIA -eq 1 && Libraries+=("$StructName")
470fi
471
472# Arria V GZ (PCIe) library
473if [[ $SKIP_LARGE_FILES -eq 0 ]]; then
474	StructName="ARRIA_V_GZ_PCIe"
475	Files=(
476		arriavgz_pcie_hip_components.vhd
477		arriavgz_pcie_hip_atoms.vhd
478	)
479	if [[ -f "$SourceDirectory/${Files[0]}" ]]; then
480		test $DEBUG -eq 1 && echo -e "    ${ANSI_DARK_GRAY}Found device 'Arria V GZ (PCIe)'.${ANSI_NOCOLOR}"
481		CreateLibraryStruct $StructName "arriavgz_pcie_hip" "." $VHDLVersion "${Files[@]}"
482
483		test $COMPILE_ARRIA -eq 1 && Libraries+=("$StructName")
484	fi
485fi
486
487# Cyclone library
488StructName="CYCLONE"
489Files=(
490	cyclone_atoms.vhd
491	cyclone_components.vhd
492)
493if [[ -f "$SourceDirectory/${Files[0]}" ]]; then
494	test $DEBUG -eq 1 && echo -e "    ${ANSI_DARK_GRAY}Found device 'Cyclone'.${ANSI_NOCOLOR}"
495	CreateLibraryStruct $StructName "cyclone" "." $VHDLVersion "${Files[@]}"
496
497	test $COMPILE_CYCLONE -eq 1 && Libraries+=("$StructName")
498fi
499
500# Cyclone II library
501StructName="CYCLONE_II"
502Files=(
503	cycloneii_atoms.vhd
504	cycloneii_components.vhd
505)
506if [[ -f "$SourceDirectory/${Files[0]}" ]]; then
507	test $DEBUG -eq 1 && echo -e "    ${ANSI_DARK_GRAY}Found device 'Cyclone II'.${ANSI_NOCOLOR}"
508	CreateLibraryStruct $StructName "cycloneii" "." $VHDLVersion "${Files[@]}"
509
510	test $COMPILE_CYCLONE -eq 1 && Libraries+=("$StructName")
511fi
512
513# Cyclone III library
514StructName="CYCLONE_III"
515Files=(
516	cycloneiii_atoms.vhd
517	cycloneiii_components.vhd
518)
519if [[ -f "$SourceDirectory/${Files[0]}" ]]; then
520	test $DEBUG -eq 1 && echo -e "    ${ANSI_DARK_GRAY}Found device 'Cyclone III'.${ANSI_NOCOLOR}"
521	CreateLibraryStruct $StructName "cycloneiii" "." $VHDLVersion "${Files[@]}"
522
523	test $COMPILE_CYCLONE -eq 1 && Libraries+=("$StructName")
524fi
525
526# Cyclone IV library
527StructName="CYCLONE_IV"
528Files=(
529	cycloneiv_atoms.vhd
530	cycloneiv_components.vhd
531)
532if [[ $SKIP_LARGE_FILES -eq 0 ]]; then
533	Files+=(
534		cycloneiv_hssi_components.vhd
535		cycloneiv_hssi_atoms.vhd
536	)
537fi
538if [[ -f "$SourceDirectory/${Files[0]}" ]]; then
539	test $DEBUG -eq 1 && echo -e "    ${ANSI_DARK_GRAY}Found device 'Cyclone IV'.${ANSI_NOCOLOR}"
540	CreateLibraryStruct $StructName "cycloneiv" "." $VHDLVersion "${Files[@]}"
541
542	test $COMPILE_CYCLONE -eq 1 && Libraries+=("$StructName")
543fi
544
545# Cyclone IV (PCIe) library
546if [[ $SKIP_LARGE_FILES -eq 0 ]]; then
547	StructName="CYCLONE_IV_PCIe"
548	Files=(
549		cycloneiv_pcie_hip_components.vhd
550		cycloneiv_pcie_hip_atoms.vhd
551	)
552	if [[ -f "$SourceDirectory/${Files[0]}" ]]; then
553		test $DEBUG -eq 1 && echo -e "    ${ANSI_DARK_GRAY}Found device 'Cyclone IV (PCIe)'.${ANSI_NOCOLOR}"
554		CreateLibraryStruct $StructName "cycloneiv_pcie_hip" "." $VHDLVersion "${Files[@]}"
555
556		test $COMPILE_CYCLONE -eq 1 && Libraries+=("$StructName")
557	fi
558fi
559
560# Cyclone IV E library
561StructName="CYCLONE_IV_E"
562Files=(
563	cycloneive_atoms.vhd
564	cycloneive_components.vhd
565)
566if [[ -f "$SourceDirectory/${Files[0]}" ]]; then
567	test $DEBUG -eq 1 && echo -e "    ${ANSI_DARK_GRAY}Found device 'Cyclone IV E'.${ANSI_NOCOLOR}"
568	CreateLibraryStruct $StructName "cycloneive" "." $VHDLVersion "${Files[@]}"
569
570	test $COMPILE_CYCLONE -eq 1 && Libraries+=("$StructName")
571fi
572
573# Cyclone V library
574StructName="CYCLONE_V"
575Files=(
576	cyclonev_atoms.vhd
577	cyclonev_components.vhd
578)
579if [[ $SKIP_LARGE_FILES -eq 0 ]]; then
580	Files+=(
581		cyclonev_hssi_components.vhd
582		cyclonev_hssi_atoms.vhd
583	)
584fi
585if [[ -f "$SourceDirectory/${Files[0]}" ]]; then
586	test $DEBUG -eq 1 && echo -e "    ${ANSI_DARK_GRAY}Found device 'Cyclone V'.${ANSI_NOCOLOR}"
587	CreateLibraryStruct $StructName "cyclonev" "." $VHDLVersion "${Files[@]}"
588
589	test $COMPILE_CYCLONE -eq 1 && Libraries+=("$StructName")
590fi
591
592# Stratix IV library
593StructName="STRATIX_IV"
594Files=(
595	stratixiv_atoms.vhd
596	stratixiv_components.vhd
597)
598if [[ $SKIP_LARGE_FILES -eq 0 ]]; then
599	Files+=(
600		stratixiv_hssi_components.vhd
601		stratixiv_hssi_atoms.vhd
602	)
603fi
604if [[ -f "$SourceDirectory/${Files[0]}" ]]; then
605	test $DEBUG -eq 1 && echo -e "    ${ANSI_DARK_GRAY}Found device 'Stratix IV'.${ANSI_NOCOLOR}"
606	CreateLibraryStruct $StructName "stratixiv" "." $VHDLVersion "${Files[@]}"
607
608	test $COMPILE_STRATIX -eq 1 && Libraries+=("$StructName")
609fi
610
611# Stratix IV (PCIe) library
612if [[ $SKIP_LARGE_FILES -eq 0 ]]; then
613	StructName="STRATIX_IV_PCIe"
614	Files=(
615		stratixiv_pcie_hip_components.vhd
616		stratixiv_pcie_hip_atoms.vhd
617	)
618	if [[ -f "$SourceDirectory/${Files[0]}" ]]; then
619		test $DEBUG -eq 1 && echo -e "    ${ANSI_DARK_GRAY}Found device 'Stratix IV (PCIe)'.${ANSI_NOCOLOR}"
620		CreateLibraryStruct $StructName "stratixiv_pcie_hip" "." $VHDLVersion "${Files[@]}"
621
622		test $COMPILE_STRATIX -eq 1 && Libraries+=("$StructName")
623	fi
624fi
625
626# Stratix V library
627StructName="STRATIX_V"
628Files=(
629	stratixv_atoms.vhd
630	stratixv_components.vhd
631)
632if [[ $SKIP_LARGE_FILES -eq 0 ]]; then
633	Files+=(
634		stratixv_hssi_components.vhd
635		stratixv_hssi_atoms.vhd
636	)
637fi
638if [[ -f "$SourceDirectory/${Files[0]}" ]]; then
639	test $DEBUG -eq 1 && echo -e "    ${ANSI_DARK_GRAY}Found device 'Stratix V'.${ANSI_NOCOLOR}"
640	CreateLibraryStruct $StructName "stratixv" "." $VHDLVersion "${Files[@]}"
641
642	test $COMPILE_STRATIX -eq 1 && Libraries+=("$StructName")
643fi
644
645# Stratix V (PCIe) library
646if [[ $SKIP_LARGE_FILES -eq 0 ]]; then
647	StructName="STRATIX_V_PCIe"
648	Files=(
649		stratixv_pcie_hip_components.vhd
650		stratixv_pcie_hip_atoms.vhd
651	)
652	if [[ -f "$SourceDirectory/${Files[0]}" ]]; then
653		test $DEBUG -eq 1 && echo -e "    ${ANSI_DARK_GRAY}Found device 'Stratix V (PCIe)'.${ANSI_NOCOLOR}"
654		CreateLibraryStruct $StructName "stratixv_pcie_hip" "." $VHDLVersion "${Files[@]}"
655
656		test $COMPILE_STRATIX -eq 1 && Libraries+=("$StructName")
657	fi
658fi
659
660# 55 nm library
661StructName="NM_55"
662Files=(
663	fiftyfivenm_atoms.vhd
664	fiftyfivenm_components.vhd
665)
666if [[ -f "$SourceDirectory/${Files[0]}" ]]; then
667	test $DEBUG -eq 1 && echo -e "    ${ANSI_DARK_GRAY}Found device '55 nm'.${ANSI_NOCOLOR}"
668	CreateLibraryStruct $StructName "fiftyfivenm" "." $VHDLVersion "${Files[@]}"
669
670	test $COMPILE_NM -eq 1 && Libraries+=("$StructName")
671fi
672
673# 20 nm library
674StructName="NM_20"
675Files=(
676	twentynm_atoms.vhd
677	twentynm_components.vhd
678)
679if [[ $SKIP_LARGE_FILES -eq 0 ]]; then
680	Files+=(
681		twentynm_hip_components.vhd
682		twentynm_hip_atoms.vhd
683		twentynm_hssi_components.vhd
684		twentynm_hssi_atoms.vhd
685	)
686fi
687if [[ -f "$SourceDirectory/${Files[0]}" ]]; then
688	test $DEBUG -eq 1 && echo -e "    ${ANSI_DARK_GRAY}Found device '20 nm'.${ANSI_NOCOLOR}"
689	CreateLibraryStruct $StructName "twentynm" "." $VHDLVersion "${Files[@]}"
690
691	test $COMPILE_NM -eq 1 && Libraries+=("$StructName")
692fi
693
694# if [[ $DEBUG -eq 1 ]]; then
695	# for StructName in ${Libraries[*]}; do
696		# PrintLibraryStruct $StructName "    "
697	# done
698# fi
699
700# Compile libraries
701if [[ ${#Libraries[@]} -ne 0 ]]; then
702	Compile "$SourceDirectory" "${Libraries[*]}"
703
704	echo "--------------------------------------------------------------------------------"
705	echo -e "Compiling Altera Quartus packages and device libraries $(test $ERRORCOUNT -eq 0 && echo $COLORED_SUCCESSFUL || echo $COLORED_FAILED)"
706else
707	echo -e "${ANSI_RED}Neither Altera Quartus packages nor device libraries selected.${ANSI_NOCOLOR}"
708fi
709