Zerocat Chipflasher  v0.4.10-732-9a3cc90b
Flash free firmware to BIOS chips, kick the Management Engine.
Makefile File Reference

Check and update hardware files, generate auxiliaries. More...

Detailed Description

Code

##>! @file
##>!
##>! @brief Check and update hardware files, generate auxiliaries.
##>!
##>! # Copyright
##>!
##>! Zerocat Chipflasher --- Flash free firmware to BIOS chips,
##>!                         kick the Management Engine.
##>!
##>! Copyright (C) 2017, 2018, 2020 Kai Mertens <kmx@posteo.net>
##>!
##>! The Zerocat Chipflasher is free software: you can redistribute it
##>! and/or modify it under the terms of the GNU General Public License
##>! as published by the Free Software Foundation, either version 3 of
##>! the License, or (at your option) any later version.
##>!
##>! The Zerocat Chipflasher is distributed in the hope that it will be
##>! useful, but WITHOUT ANY WARRANTY; without even the implied warranty
##>! of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##>! GNU General Public License for more details.
##>!
##>! You should have received a copy of the GNU General Public License
##>! along with this program.  If not, see <http://www.gnu.org/licenses/>.
##>!
##>! This file is part of the Zerocat Chipflasher.
##>!
##>! # “In file” Documentation
##>!
##>! ## Usage
##>!
##>!     $ make
##>!     $ make gerbv
##>!     $ make clean
##>!
##>! @cond
#

# Shell
SHELL                         := /bin/sh

# White Space
EMPTY                         :=
SPACE                         := $(EMPTY) $(EMPTY)
COMMA                         := ,
M5                            := ooooo
TAB1                          := \r\t\t
TAB2                          := \r\t\t\t

# Suffixes
.SUFFIXES :
.SUFFIXES : .sch .drc .bom .md .pcb .png .svg .gbr .cnc .pcb.bak .new.pcb .net .cmd

# Utilities
MV                            := $(shell command -v mv)
MVFLAGS                       :=
$(if $(strip $(MV)),,         $(error Cannot find mv utility))

RM                            := $(shell command -v rm)
RMFLAGS                       :=
$(if $(strip $(RM)),,         $(error Cannot find rm utility))

CD                            := $(shell command -v cd)
CDFLAGS                       :=
$(if $(strip $(CD)),,         $(error Cannot find cd utility))

SET                           := $(shell command -v set)
SETFLAGS                      := -f
$(if $(strip $(SET)),,        $(error Cannot find set utility))

CAT                           := $(shell command -v cat)
CATFLAGS                      :=
$(if $(strip $(CAT)),,        $(error Cannot find cat utility))

SED                           := $(shell command -v sed)
SEDFLAGS                      := -r
$(if $(strip $(SED)),,        $(error Cannot find sed utility))

GIT                           := $(shell command -v git)
GITFLAGS                      :=
$(if $(strip $(GIT)),,        $(error Cannot find git utility))

ECHO                          := $(shell command -v echo)
ECHOFLAGS                     := -e
$(if $(strip $(ECHO)),,       $(error Cannot find echo utility))

#   Note ‘mkdir -p’ might not be supported.
MKDIR                         := $(shell command -v mkdir)
MKDIRFLAGS                    :=
$(if $(strip $(MKDIR)),,      $(error Cannot find mkdir utility))

MKTEMP                        := $(shell command -v mktemp)
MKTEMPFLAGS                   :=
$(if $(strip $(MKTEMP)),,     $(error Cannot find mktemp utility))

GERBV                         := $(shell command -v gerbv)
GERBVFLAGS                    :=
$(if $(strip $(GERBV)),,      $(error Cannot find gerbv utility))

GSCHEM                        := $(shell command -v gschem)
GSCHEMFLAGS                   :=
$(if $(strip $(GSCHEM)),,     $(error Cannot find gschem utility))

GNETLIST                      := $(shell command -v gnetlist)
GNETLISTFLAGS                 :=
$(if $(strip $(GNETLIST)),,   $(error Cannot find gnetlist utility))

GSCH2PCB                      := $(shell command -v gsch2pcb)
GSCH2PCBFLAGS                 :=
$(if $(strip $(GSCH2PCB)),,   $(error Cannot find gsch2pcb utility))

GAF                           := $(shell command -v gaf)
GAFFLAGS                      :=
GAFEXPORT                     := export
GAFEXPORTFLAGS                := --color --scale=.4in --margins=4in
$(if $(strip $(GAF)),,        $(error Cannot find gaf utility))

PCB                           := $(shell command -v pcb)
PCBFLAGS                      :=
$(if $(strip $(PCB)),,        $(error Cannot find pcb utility))

INKSCAPE                      := $(shell command -v inkscape)
INKSCAPEFLAGS                 := -z
$(if $(strip $(INKSCAPE)),,   $(error Cannot find inkscape utility))

CONVERT                       := $(shell command -v convert)
CONVERTFLAGS                  := -resize 2000x
$(if $(strip $(CONVERT)),,    $(error Cannot find convert utility))

# Root Paths
ROOT_RESOURCES                := ../doc/doxygen-resources/
ROOT_GSCHEM                   := gschem/
ROOT_PCB                      := pcb/
ROOT_ARTWORK                  := artwork/

# Sources
SOURCES_SCH                   := $(ROOT_GSCHEM)board.sch $(ROOT_GSCHEM)cables.sch
SOURCES_PCB                   := $(ROOT_PCB)board.pcb
SOURCES_DRC                   := $(patsubst %.sch,%.drc,$(SOURCES_SCH))
SOURCES_LABEL                 := $(ROOT_ARTWORK)front-label.svg
GSCHEM_ATTRIBS                := $(ROOT_GSCHEM)attribs
GNETLIST_RULE                 := $(ROOT_GSCHEM)rules-drc.scm

# Settings
INKSCAPE_REQUIRED             := Inkscape 0.92.4 (5da689c313, 2019-01-14)
INKSCAPE_VERSION              := $(shell $(strip \
	$(INKSCAPE) $(INKSCAPEFLAGS) \
		--version; \
	))
VERSION_PLACEHOLDER           := <Board-Version>
BOARD_VERSION                 := $(shell $(strip \
	$(SET) $(SETFLAGS); \
	$(GIT) $(GITFLAGS) \
		describe \
			--match board-v* | \
	$(SED) $(SEDFLAGS) \
		-e 's/(.*)(-g)([0-9a-f]*)/\1-\3/;' \
			-; \
	))
PROJECT_NUMBER                := $(shell $(strip \
	$(SET) $(SETFLAGS); \
	$(GIT) $(GITFLAGS) \
		describe \
			--match v* | \
	$(SED) $(SEDFLAGS) \
		-e 's/(.*)(-g)([0-9a-f]*)/\1-\3/;' \
			-; \
	))

# Targets
TARGETS_DRC                   := $(patsubst %.sch,%.drc,$(SOURCES_SCH))
TARGETS_BOM                   := $(patsubst %.sch,%.bom,$(SOURCES_SCH))
TARGETS_BOM_MD                := $(addsuffix .md,$(TARGETS_BOM))
TARGETS_PNG                   := $(addsuffix .png,$(SOURCES_SCH)) $(addsuffix .png,$(SOURCES_PCB))
GERBER_FOLDER                 := gerber_chipflasher-$(BOARD_VERSION)/
GERBER_FILE                   := $(BOARD_VERSION)
TARGETS_IMG                   := $(TARGETS_PNG)
TARGETS_AUX                   := $(TARGETS_BOM)
TARGETS_MARKDOWN              := $(TARGETS_BOM_MD)

# Built-in Special Targets
#~ .SECONDARY :                  # Uncomment for debugging
.PHONY : \
	all \
	inkscape-version \
	settings \
	auxiliaries \
	images \
	markdown \
	gerber \
	gerbv \
	check \
	synchronize \
	clean-synchronize \
	clean-backups \
	clean \
	help \
	hello

# Targets
#  Generate all selected files.
all : hello auxiliaries images markdown label gerber

# Query inkscape version, which must not match v1 for missing -f option.
inkscape-version :
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	if [ "$(INKSCAPE_VERSION)" != "$(INKSCAPE_REQUIRED)" ]; then \
		$(ECHO) $(ECHOFLAGS) \
			"Wrong inkscape version."; \
		exit 1; \
	fi;

#  Report retrieved settings.
settings :
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	@$(ECHO) $(ECHOFLAGS) \
		"\nBOARD_VERSION:\r\t\t$(BOARD_VERSION)"\
		"\nGERBER_FOLDER:\r\t\t$(GERBER_FOLDER)"\
		"\nGERBER_FILE:\r\t\t$(GERBER_FILE)"\
		"\n";

#  Check design rules in schematics (and create *.drc files by the way)
%.drc : %.sch $(GNETLIST_RULE)
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	$(GNETLIST) $(GNETLISTFLAGS) \
		-g drc2 \
		-l $(GNETLIST_RULE) \
		-o $@ \
			$< || \
		$(CAT) $(CATFLAGS) \
			$@;

#  Generate bill of material files from gschem schematics.
%.bom : %.sch %.drc $(GSCHEM_ATTRIBS)
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	$(GNETLIST) $(GNETLISTFLAGS) \
		-g bom2 \
		-Oattrib_file=$(GSCHEM_ATTRIBS) \
		-o $@ \
			$<;

#  Create markdown file from bom file.
%.bom.md : %.bom
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	$(ECHO) $(ECHOFLAGS) \
		"# Bill of Material ($(notdir $*).sch)"\
		"\n"\
		"\n@note Footprints are named according to gEDA/gaf and PCB footprint naming convention."\
		"\n" \
			>> $@;
	$(SED) $(SEDFLAGS) \
		--in-place \
		-e '{:nline /.*:.*/!{/^:/!N; s/\n/ /g; t nline}}' \
			$<;
	$(SED) $(SEDFLAGS) \
		--in-place \
		-e '/:$$/{N; s/\n//g;}' \
		-e 's/:unknown/:/g' \
			$<;
	$(SED) $(SEDFLAGS) \
		-e 'y/:/\|/; 2i:---|:---|:---|:---|:---|:---|:---' \
			$< >> $@;

#  Generate images from schematics.
%.sch.png : %.sch
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	TEMPFILE=$(shell $(MKTEMP) $(MKTEMPFLAGS) --suffix=.png); \
	$(CD) $(CDFLAGS) \
		$(dir $@); \
	$(GAF) $(GAFFLAGS) \
		$(GAFEXPORT) $(GAFEXPORTFLAGS) \
			--output=$$TEMPFILE \
				$(notdir $<); \
	$(CONVERT) $(CONVERTFLAGS) \
		$$TEMPFILE \
			$(notdir $@); \
	$(RM) $(RMFLAGS) \
		$$TEMPFILE; \
	$(CD) $(CDFLAGS) \
		-;

#  Stamp version string onto pcb.
%.pcb.version : %.pcb
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	$(SED) $(SEDFLAGS) \
		-e "s/(PCB\[\")(.*)($(VERSION_PLACEHOLDER))(\".*)/\1\2$(BOARD_VERSION)\4/;" \
		-e "s/(Text\[.*\")(.*)($(VERSION_PLACEHOLDER))(\".*)/\1\2$(BOARD_VERSION)\4/;" \
			$(<) > $(@);

#  Create images from pcb files.
%.pcb.png : %.pcb.version
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	$(PCB) $(PCBFLAGS) \
		-x png --dpi 300 --use-alpha --only-visible --photo-mode \
		--outfile $(@) \
			$(<);

#  Generate documentation files.
markdown : $(TARGETS_MARKDOWN)
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";

#  Generate images.
images : $(TARGETS_IMG)
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";

#  Generate auxiliaries, such as Images and BoM-Files
auxiliaries : $(TARGETS_AUX)
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";

#  Export a label files, png and pdf.
label : $(SOURCES_LABEL) inkscape-version
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	TEMPFILE=$(shell $(MKTEMP) $(MKTEMPFLAGS) --suffix=.svg); \
	$(SED) $(SEDFLAGS) \
		-e 's/(>Version: )(\$$.*\$$)/\1'$(PROJECT_NUMBER)'/;' \
			$< > $$TEMPFILE; \
	$(INKSCAPE) $(INKSCAPEFLAGS) \
		-f $$TEMPFILE \
		-e$(addsuffix .png,$<) \
		--export-id="layer7" \
		-j \
		-d300; \
	$(INKSCAPE) $(INKSCAPEFLAGS) \
		-f $$TEMPFILE \
		-e$(dir $<)$(addprefix devboard-,$(notdir $(addsuffix .png,$<))) \
		--export-id="layer6" \
		-j \
		-d300; \
	$(INKSCAPE) $(INKSCAPEFLAGS) \
		-f $$TEMPFILE \
		-A$(addsuffix .pdf,$<) \
		-C; \
	$(RM) $(RMFLAGS) \
		$$TEMPFILE;

#  Export layers as gerber files.
gerber : pcb/$(GERBER_FOLDER)
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	if [ -d "$<" ]; then \
		$(ECHO) $(ECHOFLAGS) \
			"\nGerber files are available in:"\
			"\n  $${PWD}/$<"\
			"\n"; \
	fi;

#  Start $(GERBV) utility with all layers loaded.
gerbv : gerber
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	$(CD) $(CDFLAGS) \
		pcb/$(GERBER_FOLDER) && \
	$(GERBV) $(GERBVFLAGS) \
		./*.cnc \
		./*.fab*.gbr \
		./*.outline*.gbr \
		./*.top*.gbr \
		./*.bottom*.gbr && \
	$(CD) $(CDFLAGS) \
		-;

#  Pattern Rule for gerber folder
%$(GERBER_FOLDER) : $(SOURCES_PCB).version
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	$(CD) $(CDFLAGS) \
		$(*); \
	$(PCB) $(PCBFLAGS) \
		-x gerber \
		--gerberfile $(GERBER_FILE) \
			$(notdir $<); \
	$(MKDIR) $(MKDIRFLAGS) \
		$(GERBER_FOLDER); \
	$(MV) $(MVFLAGS) \
		$(GERBER_FILE)*.gbr $(GERBER_FOLDER); \
	$(MV) $(MVFLAGS) \
		$(GERBER_FILE)*.cnc $(GERBER_FOLDER); \
	$(CD) $(CDFLAGS) \
		-; \
	$(ECHO) $(ECHOFLAGS) \
		"\nGerber files have been exported.";

#  Perform checks
check : $(SOURCES_DRC)
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";

#  Synchronize board pcb file with schematic
synchronize : $(ROOT_GSCHEM)board.sch $(wildcard $(ROOT_PCB)footprints/*)
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	$(GSCH2PCB) $(GSCH2PCBFLAGS) \
		-o $(ROOT_PCB)board \
		-d $(ROOT_PCB)footprints \
			$(<); \
	$(ECHO) $(ECHOFLAGS) \
		"TODO:" \
		"\n* Start PCB Editor and load PCB file."; \
	if [ -f "$(ROOT_PCB)board.new.pcb" ]; then \
		$(ECHO) $(ECHOFLAGS) \
			"* Within PCB Editor, load new layout file into buffer."; \
	fi; \
	if [ -f "$(ROOT_PCB)board.net" ]; then \
		$(ECHO) $(ECHOFLAGS) \
			"* Within PCB Editor, load netlist file."; \
	fi; \
	if [ -f "$(ROOT_PCB)board.cmd" ]; then \
		$(ECHO) $(ECHOFLAGS) \
			"* Within PCB Editor, execute command file."; \
	fi; \
	$(ECHO) $(ECHOFLAGS) \
		"* Within PCB Editor, finalize the layout manually." \
		"\n";

#  Clean files generated by gsch2pcb.
clean-synchronize :
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	-$(RM) $(RMFLAGS) \
		$(ROOT_PCB)board.{cmd,net,new.pcb,pcb.bak};

#  Clean backup files, generated by PCB- and schematic editors.
clean-backups :
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	-$(RM) $(RMFLAGS) \
		$(ROOT_PCB)board.pcb~;
	-$(RM) $(RMFLAGS) \
		$(ROOT_GSCHEM)board.sch~;

#  Clean all.
clean : hello clean-synchronize clean-backups
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	-$(RM) $(RMFLAGS) \
		$(TARGETS_DRC) \
		$(TARGETS_PNG) \
		$(TARGETS_BOM) \
		$(TARGETS_BOM_MD) \
		$(addsuffix .png,$(SOURCES_LABEL)) \
		$(dir $(SOURCES_LABEL))$(addprefix devboard-,$(notdir $(addsuffix .png,$(SOURCES_LABEL)))) \
		$(addsuffix .pdf,$(SOURCES_LABEL));
	object="$(wildcard $(ROOT_PCB)gerber_*)"; \
	if [ -d "$${object}" ]; then \
		$(RM) $(RMFLAGS) \
			-r \
				$${object}; \
	fi;

#  Provide help information.
help : hello
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	@$(ECHO) $(ECHOFLAGS) \
		"\nList of Targets"\
		"\n---------------"\
		"\n"\
		"\nall$(TAB2)generate all selected files"\
		"\nsettings$(TAB2)display retrieved settings"\
		"\nauxiliaries$(TAB2)generate auxiliaries, such as images and BoM files"\
		"\nimages$(TAB2)generate images"\
		"\nmarkdown$(TAB2)generate documentation files"\
		"\ngerber$(TAB2)export PCB layers as gerber files"\
		"\ngerbv$(TAB2)start $(GERBV) utility with all layers loaded"\
		"\ncheck$(TAB2)perform design rule check for schematics"\
		"\nsynchronize$(TAB2)update board PCB file from schematic (manual action required)"\
		"\nclean-synchronize$(TAB2)clean files, generated by synchronize action"\
		"\nclean-backups$(TAB2)clean backup files, generated by PCB- and schematic editors"\
		"\nclean$(TAB2)clean generated files"\
		"\nhelp$(TAB2)provide this help message"\
		"\nhello$(TAB2)greeter, provided with all, clean and help"\
		"\n";

#  Say hello.
#   hello is provided with targets all, clean and help
hello :
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)"\
		"\n$(M5) Zerocat Chipflasher – The Hardware"\
		"\n$(M5) This Makefile builds Hardware Files and Auxiliaries."\
		"\n$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)";

##>! @endcond

Copyright

Zerocat Chipflasher — Flash free firmware to BIOS chips, kick the Management Engine.

Copyright (C) 2017, 2018, 2020 Kai Mertens kmx@p.nosp@m.oste.nosp@m.o.net

The Zerocat Chipflasher is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

The Zerocat Chipflasher is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

This file is part of the Zerocat Chipflasher.

“In file” Documentation

Usage

$ make
$ make gerbv
$ make clean