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

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

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