[BACK]Return to MAKEDEV.sub CVS log [TXT][DIR] Up to [local] / src / etc

Annotation of src/etc/MAKEDEV.sub, Revision 1.10

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