Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 14 Jan 2006 21:03:32 +0100
From:      Max Laier <max@love2party.net>
To:        Hartmut Brandt <hartmut.brandt@dlr.de>
Cc:        freebsd-current@freebsd.org
Subject:   .PATH-problem [was Re: make or kmod.mk broken]
Message-ID:  <200601142103.39181.max@love2party.net>
In-Reply-To: <43C93017.3080305@dlr.de>
References:  <200601140758.02019.max@love2party.net> <43C93017.3080305@dlr.de>

next in thread | previous in thread | raw e-mail | index | archive | help
--nextPart59857029.N3WBgbF9Rf
Content-Type: multipart/mixed;
  boundary="Boundary-01=_WkVyDl0P1s1/7NT"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

--Boundary-01=_WkVyDl0P1s1/7NT
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

On Saturday 14 January 2006 18:08, Hartmut Brandt wrote:
> Max Laier wrote:
> >On a related question:  How can I get the actual location of a file that
> > is in .PATH?  All I could come up with was ${.ALLSRC:M*${MY_FILE}} which
> > doesn't work as I am explaining here.
>
> M*$(MY_FILE) would also match 'foobar'  if MY_FILE is 'bar' which is
> probably not what you want.
> .IMPSRC might be what you want if you talk about an implicite rule.

What I am trying to do is parse a list of "filename:shortname"-objects.  Th=
is=20
is to support easy building of firmware modules.  If things work as I want=
=20
them to you can build a firmware module with a two line Makefile:

| KMOD=3Dsomefirmware
| FIRMWS=3Dfirmfile1.fw:somename1 firmfile2.fw:somename2

and it works if the firmfiles are in the same directory, but if they are=20
in .PATH it fails.  I was looking at .IMPSRC initially as well, but failed =
to=20
understand the concept :-\ ... any help greatly appreciated.  Thanks.

My current hack is attached, the complete thing is in perforce=20
at //depot/user/mlaier/firmware/...

=2D-=20
/"\  Best regards,                      | mlaier@freebsd.org
\ /  Max Laier                          | ICQ #67774661
 X   http://pf4freebsd.love2party.net/  | mlaier@EFnet
/ \  ASCII Ribbon Campaign              | Against HTML Mail and News

--Boundary-01=_WkVyDl0P1s1/7NT
Content-Type: text/x-diff;
  charset="iso-8859-1";
  name="kmod.mk.diff"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="kmod.mk.diff"

Index: kmod.mk
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /usr/store/mlaier/fcvs/src/sys/conf/kmod.mk,v
retrieving revision 1.200
diff -u -r1.200 kmod.mk
=2D-- kmod.mk	29 Nov 2005 09:37:42 -0000	1.200
+++ kmod.mk	6 Jan 2006 03:48:58 -0000
@@ -36,6 +36,8 @@
 #
 # SRCS		List of source files.
 #
+# FIRMWS	List of firmware images in format filename:shortname
+#
 # DESTDIR	The tree where the module gets installed. [not set]
 #
 # +++ targets +++
@@ -119,6 +121,24 @@
 CFLAGS+=3D	-mlongcall -fno-omit-frame-pointer
 .endif
=20
+.if defined(FIRMWS)
+.if !exists(@)
+${KMOD:S/$/.c/}: @
+.else
+${KMOD:S/$/.c/}: @/tools/fw_stub.awk
+.endif
+	${AWK} -f @/tools/fw_stub.awk ${FIRMWS} -m${KMOD} -c${KMOD:S/$/.c/g}
+
+SRCS+=3D	${KMOD:S/$/.c/}
+CLEANFILES+=3D	${KMOD:S/$/.c/}
+
+.for _firmw in ${FIRMWS}
+${_firmw:C/\:.*$/.fwo/}:	${_firmw:C/\:.*$//}
+	${LD} -b binary ${LDFLAGS} -r -d -o ${.TARGET} ${_firmw:C/\:.*$//}
+OBJS+=3D	${_firmw:C/\:.*$/.fwo/}
+.endfor
+.endif
+
 OBJS+=3D	${SRCS:N*.h:R:S/$/.o/g}
=20
 .if !defined(PROG)

--Boundary-01=_WkVyDl0P1s1/7NT
Content-Type: text/plain;
  charset="iso-8859-1";
  name="fw_stub.awk"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="fw_stub.awk"

#!/usr/bin/awk -f

#-
# Copyright (c) 2006 Max Laier.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS `AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $FreeBSD$

#
# Script to generate module .c file from a list of firmware images
#

function usage ()
{
	print "usage: fw_stub <firmware:name>* [-m modname] [-c outfile]";
	exit 1;
}

#   These are just for convenience ...
function printc(s)
{
	if (opt_c)
		print s > ctmpfilename;
	else
		print s > "/dev/stdout";
}

BEGIN {

#
#   Process the command line.
#

num_files = 0;

for (i = 1; i < ARGC; i++) {
	if (ARGV[i] ~ /^-/) {
		#
		#   awk doesn't have getopt(), so we have to do it ourselves.
		#   This is a bit clumsy, but it works.
		#
		for (j = 2; j <= length(ARGV[i]); j++) {
			o = substr(ARGV[i], j, 1);
			if (o == "c") {
				if (length(ARGV[i]) > j) {
					opt_c = substr(ARGV[i], j + 1);
					break;
				}
				else {
					if (++i < ARGC)
						opt_c = ARGV[i];
					else
						usage();
				}
			} else if (o == "m") {
				if (length(ARGV[i]) > j) {
					opt_m = substr(ARGV[i], j + 1);
					break;
				}
				else {
					if (++i < ARGC)
						opt_m = ARGV[i];
					else
						usage();
				}
			} else
				usage();
		}
	} else {
		if (k = index(ARGV[i], ":")) {
			filenames[num_files] = substr(ARGV[i], 1, k - 1);
			shortnames[num_files] = substr(ARGV[i], k + 1);
		} else {
			filenames[num_files] = ARGV[i];
			shortname[num_files] = ARGV[i];
		}
		num_files++;
	}
}

if (!num_files || !opt_m)
	usage();

cfilename = opt_c;
ctmpfilename = cfilename ".tmp";

printc("#include <sys/param.h>\
#include <sys/errno.h>\
#include <sys/kernel.h>\
#include <sys/module.h>\
#include <sys/linker.h>\
#include <sys/firmware.h>\n");

for (file_i = 0; file_i < num_files; file_i++) {
	symb = filenames[file_i];
	# '-', '.' and '/' are converted to '_' by ld/objcopy
	gsub(/-|\.|\//, "_", symb);
	printc("extern char _binary_" symb "_start[], _binary_" symb "_end[];");
}

printc("\nstatic int\n"\
opt_m "_fw_modevent(module_t mod, int type, void *unused)\
{\
	struct firmware *fp;\
	switch (type) {\
	case MOD_LOAD:");

for (file_i = 0; file_i < num_files; file_i++) {
	short = shortnames[file_i];
	symb = filenames[file_i];
	# '-', '.' and '/' are converted to '_' by ld/objcopy
	gsub(/-|\.|\//, "_", symb);

	if (file_i == 0)
		reg = "\t\tfp = ";
	else
		reg = "\t\t(void)";

	reg = reg "firmware_register(\"" short "\", _binary_" symb "_start , ";
	reg = reg "(size_t)(_binary_" symb "_end - _binary_" symb "_start), ";

	if (file_i == 0)
		reg = reg "NULL);";
	else
		reg = reg "fp);";

	printc(reg);
}

printc("\t\treturn (0);\
	case MOD_UNLOAD:");

for (file_i = 1; file_i < num_files; file_i++) {
	printc("\t\tfirmware_unregister(\"" shortnames[file_i] "\");");
}

printc("\t\tfirmware_unregister(\"" shortnames[0] "\");");

printc("\t\treturn (0);\
	}\
	return (EINVAL);\
}\
\
static moduledata_t " opt_m "_fw_mod = {\
        \"" opt_m "_fw\",\
        " opt_m "_fw_modevent,\
        0\
};\
DECLARE_MODULE(" opt_m "_fw, " opt_m "_fw_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);\
MODULE_VERSION(" opt_m "_fw, 1);\
MODULE_DEPEND(iwi_boot_fw, firmware, 1, 1, 1);\
");

if (opt_c)
	if ((rc = system("mv -f " ctmpfilename " " cfilename))) {
		print "'mv -f " ctmpfilename " " cfilename "' failed: " rc \
		    > "/dev/stderr";
		exit 1;
	}

exit 0;

}

--Boundary-01=_WkVyDl0P1s1/7NT--

--nextPart59857029.N3WBgbF9Rf
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (FreeBSD)

iD8DBQBDyVkbXyyEoT62BG0RAqmnAJ9uWS0xX0EJsUPIJT6cAbkjb9PxvgCcCGBM
ev330JomnKqEUGgRmb7btFY=
=Hj79
-----END PGP SIGNATURE-----

--nextPart59857029.N3WBgbF9Rf--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200601142103.39181.max>