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

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

1.6     ! todd        1: dnl    $OpenBSD: MAKEDEV.sub,v 1.5 2002/01/23 06:02:19 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
1.6     ! todd       33: changequote(`{-', `-}')dnl
1.1       todd       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
1.6     ! todd       48: pushdef({-_m4_cvs_ver-}, {-done-})dnl
1.1       todd       49: dnl
                     50: undefine({-_m4_devs-})dnl
1.6     ! todd       51: pushdef({-_m4_devs-}, {-done-})dnl
1.1       todd       52: dnl
                     53: undefine({-_m4_disks-})dnl
                     54: undefine({-_m4_disks2-})dnl
1.6     ! todd       55: pushdef({-_m4_disks-}, {-done-})dnl
        !            56: pushdef({-_m4_disks2-}, {-done-})dnl
1.1       todd       57: dnl
                     58: dnl define stack 'add to' functions, only unique names queued
                     59: dnl
1.6     ! todd       60: define({-ver_q-}, {-ifelse(index($1_ver, y), 0, ,
        !            61: {-pushdef({-_m4_cvs_ver-}, {-$2-})define({-$1_ver-}, {-y-})-})-})dnl ver_q
1.1       todd       62: dnl
1.6     ! todd       63: define({-dev_q-}, {-ifelse(index(_q_$1_dev, :), 0,
1.1       todd       64: {-errprint({-duplicated dev id: $1 at -}__file__{-:-}__line__ originally at _q_$1_dev)-},
1.6     ! todd       65: {-pushdef({-_m4_devs-}, {-$1-})dnl
        !            66: define({-_q_$1_dev-}, {-:-}__file__{-:-}__line__)-})-})dnl dev_q
1.1       todd       67: dnl
1.6     ! todd       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
1.1       todd       72: dnl
                     73: dnl store a version string for 'this' file
                     74: dnl
                     75: dnl vers ( uniqueidstring, versionstring, subdir )
                     76: dnl
1.6     ! todd       77: dnl example1: vers(__file__, {-$OpenBSD: MAKEDEV.sub,v 1.5 2002/01/23 06:02:19 todd Exp $-})
        !            78: dnl example2: vers(__file__, {-$OpenBSD: MAKEDEV.sub,v 1.5 2002/01/23 06:02:19 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-},
1.6     ! todd       83: {-ifelse({-$3-}, {--},
        !            84: {-ver_q(hstcl({-$1-}), {-translit({-{-$2-}-}, {-$-}, {--})-})-},
        !            85: {-ver_q(hstcl({-$1-}), {-_addsubdir({-{-$2-}-}, $3)-})-})-})dnl
1.1       todd       86: dnl
                     87: dnl Version info for this file:
                     88: dnl
1.6     ! todd       89: vers(__file__, {-$OpenBSD: MAKEDEV.sub,v 1.5 2002/01/23 06:02:19 todd Exp $-})dnl
1.1       todd       90: dnl
                     91: dnl
                     92: define({-_addsubdir-},
1.6     ! todd       93: {-patsubst({-$1-}, {-\$(OpenBSD:) ([^\$]*)\$-}, {-\1 $2/\2-})-})dnl
1.1       todd       94: dnl
                     95: dnl do the 'showing' of the version info
                     96: dnl
1.6     ! todd       97: define({-do_vers-}, {-#        $1-})dnl
1.1       todd       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-},
1.6     ! todd      103: {-ifelse(_m4_cvs_ver, {-done-}, {--},
1.1       todd      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-},
1.6     ! todd      111: {-ifelse(_m4_devs, {-done-}, {--},
1.1       todd      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-},
1.6     ! todd      119: {-ifelse(_m4_disks, {-done-}, {--},
        !           120: {-ifcase(_m4_disks, _m4_disks{--}*)dnl
1.1       todd      121: popdef({-_m4_disks-})dnl
                    122: show_disks()dnl
                    123: -})-})dnl
                    124: dnl
                    125: define({-show_disks2-},
1.6     ! todd      126: {-ifelse(_m4_disks2, {-done-}, {--},
1.1       todd      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
1.6     ! todd      135: dnl   Add(a, b)           - displays the result of a+b
        !           136: dnl   Mult(a, b)          - displays the result of a*b
1.1       todd      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
1.6     ! todd      145: define({-Add-}, {-$({-(-}$1+$2{-)-})-})dnl
1.1       todd      146: dnl
                    147: dnl --> Multiplication
                    148: dnl
1.6     ! todd      149: define({-Mult-}, {-$({-(-}$1*$2{-)-})-})dnl
1.1       todd      150: dnl
                    151: dnl
                    152: dnl TRUNC
                    153: dnl
1.6     ! todd      154: define({-expr_trunc-}, {-$1trunc()
1.1       todd      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
1.6     ! todd      163: define({-_SHELL-}, {-sh-})dnl
        !           164: define({-_this-}, {-{-$-}T-})dnl
        !           165: dnl define({-_recurse-}, {-_SHELL _this-})dnl
        !           166: define({-_recurse-}, {-R-})dnl
1.1       todd      167: dnl
1.6     ! todd      168: dnl _devitem(pattern, description)
1.1       todd      169: dnl
                    170: define({-_devitem-},
                    171: {-{-#-}        $1      {-$2-}-})dnl
                    172: dnl
                    173: dnl _devtitle(description)
                    174: dnl
1.6     ! todd      175: define({-_devtitle-}, {-{-#-} $1:-})dnl
1.1       todd      176: dnl
1.6     ! todd      177: dnl _DEV(name, [character major], [block major])
1.1       todd      178: dnl
1.6     ! todd      179: define({-_DEV-}, {-$1_dev{--}dnl
1.1       todd      180: dnl
                    181: dnl _DEV 'ifelse' .. $2 - major_$1_c
                    182: dnl
1.6     ! todd      183: ifelse($2, , , {-define(major_$1_c, $2)-})dnl
1.1       todd      184: dnl
1.2       todd      185: dnl _DEV 'ifelse' .. $3 - major_$1_b
1.1       todd      186: dnl
1.6     ! todd      187: ifelse($3, , , {-define(major_$1_b, $3)-})dnl
1.1       todd      188: dnl
1.4       todd      189: dnl _DEV 'ifelse' .. $4 - step_$1
                    190: dnl
1.6     ! todd      191: ifelse($4, , , {-define(step_$1, {-$4-})-})dnl
1.4       todd      192: dnl
1.1       todd      193: dnl Some magic here, defining a devitem also defines another
                    194: dnl string so that later we can check if a particular devitem was
                    195: dnl defined, and thus determine if the devices themselves are to
                    196: dnl be built
                    197: dnl
1.6     ! todd      198: define({-$1__DEV-}, {-Y-})dnl
1.1       todd      199: dnl
                    200: dnl More magic, put device string name into a queue of script segments to
1.2       todd      201: dnl be shown later if it has been defined as a device in MAKEDEV.mi
1.1       todd      202: dnl
1.6     ! todd      203: ifdef({-$1_mkdev-}, {-__mkdev({-$1-})-})dnl
1.1       todd      204: dnl
                    205: dnl
                    206: -})dnl _DEV
1.2       todd      207: dnl
                    208: dnl
1.6     ! todd      209: define({-ifdev-}, {-ifelse($1__DEV, Y, {-$2-})-})dnl
1.1       todd      210: dnl
1.6     ! todd      211: define({-_MKDEV-}, {-$1_mkdev-})dnl
        !           212: define({-_TITLE-}, {-$1_title-})dnl
        !           213: define({-__devitem-}, {-define($1_dev, {-_devitem($2, $3)-})$4-})dnl
        !           214: define({-__devtitle-}, {-define($1_title, {-_devtitle($2)-})-})dnl
1.1       todd      215: dnl
                    216: dnl Beginning and ending of case entries, just incase we change in the
                    217: dnl future, save chasing things down again
                    218: dnl
1.6     ! todd      219: define({-_end-}, {-
1.1       todd      220:        ;;
                    221:
                    222: -})dnl
1.6     ! todd      223: define({-_beg-}, {-{-)-}
1.1       todd      224:        -})dnl
                    225: dnl
                    226: dnl  create the script segment for making devices
                    227: dnl             $1     $2      $3
1.6     ! todd      228: dnl _mkdev(shortname, devpatt, action)dnl
        !           229: define({-_mkdev-}, {-define($1_mkdev, {-$2{--}_beg{--}$3{--}_end-})-})dnl
1.1       todd      230: dnl
                    231: dnl  define a major character device
                    232: dnl             $1     $2      $3      $4
1.6     ! todd      233: dnl _mcdev(shortname, devpatt, devbase, devmajor)dnl
1.1       todd      234: dnl
1.6     ! todd      235: define({-_mcdev-}, {-define($1_mkdev, {-{-$2-}_beg{--}M $3$U c $4 $U{--}dnl
        !           236: ifelse($6, , ifelse($5, , , {- -}$5), {- -}ifelse($5, , 600, $5){- -}$6){--}_end-})-})dnl
1.1       todd      237: dnl
                    238: dnl         $1        $2      $3        $4       $5      $6
1.6     ! todd      239: dnl _cdev(shortname, devpatt, devmajor, devminor[, devmod, devgrp])dnl
1.1       todd      240: define({-_cdev-},
                    241: {-dnl
1.6     ! todd      242: define($1_mkdev, {-$2{--}_beg{--}M $2 c $3 $4 $5 $6{--}_end-}){--}-})dnl
1.1       todd      243: dnl
                    244: dnl
1.6     ! todd      245: define({-__mkdev-}, {-dev_q($1)-})dnl
1.1       todd      246: dnl
                    247: dnl for showing disks
                    248: dnl
                    249: define({-CasE-},
                    250: {-ifdev({-$1-},
1.4       todd      251: {-     $1*) dodisk $1 $U major_$1_b major_$1_c $U 0{--}ifstep($1);;
1.1       todd      252: -})-})dnl
                    253: dnl
                    254: dnl
1.6     ! todd      255: define({-ifcase-}, {-dnl
        !           256: ifelse(C_ase, Y, ifdev({-$1-}, {-|$2-}),
        !           257: {-ifdev({-$1-}, {-$2define({-C_ase-}, Y)-})-})-})dnl
1.1       todd      258: dnl
                    259: dnl
                    260: dnl device list .. list devices 'iff' they are defined
                    261: dnl
                    262: dnl input:
                    263: dnl
1.6     ! todd      264: dnl    _dl({-usb-}, {-usb0 usb1-}, {-urio-}, {-urio-}, ...)
1.1       todd      265: dnl
                    266: dnl output:
                    267: dnl
                    268: dnl {-<tab>_recurse usb0 usb1 urio
                    269: dnl   <tab>_recurse uhid0 uhid2 uhid3-}
                    270: dnl
                    271: dnl  wrap if more than 60 chars wide
                    272: dnl
1.6     ! todd      273: dnl .. wrap it all up in an 'ifelse({-$1-}, , {- ... -})' for neatness ??
1.1       todd      274: dnl
1.6     ! todd      275: define({-_dl-}, {-dnl
        !           276: ifdef({-_dt-}, , {-define({-_dt-})-})dnl
        !           277: ifdef({-_do-}, , {-_dt{--}_recurse{--}define({-_do-}, 0)dnl
        !           278: define({-_dt-}, {-     -})-})dnl
1.1       todd      279: ifdef({-$1__DEV-},
1.6     ! todd      280: {-define({-_di-}, {-$2-})-},
1.1       todd      281: {-define({-_di-})-})dnl
1.6     ! todd      282: ifelse(eval(len(_di)+_do<60), 1,
        !           283: {-ifelse(eval(len(_di)>0), 1,
        !           284: {- _di{--}define({-_do-}, eval(1+_do+len(_di)))-})-},
1.1       todd      285: {-
                    286: _dt{--}_recurse _di{--}dnl
1.6     ! todd      287: define({-_do-}, len(_di))-})dnl
        !           288: ifelse({-$3-}, {--},
        !           289: {-undefine({-_dt-}, {-_do-})-}, dnl <--- The END
1.1       todd      290: {-_dl(shift(shift($@)))-})-})dnl
                    291: dnl
1.5       todd      292: dnl
1.6     ! todd      293: define({-_show_target-}, {-dnl
        !           294: ifdef({-$1__DEV-}, {-disp_dev({-$2-})-})dnl
        !           295: ifelse({-$3-}, {--},
        !           296: {-_disp_dev_end()-}, dnl <--- The END
1.5       todd      297: {-_show_target(shift(shift($@)))-})-})dnl
                    298: dnl
1.6     ! todd      299: define({-disp_dev-}, {-dnl
        !           300: ifdef({-_disp_dev_tab-}, , {-define({-_disp_dev_tab-})-})dnl
        !           301: ifdef({-_disp_dev_len-}, , {-dnl
        !           302: define({-_disp_dev_len-}, 0)dnl
1.5       todd      303: _disp_dev_tab{--}_recurse{--}dnl
1.6     ! todd      304: define({-_disp_dev_tab-}, {-   -})-})dnl
        !           305: ifelse(eval(len($1)+_disp_dev_len<60), 1,
        !           306: {- $1{--}define({-_disp_dev_len-}, eval(1+_disp_dev_len+len($1)))-}, {-
1.5       todd      307: _disp_dev_tab{--}_recurse $1{--}dnl
1.6     ! todd      308: define({-_disp_dev_len-}, len($1))-})dnl
1.5       todd      309: -})dnl
1.6     ! todd      310: define({-_disp_dev_end-}, {-undefine({-_disp_dev_tab-}, {-_disp_dev_len-})-})dnl
1.5       todd      311: dnl
1.1       todd      312: dnl A word about the above:
                    313: dnl
                    314: dnl _dt -> 'tab' .. at first, defined to nothing, as the tab is already there
                    315: dnl        then define it to a tab every time through
                    316: dnl        undefine it at the end
                    317: dnl
                    318: dnl _do -> 'old' count .. stores the length of the old string already displayed
                    319: dnl        it is initialized to 0, added to the length plus 1 of '_di' each
                    320: dnl        iteration the line is less than 60 chars long
                    321: dnl       undefined at the end
                    322: dnl _di -> 'iteration' string .. the string used in this iteration, is empty if
                    323: dnl        the device does not exist
                    324: dnl
1.3       todd      325: dnl
                    326: dnl ifstep(devstr)
                    327: dnl   .. if stepping is defined for the particular device, emit ' step', else
                    328: dnl      nothing
1.6     ! todd      329: define({-ifstep-}, {-ifdef({-step_$1-}, {- -}step_$1{--})-})dnl
1.5       todd      330: dnl
                    331: dnl
1.6     ! todd      332: define({-target-}, {-twrget({-$1-}, {-$2-}, {-$2-}, shift(shift($@)))-})dnl
1.5       todd      333: dnl
1.6     ! todd      334: dnl twrget(target, devname, prefix, str1, str2, str3)
1.5       todd      335: dnl        $1     $2      $3     $4   $5   $6
                    336: dnl
1.6     ! todd      337: define({-twrget-}, {-dnl
1.5       todd      338: dnl
1.6     ! todd      339: ifdef({-$1_target-}, , {-pushdef({-$1_target-}, {-done-})-})dnl
1.5       todd      340: dnl
1.6     ! todd      341: ifelse({-$4-}, , , {-dnl
        !           342: ifelse({-$4-}, {-_done-}, , {-dnl
        !           343: ifelse({-$5-}, , , {-dnl
        !           344: dnl errprint({-recurse: $1, $2, $3, $4, $5, $6, ...-})dnl
        !           345: twrget({-$1-}, {-$2-}, {-$3-}, shift(shift(shift(shift($@)))))dnl
1.5       todd      346: -})-})-})dnl
                    347: dnl
1.6     ! todd      348: ifelse({-$4-}, {-_done-}, , {-dnl
        !           349: dnl errprint({-recurse: $1_$2_dev, $3$4, $3$4, _done-})dnl
        !           350: twrget({-$1_$2_dev-}, {-$3$4-}, {-$3$4-}, {-_done-})dnl
1.5       todd      351: -})dnl
                    352: dnl
1.6     ! todd      353: ifdef({-$1$2target-}, , {-dnl
        !           354: pushdef({-$1_target-}, {-$2-})define({-$1$2target-})dnl
1.5       todd      355: -})dnl
                    356: dnl
                    357: -})dnl
                    358: dnl
                    359: dnl
1.6     ! todd      360: define({-show_target-}, {-dnl
        !           361: ifelse($1_target, {-done-}, {-_disp_dev_end()-},
1.5       todd      362: {-dnl $1_target:
1.6     ! todd      363: show_dev($1, -}$1_target{-)dnl
1.5       todd      364: popdef({-$1_target-})dnl
                    365: show_target({-$1-})dnl
                    366: -})-})dnl
                    367: dnl
1.6     ! todd      368: define({-show_dev-}, {-dnl
        !           369: ifdef({-$2__DEV-}, {-dnl
        !           370: ifelse($1_$2_dev_target, {-done-}, , {-dnl
1.5       todd      371: disp_dev({-$1_$2_dev_target-})dnl
                    372: popdef({-$1_$2_dev_target-})dnl
1.6     ! todd      373: show_dev({-$1-}, {-$2-})-})dnl
1.5       todd      374: -})dnl
                    375: -})dnl
                    376: dnl