MAKEDEV.sub revision 1.6
1dnl $OpenBSD: MAKEDEV.sub,v 1.6 2002/02/14 05:50:37 todd Exp $ 2dnl 3dnl Copyright (c) 2001 Todd T. Fries <todd@OpenBSD.org> 4dnl All rights reserved. 5dnl 6dnl Redistribution and use in source and binary forms, with or without 7dnl modification, are permitted provided that the following conditions 8dnl are met: 9dnl 1. Redistributions of source code must retain the above copyright 10dnl notice, this list of conditions and the following disclaimer. 11dnl 2. The name of the author may not be used to endorse or promote products 12dnl derived from this software without specific prior written permission. 13dnl 14dnl THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 15dnl INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 16dnl AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 17dnl THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18dnl EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19dnl PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 20dnl OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 21dnl WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 22dnl OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 23dnl ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24dnl 25dnl 26dnl This file is an m4 file 27dnl 28dnl Conventions: 29dnl 30dnl o First, a change of quote to make shell statements like: `command` 31dnl possible 32dnl 33changequote(`{-', `-}')dnl 34dnl 35dnl o version info must be stripped of $ so we can say 'generated from' below 36dnl 37dnl If we just use the version string how are we going to know what arch 38dnl 'MAKEDEV.md,v' came from? 39dnl 40dnl Thus, I have used the below to create a version string looking like 41dnl 'OpenBSD: etc.sparc/MAKEDEV.inc,v...' which works, although requires 42dnl some attention if ported to another Id string setup. 43dnl 44dnl 45dnl Initialize the stacks stored in _m4_* 46dnl 47undefine({-_m4_cvs_ver-})dnl 48pushdef({-_m4_cvs_ver-}, {-done-})dnl 49dnl 50undefine({-_m4_devs-})dnl 51pushdef({-_m4_devs-}, {-done-})dnl 52dnl 53undefine({-_m4_disks-})dnl 54undefine({-_m4_disks2-})dnl 55pushdef({-_m4_disks-}, {-done-})dnl 56pushdef({-_m4_disks2-}, {-done-})dnl 57dnl 58dnl define stack 'add to' functions, only unique names queued 59dnl 60define({-ver_q-}, {-ifelse(index($1_ver, y), 0, , 61{-pushdef({-_m4_cvs_ver-}, {-$2-})define({-$1_ver-}, {-y-})-})-})dnl ver_q 62dnl 63define({-dev_q-}, {-ifelse(index(_q_$1_dev, :), 0, 64{-errprint({-duplicated dev id: $1 at -}__file__{-:-}__line__ originally at _q_$1_dev)-}, 65{-pushdef({-_m4_devs-}, {-$1-})dnl 66define({-_q_$1_dev-}, {-:-}__file__{-:-}__line__)-})-})dnl dev_q 67dnl 68define({-disk_q-}, {-ifelse(index(_q_$1_disk, :), 0, 69{-errprint({-duplicated disk id: $1 at -}__file__{-:-}__line__ originally at _q_$1_disk)-}, {-pushdef({-_m4_disks-}, {-$1-})dnl 70pushdef({-_m4_disks2-}, {-$1-})dnl 71define({-_q_$1_disks-}, {-:-}__file__{-:-}__line__)-})-})dnl disk_q 72dnl 73dnl store a version string for 'this' file 74dnl 75dnl vers ( uniqueidstring, versionstring, subdir ) 76dnl 77dnl example1: vers(__file__, {-$OpenBSD: MAKEDEV.sub,v 1.6 2002/02/14 05:50:37 todd Exp $-}) 78dnl example2: vers(__file__, {-$OpenBSD: MAKEDEV.sub,v 1.6 2002/02/14 05:50:37 todd Exp $-}, etc.MACHINE) 79dnl 80dnl if subdir is defined, prepend it to the filename in the version string 81dnl 82define({-vers-}, 83{-ifelse({-$3-}, {--}, 84{-ver_q(hstcl({-$1-}), {-translit({-{-$2-}-}, {-$-}, {--})-})-}, 85{-ver_q(hstcl({-$1-}), {-_addsubdir({-{-$2-}-}, $3)-})-})-})dnl 86dnl 87dnl Version info for this file: 88dnl 89vers(__file__, {-$OpenBSD: MAKEDEV.sub,v 1.6 2002/02/14 05:50:37 todd Exp $-})dnl 90dnl 91dnl 92define({-_addsubdir-}, 93{-patsubst({-$1-}, {-\$(OpenBSD:) ([^\$]*)\$-}, {-\1 $2/\2-})-})dnl 94dnl 95dnl do the 'showing' of the version info 96dnl 97define({-do_vers-}, {-# $1-})dnl 98dnl 99dnl show version function, to be called at the place when all versions are 100dnl queued, and it is time to show all of them 101dnl 102define({-show_vers-}, 103{-ifelse(_m4_cvs_ver, {-done-}, {--}, 104{-do_vers(_m4_cvs_ver) 105popdef({-_m4_cvs_ver-})dnl 106show_vers()dnl 107-})-})dnl 108dnl 109dnl show the routines to generate devices 110define({-show_devs-}, 111{-ifelse(_m4_devs, {-done-}, {--}, 112{-_MKDEV(_m4_devs){--}dnl 113popdef({-_m4_devs-})dnl 114show_devs()dnl 115-})-})dnl 116dnl 117dnl routines to generate disks 118define({-show_disks-}, 119{-ifelse(_m4_disks, {-done-}, {--}, 120{-ifcase(_m4_disks, _m4_disks{--}*)dnl 121popdef({-_m4_disks-})dnl 122show_disks()dnl 123-})-})dnl 124dnl 125define({-show_disks2-}, 126{-ifelse(_m4_disks2, {-done-}, {--}, 127{-CasE(_m4_disks2)dnl 128popdef({-_m4_disks2-})dnl 129show_disks2()dnl 130-})-})dnl 131dnl 132dnl 133dnl Some m4 math functions: 134dnl 135dnl Add(a, b) - displays the result of a+b 136dnl Mult(a, b) - displays the result of a*b 137dnl trunc a b - displays the string a minus b removed from the RHS 138dnl hex a - displays the hex equivalent of 0-15 139dnl unt a - s/[a-z]*([0-9]*).*/\1/ aka sd0a -> 0 140dnl 141dnl Functions: 142dnl 143dnl --> Addition 144dnl 145define({-Add-}, {-$({-(-}$1+$2{-)-})-})dnl 146dnl 147dnl --> Multiplication 148dnl 149define({-Mult-}, {-$({-(-}$1*$2{-)-})-})dnl 150dnl 151dnl 152dnl TRUNC 153dnl 154define({-expr_trunc-}, {-$1trunc() 155$1{ 156$1 case {-$-}3 in 157$1 l) {-expr-} {-$-}1 : '\(.*\)'{-$-}2 ;; 158$1 r|*) {-expr-} ${--}1 : ${--}2'\(.*\)' ;; 159$1 esac 160$1}-})dnl 161dnl 162dnl 163define({-_SHELL-}, {-sh-})dnl 164define({-_this-}, {-{-$-}T-})dnl 165dnl define({-_recurse-}, {-_SHELL _this-})dnl 166define({-_recurse-}, {-R-})dnl 167dnl 168dnl _devitem(pattern, description) 169dnl 170define({-_devitem-}, 171{-{-#-} $1 {-$2-}-})dnl 172dnl 173dnl _devtitle(description) 174dnl 175define({-_devtitle-}, {-{-#-} $1:-})dnl 176dnl 177dnl _DEV(name, [character major], [block major]) 178dnl 179define({-_DEV-}, {-$1_dev{--}dnl 180dnl 181dnl _DEV 'ifelse' .. $2 - major_$1_c 182dnl 183ifelse($2, , , {-define(major_$1_c, $2)-})dnl 184dnl 185dnl _DEV 'ifelse' .. $3 - major_$1_b 186dnl 187ifelse($3, , , {-define(major_$1_b, $3)-})dnl 188dnl 189dnl _DEV 'ifelse' .. $4 - step_$1 190dnl 191ifelse($4, , , {-define(step_$1, {-$4-})-})dnl 192dnl 193dnl Some magic here, defining a devitem also defines another 194dnl string so that later we can check if a particular devitem was 195dnl defined, and thus determine if the devices themselves are to 196dnl be built 197dnl 198define({-$1__DEV-}, {-Y-})dnl 199dnl 200dnl More magic, put device string name into a queue of script segments to 201dnl be shown later if it has been defined as a device in MAKEDEV.mi 202dnl 203ifdef({-$1_mkdev-}, {-__mkdev({-$1-})-})dnl 204dnl 205dnl 206-})dnl _DEV 207dnl 208dnl 209define({-ifdev-}, {-ifelse($1__DEV, Y, {-$2-})-})dnl 210dnl 211define({-_MKDEV-}, {-$1_mkdev-})dnl 212define({-_TITLE-}, {-$1_title-})dnl 213define({-__devitem-}, {-define($1_dev, {-_devitem($2, $3)-})$4-})dnl 214define({-__devtitle-}, {-define($1_title, {-_devtitle($2)-})-})dnl 215dnl 216dnl Beginning and ending of case entries, just incase we change in the 217dnl future, save chasing things down again 218dnl 219define({-_end-}, {- 220 ;; 221 222-})dnl 223define({-_beg-}, {-{-)-} 224 -})dnl 225dnl 226dnl create the script segment for making devices 227dnl $1 $2 $3 228dnl _mkdev(shortname, devpatt, action)dnl 229define({-_mkdev-}, {-define($1_mkdev, {-$2{--}_beg{--}$3{--}_end-})-})dnl 230dnl 231dnl define a major character device 232dnl $1 $2 $3 $4 233dnl _mcdev(shortname, devpatt, devbase, devmajor)dnl 234dnl 235define({-_mcdev-}, {-define($1_mkdev, {-{-$2-}_beg{--}M $3$U c $4 $U{--}dnl 236ifelse($6, , ifelse($5, , , {- -}$5), {- -}ifelse($5, , 600, $5){- -}$6){--}_end-})-})dnl 237dnl 238dnl $1 $2 $3 $4 $5 $6 239dnl _cdev(shortname, devpatt, devmajor, devminor[, devmod, devgrp])dnl 240define({-_cdev-}, 241{-dnl 242define($1_mkdev, {-$2{--}_beg{--}M $2 c $3 $4 $5 $6{--}_end-}){--}-})dnl 243dnl 244dnl 245define({-__mkdev-}, {-dev_q($1)-})dnl 246dnl 247dnl for showing disks 248dnl 249define({-CasE-}, 250{-ifdev({-$1-}, 251{- $1*) dodisk $1 $U major_$1_b major_$1_c $U 0{--}ifstep($1);; 252-})-})dnl 253dnl 254dnl 255define({-ifcase-}, {-dnl 256ifelse(C_ase, Y, ifdev({-$1-}, {-|$2-}), 257{-ifdev({-$1-}, {-$2define({-C_ase-}, Y)-})-})-})dnl 258dnl 259dnl 260dnl device list .. list devices 'iff' they are defined 261dnl 262dnl input: 263dnl 264dnl _dl({-usb-}, {-usb0 usb1-}, {-urio-}, {-urio-}, ...) 265dnl 266dnl output: 267dnl 268dnl {-<tab>_recurse usb0 usb1 urio 269dnl <tab>_recurse uhid0 uhid2 uhid3-} 270dnl 271dnl wrap if more than 60 chars wide 272dnl 273dnl .. wrap it all up in an 'ifelse({-$1-}, , {- ... -})' for neatness ?? 274dnl 275define({-_dl-}, {-dnl 276ifdef({-_dt-}, , {-define({-_dt-})-})dnl 277ifdef({-_do-}, , {-_dt{--}_recurse{--}define({-_do-}, 0)dnl 278define({-_dt-}, {- -})-})dnl 279ifdef({-$1__DEV-}, 280{-define({-_di-}, {-$2-})-}, 281{-define({-_di-})-})dnl 282ifelse(eval(len(_di)+_do<60), 1, 283{-ifelse(eval(len(_di)>0), 1, 284{- _di{--}define({-_do-}, eval(1+_do+len(_di)))-})-}, 285{- 286_dt{--}_recurse _di{--}dnl 287define({-_do-}, len(_di))-})dnl 288ifelse({-$3-}, {--}, 289{-undefine({-_dt-}, {-_do-})-}, dnl <--- The END 290{-_dl(shift(shift($@)))-})-})dnl 291dnl 292dnl 293define({-_show_target-}, {-dnl 294ifdef({-$1__DEV-}, {-disp_dev({-$2-})-})dnl 295ifelse({-$3-}, {--}, 296{-_disp_dev_end()-}, dnl <--- The END 297{-_show_target(shift(shift($@)))-})-})dnl 298dnl 299define({-disp_dev-}, {-dnl 300ifdef({-_disp_dev_tab-}, , {-define({-_disp_dev_tab-})-})dnl 301ifdef({-_disp_dev_len-}, , {-dnl 302define({-_disp_dev_len-}, 0)dnl 303_disp_dev_tab{--}_recurse{--}dnl 304define({-_disp_dev_tab-}, {- -})-})dnl 305ifelse(eval(len($1)+_disp_dev_len<60), 1, 306{- $1{--}define({-_disp_dev_len-}, eval(1+_disp_dev_len+len($1)))-}, {- 307_disp_dev_tab{--}_recurse $1{--}dnl 308define({-_disp_dev_len-}, len($1))-})dnl 309-})dnl 310define({-_disp_dev_end-}, {-undefine({-_disp_dev_tab-}, {-_disp_dev_len-})-})dnl 311dnl 312dnl A word about the above: 313dnl 314dnl _dt -> 'tab' .. at first, defined to nothing, as the tab is already there 315dnl then define it to a tab every time through 316dnl undefine it at the end 317dnl 318dnl _do -> 'old' count .. stores the length of the old string already displayed 319dnl it is initialized to 0, added to the length plus 1 of '_di' each 320dnl iteration the line is less than 60 chars long 321dnl undefined at the end 322dnl _di -> 'iteration' string .. the string used in this iteration, is empty if 323dnl the device does not exist 324dnl 325dnl 326dnl ifstep(devstr) 327dnl .. if stepping is defined for the particular device, emit ' step', else 328dnl nothing 329define({-ifstep-}, {-ifdef({-step_$1-}, {- -}step_$1{--})-})dnl 330dnl 331dnl 332define({-target-}, {-twrget({-$1-}, {-$2-}, {-$2-}, shift(shift($@)))-})dnl 333dnl 334dnl twrget(target, devname, prefix, str1, str2, str3) 335dnl $1 $2 $3 $4 $5 $6 336dnl 337define({-twrget-}, {-dnl 338dnl 339ifdef({-$1_target-}, , {-pushdef({-$1_target-}, {-done-})-})dnl 340dnl 341ifelse({-$4-}, , , {-dnl 342ifelse({-$4-}, {-_done-}, , {-dnl 343ifelse({-$5-}, , , {-dnl 344dnl errprint({-recurse: $1, $2, $3, $4, $5, $6, ...-})dnl 345twrget({-$1-}, {-$2-}, {-$3-}, shift(shift(shift(shift($@)))))dnl 346-})-})-})dnl 347dnl 348ifelse({-$4-}, {-_done-}, , {-dnl 349dnl errprint({-recurse: $1_$2_dev, $3$4, $3$4, _done-})dnl 350twrget({-$1_$2_dev-}, {-$3$4-}, {-$3$4-}, {-_done-})dnl 351-})dnl 352dnl 353ifdef({-$1$2target-}, , {-dnl 354pushdef({-$1_target-}, {-$2-})define({-$1$2target-})dnl 355-})dnl 356dnl 357-})dnl 358dnl 359dnl 360define({-show_target-}, {-dnl 361ifelse($1_target, {-done-}, {-_disp_dev_end()-}, 362{-dnl $1_target: 363show_dev($1, -}$1_target{-)dnl 364popdef({-$1_target-})dnl 365show_target({-$1-})dnl 366-})-})dnl 367dnl 368define({-show_dev-}, {-dnl 369ifdef({-$2__DEV-}, {-dnl 370ifelse($1_$2_dev_target, {-done-}, , {-dnl 371disp_dev({-$1_$2_dev_target-})dnl 372popdef({-$1_$2_dev_target-})dnl 373show_dev({-$1-}, {-$2-})-})dnl 374-})dnl 375-})dnl 376dnl 377