Last active
December 27, 2019 16:21
-
-
Save moriglia/2ac041368e8b7a57942b7245b4de92d1 to your computer and use it in GitHub Desktop.
Create a basic HDL project structure with a ready boilerplate makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Makefile generated by starthdlproject | |
SHELL := /bin/bash | |
vhd_files = $(shell find ../hdl/src/ ../hdl/tb/ \ | |
-regex .*\/[a-zA-Z0-9_\.]+\.vhd[l]? \ | |
-not -regex .*\/[a-zA-Z0-9_\.]+\.cpp\.vhd[l]?) | |
preproc_files = $(shell find ../hdl/src/ ../hdl/tb/ \ | |
-regex .*\/[a-zA-Z0-9_\.]+\.cpp\.vhd[l]?) | |
preproc_basenames = $(shell find ../hdl/src/ ../hdl/tb/ \ | |
-regex .*\/[a-zA-Z0-9_\.]+\.cpp\.vhd[l]? -exec basename '{}' ';') | |
postproc_files := $(patsubst %.cpp.vhdl,%.vhdl,$(preproc_basenames)) | |
postproc_files := $(patsubst %.cpp.vhd,%.vhd,$(postproc_files)) | |
current_pwd = $(shell pwd) | |
simfile ?= $(shell find . -regex \.\/[a-zA-Z0-9_\.]+_tb.vhd[l]? -exec basename '{}' ';') | |
simname = $(patsubst %.vhd,%,$(patsubst %.vhdl,%,$(simfile))) | |
.phony: update clean syntax preproc | |
update: | |
@for f in ${vhd_files} ; do \ | |
bn=`basename $$f` ; \ | |
if [ ! -f $$bn ] ; then \ | |
ln -s $$f $$bn ; \ | |
fi ; \ | |
done | |
@make preproc | |
clean: | |
rm -rf $(shell find . -not -iname makefile -not -type d) ; | |
syntax: preproc update | |
ghdl -s $(vhd_files) $(postproc_files) | |
preproc: | |
@for f in $(preproc_files) ; do \ | |
bn=`basename $$f` ; \ | |
cpp -P $$f -o $(current_pwd)/$${bn/".cpp"/""}; \ | |
done | |
build: syntax $(simfile) | |
@echo Simfile: $(simfile) | |
@echo Simname: $(simname) | |
ghdl -a $(vhd_files) $(postproc_files) | |
@for sname in $(simname) ; do \ | |
ghdl -e $$sname ; \ | |
ghdl -r $$sname --vcd=$${sname}.vcd ;\ | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -ne 1 ] ; then | |
echo "Usage: `basename $0` <project_name>" ; | |
exit 1 | |
fi | |
current_directory=`pwd` | |
mkdir -p $1 ; | |
cd $1 ; | |
mkdir -p hdl/src hdl/tb ghdl | |
cd ghdl ; | |
wget https://gist.githubusercontent.com/moriglia/2ac041368e8b7a57942b7245b4de92d1/raw/d3cb2d8aa356ef5805defac8e6213e16dc77739a/makefile | |
if [ $? -ne 0 ] ; then | |
echo "Unable to dwnload makefile. Creating one (may not be updated...)" | |
echo "# Makefile generated by `basename $0` | |
SHELL := /bin/bash | |
vhd_files = \$(shell find ../hdl/src/ ../hdl/tb/ \\ | |
-regex .*\/[a-zA-Z0-9_\.]+\.vhd[l]? \\ | |
-not -regex .*\/[a-zA-Z0-9_\.]+\.cpp\.vhd[l]?) | |
preproc_files = \$(shell find ../hdl/src/ ../hdl/tb/ \\ | |
-regex .*\/[a-zA-Z0-9_\.]+\.cpp\.vhd[l]?) | |
preproc_basenames = \$(shell find ../hdl/src/ ../hdl/tb/ \\ | |
-regex .*\/[a-zA-Z0-9_\.]+\.cpp\.vhd[l]? -exec basename '{}' ';') | |
postproc_files := \$(patsubst %.cpp.vhdl,%.vhdl,\$(preproc_basenames)) | |
postproc_files := \$(patsubst %.cpp.vhd,%.vhd,\$(postproc_files)) | |
current_pwd = \$(shell pwd) | |
simfile ?= \$(shell find . -regex \.\/[a-zA-Z0-9_\.]+_tb.vhd[l]? -exec basename '{}' ';') | |
simname = \$(patsubst %.vhd,%,\$(patsubst %.vhdl,%,\$(simfile))) | |
.phony: update clean syntax preproc | |
update: | |
@for f in \${vhd_files} ; do \\ | |
bn=\`basename \$\$f\` ; \\ | |
if [ ! -f \$\$bn ] ; then \\ | |
ln -s \$\$f \$\$bn ; \\ | |
fi ; \\ | |
done | |
@make preproc | |
clean: | |
rm -rf \$(shell find . -not -iname makefile -not -type d) ; | |
syntax: preproc | |
ghdl -s \$(vhd_files) \$(postproc_files) | |
preproc: | |
@for f in \$(preproc_files) ; do \\ | |
bn=\`basename \$\$f\` ; \\ | |
cpp -P \$\$f -o \$(current_pwd)/\$\${bn/\".cpp\"/\"\"}; \\ | |
done | |
build: syntax \$(simfile) | |
ghdl -a \$(vhd_files) \$(postproc_files) | |
ghdl -e \$(simname) | |
ghdl -r \$(simname) --vcd=\$(simname).vcd | |
" > makefile ; | |
fi ; | |
cd $current_directory ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment