From 9fcd8dadfee3d4b713fb4a0bdc1eb0e2a256b67a Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Mon, 9 Jul 2018 23:09:21 -0400 Subject: [PATCH] freebsd11_network: Adopt the generation of usbdevs.h. The only thing using it at present is the "pegasus" driver, so it already doesn't make a lot of sense to keep it in src/apps/devices. Since in the future it will be used by FreeBSD USB network drivers, it makes sense for the FreeBSD compat layer to adopt it. Also some related cleanup to the awk files -- they are now stored in a "tools" subdirectory, which is more similar to where FreeBSD does it. We are also now using FreeBSD's usbdevs2h.awk instead of NetBSD's, as this seems to fit with the overall schema. --- .../kernel/drivers/network/pegasus/Jamfile | 7 +- src/apps/devices/Jamfile | 19 -- src/libs/compat/freebsd11_network/Jamfile | 21 +- .../freebsd11_network/compat/dev/usb}/usbdevs | 0 .../{ => tools}/miidevs2h.awk | 0 .../freebsd11_network/tools/usbdevs2h.awk} | 205 ++++++++++-------- 6 files changed, 143 insertions(+), 109 deletions(-) rename src/{apps/devices => libs/compat/freebsd11_network/compat/dev/usb}/usbdevs (100%) rename src/libs/compat/freebsd11_network/{ => tools}/miidevs2h.awk (100%) rename src/{apps/devices/usb_devlist2h.awk => libs/compat/freebsd11_network/tools/usbdevs2h.awk} (62%) diff --git a/src/add-ons/kernel/drivers/network/pegasus/Jamfile b/src/add-ons/kernel/drivers/network/pegasus/Jamfile index ba022920f9..07609ce6a9 100644 --- a/src/add-ons/kernel/drivers/network/pegasus/Jamfile +++ b/src/add-ons/kernel/drivers/network/pegasus/Jamfile @@ -13,8 +13,7 @@ KernelAddon pegasus : if_aue.c ; -# driver.c currently needs usbdevs.h so we make its path available and adds dependency ObjectHdrs [ FGristFiles driver$(SUFOBJ) if_aue$(SUFOBJ) ] - : [ FDirName $(TARGET_COMMON_DEBUG_OBJECT_DIR_$(TARGET_PACKAGING_ARCH)) apps - devices ] ; -Includes [ FGristFiles driver.c if_aue.c ] : usbdevs.h ; + : [ FDirName $(TARGET_COMMON_DEBUG_OBJECT_DIR_$(TARGET_PACKAGING_ARCH)) libs + compat freebsd11_network ] ; +Includes [ FGristFiles driver.c if_aue.c ] : usbdevs.h ; diff --git a/src/apps/devices/Jamfile b/src/apps/devices/Jamfile index c884f762a4..bf09be9cc7 100644 --- a/src/apps/devices/Jamfile +++ b/src/apps/devices/Jamfile @@ -25,25 +25,6 @@ actions ISAPnPHeaderGen1 ISAPnPHeaderGen [ FGristFiles isapnpids.h ] : isapnp_devids.txt : devlist2h.awk ; -rule USBDevsHeaderGen -{ - SEARCH on $(2) = $(SEARCH_SOURCE) ; - SEARCH on $(3) = $(SEARCH_SOURCE) ; - - Depends $(1) : $(2) $(3) ; - MakeLocateArch $(<) ; - USBDevsHeaderGen1 $(1) : $(2) $(3) ; - LocalClean clean : $(<) ; -} - -actions USBDevsHeaderGen1 -{ - gawk -v HEADERFILE=$(1[1]) -v DATAFILE=$(1[2]) -f $(2[2]) $(2[1]) -} - -USBDevsHeaderGen [ FGristFiles usbdevs.h usbdevs_data.h ] : usbdevs - : usb_devlist2h.awk ; - rule PCIHeaderGen { SEARCH on $(3) = $(SEARCH_SOURCE) ; diff --git a/src/libs/compat/freebsd11_network/Jamfile b/src/libs/compat/freebsd11_network/Jamfile index a91c44c88a..54b8e01350 100644 --- a/src/libs/compat/freebsd11_network/Jamfile +++ b/src/libs/compat/freebsd11_network/Jamfile @@ -52,7 +52,7 @@ KernelStaticLibrary libfreebsd11_network.a : rule MIIHeaderGen { SEARCH on $(2) = [ FDirName $(SUBDIR) compat dev mii ] ; - SEARCH on $(3) = $(SEARCH_SOURCE) ; + SEARCH on $(3) = [ FDirName $(SUBDIR) tools ] ; Depends $(1) : $(2) $(3) ; MakeLocateArch $(<) ; @@ -66,3 +66,22 @@ actions MIIHeaderGen1 } MIIHeaderGen [ FGristFiles miidevs.h ] : miidevs : miidevs2h.awk ; + +rule USBDevsHeaderGen +{ + SEARCH on $(2) = [ FDirName $(SUBDIR) compat dev usb ] ; + SEARCH on $(3) = [ FDirName $(SUBDIR) tools ] ; + + Depends $(1) : $(2) $(3) ; + MakeLocateArch $(<) ; + USBDevsHeaderGen1 $(1) : $(2) $(3) ; + LocalClean clean : $(<) ; +} + +actions USBDevsHeaderGen1 +{ + gawk -v HEADERFILE=$(1[1]) -v DATAFILE=$(1[2]) -f $(2[2]) $(2[1]) +} + +USBDevsHeaderGen [ FGristFiles usbdevs.h usbdevs_data.h ] : usbdevs + : usbdevs2h.awk ; diff --git a/src/apps/devices/usbdevs b/src/libs/compat/freebsd11_network/compat/dev/usb/usbdevs similarity index 100% rename from src/apps/devices/usbdevs rename to src/libs/compat/freebsd11_network/compat/dev/usb/usbdevs diff --git a/src/libs/compat/freebsd11_network/miidevs2h.awk b/src/libs/compat/freebsd11_network/tools/miidevs2h.awk similarity index 100% rename from src/libs/compat/freebsd11_network/miidevs2h.awk rename to src/libs/compat/freebsd11_network/tools/miidevs2h.awk diff --git a/src/apps/devices/usb_devlist2h.awk b/src/libs/compat/freebsd11_network/tools/usbdevs2h.awk similarity index 62% rename from src/apps/devices/usb_devlist2h.awk rename to src/libs/compat/freebsd11_network/tools/usbdevs2h.awk index 3bd7f80d79..ff632ce4cd 100644 --- a/src/apps/devices/usb_devlist2h.awk +++ b/src/libs/compat/freebsd11_network/tools/usbdevs2h.awk @@ -1,5 +1,9 @@ #! /usr/bin/awk -f -# $NetBSD: devlist2h.awk,v 1.11 2003/12/15 07:32:21 jmc Exp $ +#- +# $NetBSD: usb/devlist2h.awk,v 1.9 2001/01/18 20:28:22 jdolecek Exp $ +# $FreeBSD$ +# +# SPDX-License-Identifier: BSD-4-Clause # # Copyright (c) 1995, 1996 Christopher G. Demetriou # All rights reserved. @@ -29,152 +33,134 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # -BEGIN { - nproducts = nvendors = blanklines = 0 - dfile=DATAFILE - hfile=HEADERFILE + +function usage() +{ + print "usage: usbdevs2h.awk [-d|-h]"; + exit 1; } -NR == 1 { - VERSION = $0 - gsub("\\$", "", VERSION) - printf("/*\n") > dfile +function header(file) +{ + printf("/*\n") > file printf(" * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \ - > dfile - printf(" *\n") > dfile - printf(" * generated from:\n") > dfile - printf(" *\t%s\n", VERSION) > dfile - printf(" */\n") > dfile - - printf("/*\n") > hfile - printf(" * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \ - > hfile - printf(" *\n") > hfile - printf(" * generated from:\n") > hfile - printf(" *\t%s\n", VERSION) > hfile - printf(" */\n") > hfile - - next + > file + printf(" *\n") > file + printf(" * generated from:\n") > file + printf(" *\t%s\n", VERSION) > file + printf(" */\n") > file } -NF > 0 && $1 == "vendor" { + +function vendor(hfile) +{ nvendors++ vendorindex[$2] = nvendors; # record index for this name, for later. vendors[nvendors, 1] = $2; # name vendors[nvendors, 2] = $3; # id - printf("#define\tUSB_VENDOR_%s\t%s\t", vendors[nvendors, 1], - vendors[nvendors, 2]) > hfile - + if (hfile) + printf("#define\tUSB_VENDOR_%s\t%s\t", vendors[nvendors, 1], + vendors[nvendors, 2]) > hfile i = 3; f = 4; # comments ocomment = oparen = 0 if (f <= NF) { - printf("\t/* ") > hfile + if (hfile) + printf("\t/* ") > hfile ocomment = 1; } while (f <= NF) { if ($f == "#") { - printf("(") > hfile + if (hfile) + printf("(") > hfile oparen = 1 f++ continue } if (oparen) { - printf("%s", $f) > hfile - if (f < NF) + if (hfile) + printf("%s", $f) > hfile + if (f < NF && hfile) printf(" ") > hfile f++ continue } vendors[nvendors, i] = $f - printf("%s", vendors[nvendors, i]) > hfile - if (f < NF) + if (hfile) + printf("%s", vendors[nvendors, i]) > hfile + if (f < NF && hfile) printf(" ") > hfile i++; f++; } - if (oparen) + if (oparen && hfile) printf(")") > hfile - if (ocomment) + if (ocomment && hfile) printf(" */") > hfile - printf("\n") > hfile - - next + if (hfile) + printf("\n") > hfile } -NF > 0 && $1 == "product" { + +function product(hfile) +{ nproducts++ products[nproducts, 1] = $2; # vendor name products[nproducts, 2] = $3; # product id products[nproducts, 3] = $4; # id - printf("#define\tUSB_PRODUCT_%s_%s\t%s\t", products[nproducts, 1], - products[nproducts, 2], products[nproducts, 3]) > hfile + if (hfile) + printf("#define\tUSB_PRODUCT_%s_%s\t%s\t", \ + products[nproducts, 1], products[nproducts, 2], \ + products[nproducts, 3]) > hfile i=4; f = 5; # comments ocomment = oparen = 0 if (f <= NF) { - printf("\t/* ") > hfile + if (hfile) + printf("\t/* ") > hfile ocomment = 1; } while (f <= NF) { if ($f == "#") { - printf("(") > hfile + if (hfile) + printf("(") > hfile oparen = 1 f++ continue } if (oparen) { - printf("%s", $f) > hfile - if (f < NF) + if (hfile) + printf("%s", $f) > hfile + if (f < NF && hfile) printf(" ") > hfile f++ continue } products[nproducts, i] = $f - printf("%s", products[nproducts, i]) > hfile - if (f < NF) + if (hfile) + printf("%s", products[nproducts, i]) > hfile + if (f < NF && hfile) printf(" ") > hfile i++; f++; } - if (oparen) + if (oparen && hfile) printf(")") > hfile - if (ocomment) + if (ocomment && hfile) printf(" */") > hfile - printf("\n") > hfile - - next + if (hfile) + printf("\n") > hfile } + +function dump_dfile(dfile) { - if ($0 == "") - blanklines++ - print $0 > hfile - if (blanklines < 2) - print $0 > dfile -} -END { - # print out the match tables - printf("\n") > dfile - printf("typedef uint16 usb_vendor_id_t;\n") > dfile - printf("typedef uint16 usb_product_id_t;\n") > dfile - printf("struct usb_knowndev {\n") > dfile - printf(" usb_vendor_id_t vendor;\n") > dfile - printf(" usb_product_id_t product;\n") > dfile - printf(" int flags;\n") > dfile - printf(" char *vendorname, *productname;\n") > dfile - printf("};\n") > dfile - printf("\n") > dfile - printf("#define USB_KNOWNDEV_NOPROD 0x01 /* match on vendor only */\n") > dfile - printf("\n") > dfile - printf("const struct usb_knowndev usb_knowndevs[] = {\n") > dfile for (i = 1; i <= nproducts; i++) { printf("\t{\n") > dfile printf("\t USB_VENDOR_%s, USB_PRODUCT_%s_%s,\n", - products[i, 1], products[i, 1], products[i, 2]) \ - > dfile + products[i, 1], products[i, 1], products[i, 2]) > dfile printf("\t ") > dfile printf("0") > dfile printf(",\n") > dfile @@ -183,7 +169,7 @@ END { printf("\t \"") > dfile j = 3; needspace = 0; - while ((vendi, j) in vendors) { + while (vendors[vendi, j] != "") { if (needspace) printf(" ") > dfile printf("%s", vendors[vendi, j]) > dfile @@ -195,7 +181,7 @@ END { printf("\t \"") > dfile j = 4; needspace = 0; - while ((i, j) in products) { + while (products[i, j] != "") { if (needspace) printf(" ") > dfile printf("%s", products[i, j]) > dfile @@ -207,14 +193,12 @@ END { } for (i = 1; i <= nvendors; i++) { printf("\t{\n") > dfile - printf("\t USB_VENDOR_%s, 0,\n", vendors[i, 1]) \ - > dfile - printf("\t USB_KNOWNDEV_NOPROD,\n") \ - > dfile + printf("\t USB_VENDOR_%s, 0,\n", vendors[i, 1]) > dfile + printf("\t USB_KNOWNDEV_NOPROD,\n") > dfile printf("\t \"") > dfile j = 3; needspace = 0; - while ((i, j) in vendors) { + while (vendors[i, j] != "") { if (needspace) printf(" ") > dfile printf("%s", vendors[i, j]) > dfile @@ -227,6 +211,57 @@ END { } printf("\t{ 0, 0, 0, NULL, NULL, }\n") > dfile printf("};\n") > dfile - close(dfile) - close(hfile) +} + +BEGIN { + +nproducts = nvendors = 0 +dfile=DATAFILE +hfile=HEADERFILE +# Process the command line +for (i = 1; i < ARGC; i++) { + arg = ARGV[i]; + if (arg !~ /^-[dh]+$/ && arg !~ /devs$/) + usage(); +# if (arg ~ /^-.*d/) +# dfile="usbdevs_data.h" +# if (arg ~ /^-.*h/) +# hfile="usbdevs.h" + if (arg ~ /devs$/) + srcfile = arg; +} +ARGC = 1; +line=0; + +while ((getline < srcfile) > 0) { + line++; + if (line == 1) { + VERSION = $0 + gsub("\\$", "", VERSION) + if (dfile) + header(dfile) + if (hfile) + header(hfile) + continue; + } + if ($1 == "vendor") { + vendor(hfile) + continue + } + if ($1 == "product") { + product(hfile) + continue + } + if ($0 == "") + blanklines++ + if (hfile) + print $0 > hfile + if (blanklines < 2 && dfile) + print $0 > dfile +} + +# print out the match tables + +if (dfile) + dump_dfile(dfile) }