Source code pulled from OpenBSD for OpenNTPD. The place to contribute to this code is via the OpenBSD CVS tree.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

373 lines
11 KiB

22 years ago
22 years ago
22 years ago
  1. dnl $OpenBSD: MAKEDEV.sub,v 1.14 2005/02/07 06:14:18 david Exp $
  2. dnl
  3. dnl Copyright (c) 2001-2004 Todd T. Fries <todd@OpenBSD.org>
  4. dnl
  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.
  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
  25. changequote(`{-', `-}')dnl
  26. dnl
  27. dnl o Next, change the comment character to make shell parameter
  28. dnl substitution possible
  29. dnl
  30. changecom(`/*', `*/')dnl
  31. dnl
  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
  45. pushdef({-_m4_cvs_ver-}, {-done-})dnl
  46. dnl
  47. undefine({-_m4_devs-})dnl
  48. pushdef({-_m4_devs-}, {-done-})dnl
  49. dnl
  50. undefine({-_m4_disks-})dnl
  51. undefine({-_m4_disks2-})dnl
  52. pushdef({-_m4_disks-}, {-done-})dnl
  53. pushdef({-_m4_disks2-}, {-done-})dnl
  54. dnl
  55. dnl define stack 'add to' functions, only unique names queued
  56. dnl
  57. define({-ver_q-}, {-ifelse(index($1_ver, y), 0, ,
  58. {-pushdef({-_m4_cvs_ver-}, {-$2-})define({-$1_ver-}, {-y-})-})-})dnl ver_q
  59. dnl
  60. define({-dev_q-}, {-ifelse(index(_q_$1_dev, :), 0,
  61. {-errprint({-duplicated dev id: $1 at -}__file__{-:-}__line__ originally at _q_$1_dev)-},
  62. {-pushdef({-_m4_devs-}, {-$1-})dnl
  63. define({-_q_$1_dev-}, {-:-}__file__{-:-}__line__)-})-})dnl dev_q
  64. dnl
  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
  69. dnl
  70. dnl store a version string for 'this' file
  71. dnl
  72. dnl vers ( uniqueidstring, versionstring, subdir )
  73. dnl
  74. dnl example1: vers(__file__, {-$OpenBSD: MAKEDEV.sub,v 1.14 2005/02/07 06:14:18 david Exp $-})
  75. dnl example2: vers(__file__, {-$OpenBSD: MAKEDEV.sub,v 1.14 2005/02/07 06:14:18 david Exp $-}, etc.MACHINE)
  76. dnl
  77. dnl if subdir is defined, prepend it to the filename in the version string
  78. dnl
  79. define({-vers-},
  80. {-ifelse({-$3-}, {--},
  81. {-ver_q(hstcl({-$1-}), {-translit({-{-$2-}-}, {-$-}, {--})-})-},
  82. {-ver_q(hstcl({-$1-}), {-_addsubdir({-{-$2-}-}, $3)-})-})-})dnl
  83. dnl
  84. dnl Version info for this file:
  85. dnl
  86. vers(__file__, {-$OpenBSD: MAKEDEV.sub,v 1.14 2005/02/07 06:14:18 david Exp $-})dnl
  87. dnl
  88. dnl
  89. define({-_addsubdir-},
  90. {-patsubst({-$1-}, {-\$(OpenBSD:) ([^\$]*)\$-}, {-\1 $2/\2-})-})dnl
  91. dnl
  92. dnl do the 'showing' of the version info
  93. dnl
  94. define({-do_vers-}, {-COMM $1-})dnl
  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-},
  100. {-ifelse(_m4_cvs_ver, {-done-}, {--},
  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-},
  108. {-ifelse(_m4_devs, {-done-}, {--},
  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-},
  116. {-ifelse(_m4_disks, {-done-}, {--},
  117. {-ifcase(_m4_disks, _m4_disks{--}*)dnl
  118. popdef({-_m4_disks-})dnl
  119. show_disks()dnl
  120. -})-})dnl
  121. dnl
  122. define({-show_disks2-},
  123. {-ifelse(_m4_disks2, {-done-}, {--},
  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
  132. dnl Add(a, b) - displays the result of a+b
  133. dnl Mult(a, b) - displays the result of a*b
  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
  142. define({-Add-}, {-$({-(-}$1+$2{-)-})-})dnl
  143. dnl
  144. dnl --> Multiplication
  145. dnl
  146. define({-Mult-}, {-$({-(-}$1*$2{-)-})-})dnl
  147. dnl
  148. dnl
  149. dnl TRUNC
  150. dnl
  151. define({-expr_trunc-}, {-$1trunc()
  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
  160. define({-_SHELL-}, {-sh-})dnl
  161. define({-_this-}, {-{-$-}T-})dnl
  162. dnl define({-_recurse-}, {-_SHELL _this-})dnl
  163. define({-_recurse-}, {-R-})dnl
  164. dnl
  165. dnl _devitem(pattern, description)
  166. dnl
  167. define({-_devitem-},
  168. {-{-#-} $1 {-$2-}-})dnl
  169. dnl
  170. dnl _devtitle(description)
  171. dnl
  172. define({-_devtitle-}, {-{-#-} $1:-})dnl
  173. dnl
  174. dnl _DEV(name, [character major], [block major])
  175. dnl
  176. define({-_DEV-}, {-$1_dev{--}dnl
  177. dnl
  178. dnl _DEV 'ifelse' .. $2 - major_$1_c
  179. dnl
  180. ifelse($2, , , {-define(major_$1_c, $2)-})dnl
  181. dnl
  182. dnl _DEV 'ifelse' .. $3 - major_$1_b
  183. dnl
  184. ifelse($3, , , {-define(major_$1_b, $3)-})dnl
  185. dnl
  186. dnl _DEV 'ifelse' .. $4 - step_$1
  187. dnl
  188. ifelse($4, , , {-define(step_$1, {-$4-})-})dnl
  189. dnl
  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
  195. define({-$1__DEV-}, {-Y-})dnl
  196. dnl
  197. dnl More magic, put device string name into a queue of script segments to
  198. dnl be shown later if it has been defined as a device in MAKEDEV.mi
  199. dnl
  200. ifdef({-$1_mkdev-}, {-__mkdev({-$1-})-})dnl
  201. dnl
  202. dnl
  203. -})dnl _DEV
  204. dnl
  205. dnl
  206. define({-ifdev-}, {-ifelse($1__DEV, Y, {-$2-})-})dnl
  207. dnl
  208. define({-_MKDEV-}, {-$1_mkdev-})dnl
  209. define({-_TITLE-}, {-$1_title-})dnl
  210. define({-__devitem-}, {-define($1_dev, {-_devitem($2, $3)-})-})dnl
  211. define({-__devtitle-}, {-define($1_title, {-_devtitle($2)-})-})dnl
  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
  216. define({-_end-}, {-
  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 [, group [ owner ] ])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*) dodisk $1 $U major_$1_b major_$1_c $U 0{--}ifstep($1);;
  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
  289. define({-_show_target-}, {-dnl
  290. ifdef({-$1__DEV-}, {-disp_dev({-$2-})-})dnl
  291. ifelse({-$3-}, {--},
  292. {-_disp_dev_end()-}, dnl <--- The END
  293. {-_show_target(shift(shift($@)))-})-})dnl
  294. dnl
  295. define({-disp_dev-}, {-dnl
  296. ifdef({-_disp_dev_tab-}, , {-define({-_disp_dev_tab-})-})dnl
  297. ifdef({-_disp_dev_len-}, , {-dnl
  298. define({-_disp_dev_len-}, 0)dnl
  299. _disp_dev_tab{--}_recurse{--}dnl
  300. define({-_disp_dev_tab-}, {- -})-})dnl
  301. ifelse(eval(len($1)+_disp_dev_len<60), 1,
  302. {- $1{--}define({-_disp_dev_len-}, eval(1+_disp_dev_len+len($1)))-}, {-
  303. _disp_dev_tab{--}_recurse $1{--}dnl
  304. define({-_disp_dev_len-}, len($1))-})dnl
  305. -})dnl
  306. define({-_disp_dev_end-}, {-undefine({-_disp_dev_tab-}, {-_disp_dev_len-})-})dnl
  307. dnl
  308. dnl A word about the above:
  309. dnl
  310. dnl _dt -> 'tab' .. at first, defined to nothing, as the tab is already there
  311. dnl then define it to a tab every time through
  312. dnl undefine it at the end
  313. dnl
  314. dnl _do -> 'old' count .. stores the length of the old string already displayed
  315. dnl it is initialized to 0, added to the length plus 1 of '_di' each
  316. dnl iteration the line is less than 60 chars long
  317. dnl undefined at the end
  318. dnl _di -> 'iteration' string .. the string used in this iteration, is empty if
  319. dnl the device does not exist
  320. dnl
  321. dnl
  322. dnl ifstep(devstr)
  323. dnl .. if stepping is defined for the particular device, emit ' step', else
  324. dnl nothing
  325. define({-ifstep-}, {-ifdef({-step_$1-}, {- -}step_$1{--})-})dnl
  326. dnl
  327. dnl
  328. define({-target-}, {-twrget({-$1-}, {-$2-}, {-$2-}, shift(shift($@)))-})dnl
  329. dnl
  330. dnl twrget(target, devname, prefix, str1, str2, str3)
  331. dnl $1 $2 $3 $4 $5 $6
  332. dnl
  333. define({-twrget-}, {-dnl
  334. dnl
  335. ifdef({-$1_target-}, , {-pushdef({-$1_target-}, {-done-})-})dnl
  336. dnl
  337. ifelse({-$4-}, , , {-dnl
  338. ifelse({-$4-}, {-_done-}, , {-dnl
  339. ifelse({-$5-}, , , {-dnl
  340. dnl errprint({-recurse: $1, $2, $3, $4, $5, $6, ...-})dnl
  341. twrget({-$1-}, {-$2-}, {-$3-}, shift(shift(shift(shift($@)))))dnl
  342. -})-})-})dnl
  343. dnl
  344. ifelse({-$4-}, {-_done-}, , {-dnl
  345. dnl errprint({-recurse: $1_$2_dev, $3$4, $3$4, _done-})dnl
  346. twrget({-$1_$2_dev-}, {-$3$4-}, {-$3$4-}, {-_done-})dnl
  347. -})dnl
  348. dnl
  349. ifdef({-$1$2target-}, , {-dnl
  350. pushdef({-$1_target-}, {-$2-})define({-$1$2target-})dnl
  351. -})dnl
  352. dnl
  353. -})dnl
  354. dnl
  355. dnl
  356. define({-show_target-}, {-dnl
  357. ifelse($1_target, {-done-}, {-_disp_dev_end()-},
  358. {-dnl $1_target:
  359. show_dev($1, -}$1_target{-)dnl
  360. popdef({-$1_target-})dnl
  361. show_target({-$1-})dnl
  362. -})-})dnl
  363. dnl
  364. define({-show_dev-}, {-dnl
  365. ifdef({-$2__DEV-}, {-dnl
  366. ifelse($1_$2_dev_target, {-done-}, , {-dnl
  367. disp_dev({-$1_$2_dev_target-})dnl
  368. popdef({-$1_$2_dev_target-})dnl
  369. show_dev({-$1-}, {-$2-})-})dnl
  370. -})dnl
  371. -})dnl
  372. dnl