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

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

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