1 <!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN">
3 <meta content=
"text/html; charset=ISO-8859-1" http-equiv=
"content-type">
4 <title>GNU Make Standard Library
</title></head>
7 <h1>GNU Make Standard Library
</h1>
8 The GNU Make Standard Library (GMSL) is a collection of functions
9 implemented using native GNU Make functionality that provide list and
10 string manipulation, integer arithmetic, associative arrays, stacks,
11 and debugging facilities.
The GMSL is released under the BSD License.
<br>
13 <a href=
"http://sourceforge.net/projects/gmsl/">[Project Page]
</a> <a href=
"http://sourceforge.net/project/showfiles.php?group_id=129887">[Download]
</a>
14 <a href=
"http://sourceforge.net/forum/forum.php?forum_id=443916">[Discussion
17 The two files needed are
<span style=
"font-family: monospace;">gmsl
</span>
18 and
<span style=
"font-family: monospace;">__gmsl
</span>.
To
19 include the GMSL in your Makefile do
<br>
20 <pre style=
"margin-left: 40px;">include gmsl
</pre>
21 <span style=
"font-family: monospace;">gmsl
</span> automatically includes
<span style=
"font-family: monospace;"> __gmsl
</span>.
To check that
22 you have the right version of
<span style=
"font-family: monospace;">gmsl
</span>
23 use the
<span style=
"font-family: monospace;">gmsl_compatible
</span>
25 below). The current version is
<span style=
"font-family: monospace;">1
28 The GMSL package also includes a test suite for GMSL.
Just run
<span style=
"font-family: monospace;">make -f gmsl-tests
</span>.
<br>
29 <h2>Logical Operators
</h2>GMSL has boolean $(true) (a non-empty string)
30 and $(false) (an empty string).
The following operators can be
31 used with those variables.
<br>
33 <hr style=
"width: 100%; height: 2px;"><span style=
"font-weight: bold;">not
</span><br>
37 <span style=
"font-family: monospace;">Arguments: A boolean value
</span><br style=
"font-family: monospace;">
39 <span style=
"font-family: monospace;">Returns:
Returns $(true) if the boolean is $(false) and vice versa
</span><br style=
"font-family: monospace;">
41 <hr style=
"width: 100%; height: 2px; font-family: monospace;"><span style=
"font-weight: bold;"></span><span style=
"font-weight: bold;">and
</span><br>
43 <span style=
"font-family: monospace;">Arguments: Two boolean values
</span><br style=
"font-family: monospace;">
44 <span style=
"font-family: monospace;">Returns:
Returns $(true) if both of the booleans are true
</span><br style=
"font-family: monospace;">
45 <hr style=
"width: 100%; height: 2px; font-family: monospace;"><span style=
"font-weight: bold;">or
</span><br>
47 <span style=
"font-family: monospace;">Arguments: Two boolean values
</span><br style=
"font-family: monospace;">
48 <span style=
"font-family: monospace;">Returns:
Returns $(true) if either of the booleans is true
</span><br style=
"font-family: monospace;">
49 <hr style=
"width: 100%; height: 2px; font-family: monospace;"><span style=
"font-weight: bold;">xor
</span><br style=
"font-weight: bold;">
51 <span style=
"font-family: monospace;">Arguments: Two boolean values
</span><br style=
"font-family: monospace;">
52 <span style=
"font-family: monospace;">Returns:
Returns $(true) if exactly one of the booleans is true
</span><br style=
"font-family: monospace;">
53 <hr style=
"width: 100%; height: 2px; font-family: monospace;"><span style=
"font-weight: bold;">nand
</span><br>
55 <span style=
"font-family: monospace;">Arguments: Two boolean values
</span><br style=
"font-family: monospace;">
56 <span style=
"font-family: monospace;">Returns:
Returns value of 'not and'
</span><br style=
"font-family: monospace;">
57 <hr style=
"width: 100%; height: 2px; font-family: monospace;"><span style=
"font-weight: bold;">nor
</span><br>
59 <span style=
"font-family: monospace;">Arguments: Two boolean values
</span><br style=
"font-family: monospace;">
60 <span style=
"font-family: monospace;">Returns:
Returns value of 'not or'
</span><br style=
"font-family: monospace;">
61 <hr style=
"width: 100%; height: 2px; font-family: monospace;"><span style=
"font-weight: bold;">xnor
</span><br>
63 <span style=
"font-family: monospace;">Arguments: Two boolean values
</span><br style=
"font-family: monospace;">
64 <span style=
"font-family: monospace;">Returns:
Returns value of 'not xor'
</span><br style=
"font-family: monospace;">
65 <hr style=
"width: 100%; height: 2px; font-family: monospace;">
66 <h2>List Manipulation Functions
</h2>
67 A list is a string of characters; the list separator is a space.
<br>
70 <hr style=
"width: 100%; height: 2px;"><b>first
</b><br>
72 <span style=
"font-family: monospace;">Arguments:
1: A list
<br>
73 Returns:
Returns the first element of a list
<br>
77 <span style=
"font-family: monospace;">Arguments:
1: A list
<br>
78 Returns:
Returns the last element of a list
<br>
82 <span style=
"font-family: monospace;">Arguments:
1: A list
<br>
83 Returns:
Returns the list with the first element
88 <span style=
"font-family: monospace;">Arguments:
1: A list
<br>
89 Returns:
Returns the list with the last element removed
<br>
93 <span style=
"font-family: monospace;">Arguments:
1: Name of function to
94 $(call) for each element of list
<br>
95 2: List to
96 iterate over calling the function in
1<br>
97 Returns:
The list after calling the function on each
100 <hr><b>pairmap
</b><br>
102 <span style=
"font-family: monospace;">Arguments:
1: Name of function to
103 $(call) for each pair of elements
<br>
104 2: List to
105 iterate over calling the function in
1<br>
106 3: Second
107 list to iterate over calling the function in
1<br>
108 Returns:
The list after calling the function on each
113 <span style=
"font-family: monospace;">Arguments:
1: A list to compare
115 2: ...this
117 Returns:
Returns $(true) if the two lists are identical
<br>
121 <span style=
"font-family: monospace;">Arguments:
1: A list to compare
123 2: ...this
125 Returns:
Returns $(true) if the two lists are different
<br>
127 <hr><b>reverse
</b><br>
129 <span style=
"font-family: monospace;">Arguments:
1: A list to reverse
<br>
130 Returns:
The list with its elements in reverse order
<br>
134 <span style=
"font-family: monospace;">Arguments:
1: A list to deduplicate
<br>
135 Returns:
The list with elements in order without duplicates
<br>
137 <hr><b>length
</b><br>
139 <span style=
"font-family: monospace;">Arguments:
1: A list
<br>
140 Returns:
The number of elements in the list
<br>
142 <hr style=
"width: 100%; height: 2px;"><span style=
"font-family: monospace;"></span>
143 <h2>String Manipulation Functions
</h2>
144 A string is any sequence of characters.
<br>
146 <hr style=
"width: 100%; height: 2px;"><b>seq
</b><br>
148 <span style=
"font-family: monospace;">Arguments:
1: A string to compare
150 2: ...this
152 Returns:
Returns $(true) if the two strings are
157 <span style=
"font-family: monospace;">Arguments:
1: A string to compare
159 2: ...this
161 Returns:
Returns $(true) if the two strings are not
164 <hr><b>strlen
</b><br>
166 <span style=
"font-family: monospace;">Arguments:
1: A string
<br>
167 Returns:
Returns the length of the string
<br>
169 <hr><b>substr
</b><br>
171 <span style=
"font-family: monospace;">Arguments:
1: A string
<br>
172 2: Start offset (first character is
1)
<br>
173 3: Ending offset (inclusive)
<br>Returns:
Returns a substring
<br>
177 <span style=
"font-family: monospace;">Arguments:
1: The character to
179 2: A
181 Returns:
Splits a string into a list separated by
182 spaces at the split
<br>
183 character
184 in the first argument
<br>
188 <span style=
"font-family: monospace;">Arguments:
1: The character to
189 put between fields
<br>
190 2: A list
191 to merge into a string
<br>
192 Returns:
Merges a list into a single string, list
193 elements are separated
<br>
194 by the
195 character in the first argument
<br>
199 <span style=
"font-family: monospace;">Arguments:
1: The list of
200 characters to translate from
<br>
201 2: The
202 list of characters to translate to
<br>
203 3: The
204 text to translate
<br>
205 Returns:
Returns the text after translating characters
<br>
209 <span style=
"font-family: monospace;">Arguments:
1: Text to upper case
<br>
210 Returns:
Returns the text in upper case
<br>
214 <span style=
"font-family: monospace;">Arguments:
1: Text to lower case
<br>
215 Returns:
Returns the text in lower case
<br>
217 <hr style=
"width: 100%; height: 2px;"><span style=
"font-family: monospace;"></span>
218 <h2>Set Manipulation Functions
</h2>
219 Sets are represented by sorted, deduplicated lists. To create a set
220 from a list use
<span style=
"font-family:
221 monospace;">set_create
</span>, or start with the
<span
222 style=
"font-family: monospace;">empty_set
</span> and
<span
223 style=
"font-family: monospace;">set_insert
</span> individual elements.
224 The empty set is defined as
<span style=
"font-family:
225 monospace;">empty_set
</span>.
<p>
227 <hr><b>set_create
</b><br>
229 <span style=
"font-family: monospace;">Arguments:
1: A list of set elements
<br>
230 Returns:
Returns the newly created set
<br>
233 <hr><b>set_insert
</b><br>
235 <span style=
"font-family: monospace;">Arguments:
1: A single element to add to a set
<br>
236 2: A set
<br>
237 Returns:
Returns the set with the element added
<br>
240 <hr><b>set_remove
</b><br>
242 <span style=
"font-family: monospace;">Arguments:
1: A single element to remove from a set
<br>
243 2: A set
<br>
244 Returns:
Returns the set with the element removed
<br>
247 <hr><b>set_is_member
</b><br>
249 <span style=
"font-family: monospace;">Arguments:
1: A single element
<br>
250 2: A set
<br>
251 Returns:
Returns $(true) if the element is in the set
<br>
254 <hr><b>set_union
</b><br>
256 <span style=
"font-family: monospace;">Arguments:
1: A set
<br>
257 2: Another set
<br>
258 Returns:
Returns the union of the two sets
<br>
261 <hr><b>set_intersection
</b><br>
263 <span style=
"font-family: monospace;">Arguments:
1: A set
<br>
264 2: Another set
<br>
265 Returns:
Returns the intersection of the two sets
<br>
268 <hr><b>set_is_subset
</b><br>
270 <span style=
"font-family: monospace;">Arguments:
1: A set
<br>
271 2: Another set
<br>
272 Returns:
Returns $(true) if the first set is a subset of the second
<br>
275 <hr><b>set_equal
</b><br>
277 <span style=
"font-family: monospace;">Arguments:
1: A set
<br>
278 2: Another set
<br>
279 Returns:
Returns $(true) if the two sets are identical
<br>
282 <hr style=
"width: 100%; height: 2px;"><span style=
"font-family: monospace;"></span>
283 <h2>Integer Arithmetic Functions
</h2>
284 Integers are represented by lists with the equivalent number of
285 x's.
For example the number
4 is x x x x.
The maximum
286 integer that the library can handle as
<span style=
"font-style: italic;">input
</span> (i.e. as the argument to a
287 call to
<span style=
"font-family: monospace;">int_encode
</span>) is
288 65536. There is no limit on integer size for internal computations or
291 The arithmetic library functions come in two forms: one form of each
292 function takes integers as arguments and the other form takes the
293 encoded form (x's created by a call to
<span style=
"font-family: monospace;">int_encode
</span>).
For example,
294 there are two plus functions:
<span style=
"font-family: monospace;">plus
</span>
295 (called with integer arguments and returns an integer) and
<span style=
"font-family: monospace;">int_plus
</span> (called with encoded
296 arguments and returns an encoded result).
<br>
298 <span style=
"font-family: monospace;">plus
</span> will be slower than
<span style=
"font-family: monospace;">int_plus
</span> because its arguments
299 and result have to be translated between the x's format and
300 integers.
If doing a complex calculation use the
<span style=
"font-family: monospace;">int_*
</span> forms with a single
301 encoding of inputs and single decoding of the output.
For simple
302 calculations the direct forms can be used.
<br>
304 <hr style=
"width: 100%; height: 2px;"><b>int_decode
</b><br>
306 <span style=
"font-family: monospace;">Arguments:
1: A number of x's
308 Returns:
Returns the integer for human consumption
309 that is represented
<br>
310 by the
313 <hr><b>int_encode
</b><br>
315 <span style=
"font-family: monospace;">Arguments:
1: A number in
316 human-readable integer form
<br>
317 Returns:
Returns the integer encoded as a string of x's
<br>
319 <hr><b>int_plus
</b><br>
321 <span style=
"font-family: monospace;">Arguments:
1: A number in x's
323 2: Another
324 number in x's represntation
<br>
325 Returns:
Returns the sum of the two numbers in x's
328 <hr><b>plus (wrapped version of int_plus)
</b><br>
330 <span style=
"font-family: monospace;">Arguments:
1: An integer
<br>
331 2: Another
333 Returns:
Returns the sum of the two integers
<br>
335 <hr><b>int_subtract
</b><br>
337 <span style=
"font-family: monospace;">Arguments:
1: A number in x's
339 2: Another
340 number in x's represntation
<br>
341 Returns:
Returns the difference of the two numbers in
342 x's representation,
<br>
343 or outputs
344 an error on a numeric underflow
<br>
346 <hr><b>subtract (wrapped version of int_subtract)
</b><br>
348 <span style=
"font-family: monospace;">Arguments:
1: An integer
<br>
349 2: Another
351 Returns:
Returns the difference of the two integers,
<br>
352 or outputs
353 an error on a numeric underflow
<br>
355 <hr><b>int_multiply
</b><br>
357 <span style=
"font-family: monospace;">Arguments:
1: A number in x's
359 2: Another
360 number in x's represntation
<br>
361 Returns:
Returns the product of the two numbers in x's
364 <hr><b>multiply (wrapped version of int_multiply)
</b><br>
366 <span style=
"font-family: monospace;">Arguments:
1: An integer
<br>
367 2: Another
369 Returns:
Returns the product of the two integers
<br>
371 <hr><b>int_divide
</b><br>
373 <span style=
"font-family: monospace;">Arguments:
1: A number in x's
375 2: Another
376 number in x's represntation
<br>
377 Returns:
Returns the result of integer division of
378 argument
1 divided
<br>
379 by
380 argument
2 in x's representation
<br>
382 <hr><b>divide (wrapped version of int_divide)
</b><br>
384 <span style=
"font-family: monospace;">Arguments:
1: An integer
<br>
385 2: Another
387 Returns:
Returns the integer division of the first
388 argument by the second
<br>
390 <hr><b>int_max, int_min
</b><br>
392 <span style=
"font-family: monospace;">Arguments:
1: A number in x's
394 2: Another
395 number in x's represntation
<br>
396 Returns:
Returns the maximum or minimum of its
398
401 <hr><b>max, min
</b><br>
403 <span style=
"font-family: monospace;">Arguments:
1: An integer
<br>
404 2: Another
406 Returns:
Returns the maximum or minimum of its integer
409 <hr><b>int_gt, int_gte, int_lt, int_lte, int_eq, int_ne
</b><br>
411 <span style=
"font-family: monospace;">Arguments: Two x's representation
412 numbers to be compared
<br>
413 Returns:
$(true) or $(false)
<br>
415 int_gt First argument greater than second argument
<br>
416 int_gte First argument greater than or equal to second argument
<br>
417 int_lt First argument less than second argument
<br>
418 int_lte First argument less than or equal to second argument
<br>
419 int_eq First argument is numerically equal to the second argument
<br>
420 int_ne First argument is not numerically equal to the second argument
<br>
422 <hr><b>gt, gte, lt, lte, eq, ne
</b><br>
424 <span style=
"font-family: monospace;">Arguments: Two integers to be
426 Returns:
$(true) or $(false)
<br>
428 gt First argument greater than second argument
<br>
429 gte First argument greater than or equal to second argument
<br>
430 lt First argument less than second argument
<br>
431 lte First argument less than or equal to second argument
<br>
432 eq First argument is numerically equal to the second argument
<br>
433 ne First argument is not numerically equal to the second argument
<br>
435 increment adds
1 to its argument, decrement subtracts
1. Note that
<br>
436 decrement does not range check and hence will not underflow, but
<br>
437 will incorrectly say that
0 -
1 =
0<br>
438 <hr><b>int_inc
</b><br>
440 <span style=
"font-family: monospace;">Arguments:
1: A number in x's
442 Returns:
The number incremented by
1 in x's
447 <span style=
"font-family: monospace;">Arguments:
1: An integer
<br>
448 Returns:
The argument incremented by
1<br>
450 <hr><b>int_dec
</b><br>
452 <span style=
"font-family: monospace;">Arguments:
1: A number in x's
454 Returns:
The number decremented by
1 in x's
459 <span style=
"font-family: monospace;">Arguments:
1: An integer
<br>
460 Returns:
The argument decremented by
1<br>
462 <hr><b>int_double
</b><br>
464 <span style=
"font-family: monospace;">Arguments:
1: A number in x's
466 Returns:
The number doubled (i.e. *
2) and returned in
467 x's representation
<br>
469 <hr><b>double
</b><br>
471 <span style=
"font-family: monospace;">Arguments:
1: An integer
<br>
472 Returns:
The integer times
2<br>
474 <hr><b>int_halve
</b><br>
476 <span style=
"font-family: monospace;">Arguments:
1: A number in x's
478 Returns:
The number halved (i.e. /
2) and returned in
479 x's representation
<br>
483 <span style=
"font-family: monospace;">Arguments:
1: An integer
<br>
484 Returns:
The integer divided by
2<br>
486 <hr style=
"width: 100%; height: 2px;"><span style=
"font-family: monospace;"></span>
487 <h2>Associative Arrays
</h2>
488 An associate array maps a key value (a string with no spaces in it) to
489 a single value (any string).
<br>
492 <hr style=
"width: 100%; height: 2px;"><b>set
</b><br>
494 <span style=
"font-family: monospace;">Arguments:
1: Name of associative
496 2: The key
497 value to associate
<br>
498 3: The
499 value associated with the key
<br>
500 Returns:
None
<br>
504 <span style=
"font-family: monospace;">Arguments:
1: Name of associative
506 2: The key
508 Returns:
The value stored in the array for that key
<br>
512 <span style=
"font-family: monospace;">Arguments:
1: Name of associative
514 Returns:
Returns a list of all defined keys in the
517 <hr><b>defined
</b><br>
519 <span style=
"font-family: monospace;">Arguments:
1: Name of associative
521 2: The key
523 Returns:
Returns true if the key is defined (i.e. not
526 <hr style=
"width: 100%; height: 2px;"><span style=
"font-family: monospace;"></span>
527 <h2>Named Stacks
</h2>
528 A stack is an ordered list of strings (with no spaces in them).
<br>
530 <hr style=
"width: 100%; height: 2px;"><b>push
</b><br>
532 <span style=
"font-family: monospace;">Arguments:
1: Name of stack
<br>
533 2: Value
534 to push onto the top of the stack (must not contain
<br>
535 a space)
<br>
536 Returns:
None
<br>
540 <span style=
"font-family: monospace;">Arguments:
1: Name of stack
<br>
541 Returns:
Top element from the stack after removing it
<br>
545 <span style=
"font-family: monospace;">Arguments:
1: Name of stack
<br>
546 Returns:
Top element from the stack without removing it
<br>
550 <span style=
"font-family: monospace;">Arguments:
1: Name of stack
<br>
551 Returns:
Number of items on the stack
<br>
553 <hr style=
"width: 100%; height: 2px;"><span style=
"font-family: monospace;"></span>
554 <h2>Miscellaneous and Debugging Facilities
</h2>
555 GMSL defines the following constants; all are accessed as normal GNU
556 Make variables by wrapping them in
<span style=
"font-family: monospace;">$()
</span> or
<span style=
"font-family: monospace;">${}
</span>.
<br>
558 <table style=
"text-align: left;" border=
"1" cellpadding=
"2" cellspacing=
"2">
561 <td><span style=
"font-style: italic;">Constant
</span><br>
563 <td><span style=
"font-style: italic;">Value
</span><br>
565 <td><span style=
"font-style: italic;">Purpose
</span><br>
569 <td><span style=
"font-family: monospace;">true
</span><br>
571 <td><span style=
"font-family: monospace;">T
</span><br>
573 <td>Boolean for
<span style=
"font-family: monospace;">$(if)
</span>
574 and return from
GMSL functions
<br>
578 <td><span style=
"font-family: monospace;">false
</span><br>
582 <td>Boolean for
<span style=
"font-family: monospace;">$(if)
</span>
583 and return from GMSL functions
<br>
587 <td><span style=
"font-family: monospace;">gmsl_version
</span><br>
589 <td><span style=
"font-family: monospace;">1 0 0</span><br>
591 <td>GMSL version number as list: major minor revision
<br>
596 <span style=
"font-weight: bold;"><br>
597 gmsl_compatible
</span><span style=
"font-family: monospace;"><br>
599 Arguments: List containing the desired library version number (maj min
601 </span><span style=
"font-family: monospace;">Returns:
602 $(true) if this version of the library is compatible
<br>
603 </span><span style=
"font-family: monospace;">
604 with the requested version number, otherwise $(false)
</span>
605 <hr><b>gmsl-print-% (target not a function)
</b><br>
607 <span style=
"font-family: monospace;">Arguments: The % should be
608 replaced by the name of a variable that you
<br>
609 wish to
611 Action:
Echos the name of the variable that matches
612 the % and its value.
<br>
613 For
614 example, 'make gmsl-print-SHELL' will output the value of
<br>
615 the SHELL
618 <hr><b>assert
</b><br>
620 <span style=
"font-family: monospace;">Arguments:
1: A boolean that must
621 be true or the assertion will fail
<br>
622 2: The
623 message to print with the assertion
<br>
624 Returns:
None
<br>
626 <hr><b>assert_exists
</b><br>
628 <span style=
"font-family: monospace;">Arguments:
1: Name of file that
629 must exist, if it is missing an assertion
<br>
630 will be
632 Returns:
None
<br>
634 <hr style=
"width: 100%; height: 2px;"><br>
635 GMSL has a number of environment variables (or command-line overrides)
636 that control various bits of functionality:
<br>
638 <table style=
"text-align: left;" border=
"1" cellpadding=
"2" cellspacing=
"2">
641 <td><span style=
"font-style: italic;">Variable
</span><br>
643 <td><span style=
"font-style: italic;">Purpose
</span><br>
647 <td><span style=
"font-family: monospace;">GMSL_NO_WARNINGS
</span><br>
649 <td>If set prevents GMSL from outputting warning messages:
650 artithmetic functions generate underflow warnings.
<br>
654 <td><span style=
"font-family: monospace;">GMSL_NO_ERRORS
</span><br>
656 <td>If set prevents GMSL from generating fatal errors: division
657 by zero or failed assertions are fatal.
<br>
661 <td><span style=
"font-family: monospace;">GMSL_TRACE
</span><br>
663 <td>Enables function tracing.
Calls to GMSL functions will
664 result in name and arguments being traced.
<br>
669 <span style=
"font-family: monospace;"></span><br>
671 Copyright (c)
2005-
2006 <a href=
"http://www.jgc.org/">John Graham-Cumming
</a>.
<br>
672 <hr style=
"width: 100%; height: 2px;">
673 <table style=
"width: 100%; text-align: left;" border=
"0" cellpadding=
"2" cellspacing=
"2">
676 <td style=
"width: 50%;">John Graham-Cumming's work on this
677 project was sponsored by
<a href=
"http://www.electric-cloud.com/">Electric
679 <a href=
"http://www.electric-cloud.com/"><img alt=
"" src=
"http://gmsl.sf.net/ec_logo.gif" style=
"border: 0px solid ; width: 223px; height: 47px;"></a><br>
682 <p><a href=
"http://sourceforge.net/"><img src=
"http://sourceforge.net/sflogo.php?group_id=129887&type=1" alt=
"SourceForge.net Logo" border=
"0" height=
"31" width=
"88"></a></p>