Zerocat Chipflasher  v0.4.10-182-333b622f
Flash free firmware to BIOS chips, kick the Management Engine.
Makefile File Reference

Build the chipflasher’s firmware, i.e. kick. More...

Detailed Description

Code

##>! @file
##>!
##>! @brief Build the chipflasher’s firmware, i.e. `kick`.
##>!
##>! # Copyright
##>!
##>! Zerocat Chipflasher --- Flash free firmware to BIOS chips,
##>!                         kick the Management Engine.
##>!
##>! Copyright (C) 2015 Tomás Zerolo <tomas@tuxteam.de> @n
##>! Copyright (C) 2015-2018, 2020, 2021 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
##>!
##>! ## Diagnostic Pragmas
##>!
##>! NOTE Propeller code allows some non ANSI standard format specifiers,
##>! i.e. "%b" for binary representation of an integer.
##>! That will produce warnings according to -Wformat and -Wformat-extra-args.
##>!
##>! You can temporarily disable these warnings in your source code:
##>!
##>!     [...]
##>!     ##>!pragma GCC diagnostic push
##>!     ##>!pragma GCC diagnostic ignored "-Wall"
##>!     ##>!pragma GCC diagnostic ignored "-Wformat-extra-args"
##>!     //your code goes here, i.e.:
##>!     //printi("binary number: %08b", x);
##>!     ##>!pragma GCC diagnostic pop
##>!     [...]
##>!
##>! Please compare to:
##>! https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html##>!Diagnostic-Pragmas)
##>!
##>! ## Usage
##>!
##>!     $ make help
##>!
##>! ## FIXME
##>!
##>! A patern rule would be nice. But where to stick the -lm -lfdserial and so on?
##>! NOTE lib order matters (-lfoo -lbar). And $^ must go before libs.
##>!
##>! @cond
#

# Shell
SHELL                         := /bin/sh

# White Space
EMPTY                         :=
SPACE                         := $(EMPTY) $(EMPTY)
COMMA                         := ,
M5                            := xxxxx

# Suffixes
.SUFFIXES :
.SUFFIXES : .c .h .elf

# Root Paths
ROOT_DOC                      := ../../doc/

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

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

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

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

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

READ                          := $(shell command -v read)
READFLAGS                     :=
$(if $(strip $(READ)),,       $(error Cannot find read utility))

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

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

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

PROPELFGCC                    := $(shell command -v propeller-elf-gcc)
PROPELFGCC_SYSROOT            = \
	--sysroot=$(PARALLAX_REPO)/
PROPELFGCC_INCLUDES           := \
	-I . \
	-I =Learn/Simple\ Libraries/TextDevices/libsimpletext \
	-I =Learn/Simple\ Libraries/Utility/libsimpletools \
	-I =Learn/Simple\ Libraries/Protocol/libsimplei2c
PROPELFGCC_LIBDIRS_lmm        := \
	-L . \
	-L =Learn/Simple\ Libraries/TextDevices/libsimpletext/lmm \
	-L =Learn/Simple\ Libraries/Utility/libsimpletools/lmm \
	-L =Learn/Simple\ Libraries/Protocol/libsimplei2c/lmm
PROPELFGCC_LIBDIRS_cmm        := \
	-L . \
	-L =Learn/Simple\ Libraries/TextDevices/libsimpletext/cmm \
	-L =Learn/Simple\ Libraries/Utility/libsimpletools/cmm \
	-L =Learn/Simple\ Libraries/Protocol/libsimplei2c/cmm
PROPELFGCC_LIBS               := \
	-lsimpletext \
	-lsimpletools \
	-lsimplei2c
PROPELFGCCFLAGS               = \
	$(PROPELFGCC_SYSROOT) \
	$(PROPELFGCC_INCLUDES) \
	$(PROPELFGCC_LIBDIRS_$*) \
	-Os -Wall -Wmissing-prototypes -m32bit-doubles -fno-exceptions -std=c99 -m$*
$(if $(strip $(PROPELFGCC)),, $(error Cannot find propeller-elf-gcc utility))

# Settings
PROJECT_NUMBER                := $(shell $(strip \
	$(SET) $(SETFLAGS); \
	$(GIT) $(GITFLAGS) \
		describe \
			--match v* | \
	$(SED) $(SEDFLAGS) \
		-e 's/(.*)(-g)([0-9a-f]*)/\1-\3/;' \
			-; \
	))
PARALLAX_REMOTE               := https://github.com/
PARALLAX_REPO                 := parallaxinc/Simple-Libraries
PARALLAX_REPO_VERSION         := c4f9a3e273002ec5e6f8b1d1ab95c14cb1823e82

# Files
DOXYORIG                      := $(ROOT_DOC)doxygen-resources/Doxyfile.orig
LIBPROP                       := $(wildcard libprop/*)
LIBCOMMON                     := $(wildcard libcommon/*)
LIBSPI                        := $(wildcard libSPI/*)
LIBKICK                       := $(wildcard libkick/*)

# Built-in Special Targets
#~ .SECONDARY :                  # Uncomment for debugging
.PHONY : \
	all \
	kick \
	print-search-dirs \
	setup-lib-parallaxinc \
	remove-lib-parallaxinc \
	clean \
	help hello

# Targets
#   all: same as kick
all : hello kick

#   target “kick”
#     Memory model
#     lmm: stores the program image and variable data in Main RAM, fastest execution
#     cmm: the program image is compiled into a size-optimized form
#     xmmc: stores program images in external flash memory, an SD card, or EEPROM.
kick : kick.lmm.elf kick.cmm.elf
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";

$(PARALLAX_REPO) :
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	$(READ) $(READFLAGS) \
		-p 'Ready to start download from “$(PARALLAX_REMOTE)”? [yes|no]: ' \
			reply; \
	if [ "$$reply" = 'yes' ]; then \
		$(MKDIR) $(MKDIRFLAGS) \
			$(dir $(@)); \
		$(CD) $(CDFLAGS) \
			$(dir $(@)); \
		$(GIT) $(GITFLAGS) \
			clone $(PARALLAX_REMOTE)$(@).git; \
		if [ $$? -eq 0 ]; then \
			$(CD) $(CDFLAGS) \
				$(@F)/; \
			$(GIT) $(GITFLAGS) \
				checkout $(PARALLAX_REPO_VERSION); \
			$(CD) $(CDFLAGS) \
				-; \
		else \
			exit 1; \
		fi; \
	else \
		$(ECHO) $(ECHOFLAGS) \
			"Download cancelled by user."; \
		exit 1; \
	fi;

libcommon/common.h.tmp : libcommon/common.h $(DOXYORIG)
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	$(SED) $(SEDFLAGS) \
		-e "/^#define VERSION/s/(.*\")(.*)(\".*)/\1$(PROJECT_NUMBER)\3/;" \
			$< > $@;

#   build kick.elf file
kick.%.elf : kick.c kick.h libcommon/common.h.tmp $(LIBPROP) $(LIBCOMMON) $(LIBSPI) $(LIBKICK) setup-lib-parallaxinc
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	$(PROPELFGCC) $(PROPELFGCCFLAGS) \
		$< \
		$(PROPELFGCC_LIBS) \
			-o $@;

#   print search directories
print-search-dirs :
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	$(PROPELFGCC) \
		-print-search-dirs;

#   set up parallaxinc repo clone
setup-lib-parallaxinc : $(PARALLAX_REPO)
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";

#   clean (remove) parallaxinc folder
remove-lib-parallaxinc :
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	$(RM) $(RMFLAGS) \
		-rf \
			$(dir $(PARALLAX_REPO));

#   clean kick
clean : hello
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	-$(RM) $(RMFLAGS) \
		kick.lmm.elf \
		kick.cmm.elf \
		libcommon/common.h.tmp;

#   display help information
help : hello
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	@$(ECHO) $(ECHOFLAGS) \
		"\nList Of Targets"\
		"\n---------------"\
		"\nall\r\t\t\t\tsame as kick"\
		"\nkick\r\t\t\t\tbuild kick, the firmware"\
		"\nprint-search-dirs\r\t\t\t\tprint Propeller-Elf-GCC search directories"\
		"\nsetup-lib-parallaxinc\r\t\t\t\tdownload Parallax Library Repo and Checkout"\
		"\nremove-lib-parallaxinc\r\t\t\t\tremove Parallax Library Repo"\
		"\nclean\r\t\t\t\tclean kick"\
		"\nhelp\r\t\t\t\tdisplay this help information"\
		"\nhello\r\t\t\t\tgreeter, provided with all, clean and help"\
		"\n";

#   Say hello.
#     provided with 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 – Firmware"\
		"\n$(M5) This Makefile builds Firmware Files."\
		"\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) 2015 Tomás Zerolo tomas.nosp@m.@tux.nosp@m.team..nosp@m.de
Copyright (C) 2015-2018, 2020, 2021 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

Diagnostic Pragmas

NOTE Propeller code allows some non ANSI standard format specifiers, i.e. "%b" for binary representation of an integer. That will produce warnings according to -Wformat and -Wformat-extra-args.

You can temporarily disable these warnings in your source code:

[...]
##>!pragma GCC diagnostic push
##>!pragma GCC diagnostic ignored "-Wall"
##>!pragma GCC diagnostic ignored "-Wformat-extra-args"
//your code goes here, i.e.:
//printi("binary number: %08b", x);
##>!pragma GCC diagnostic pop
[...]

Please compare to: https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html##>!Diagnostic-Pragmas)

Usage

$ make help

FIXME

A patern rule would be nice. But where to stick the -lm -lfdserial and so on? NOTE lib order matters (-lfoo -lbar). And $^ must go before libs.