1=head1 NAME 2 3makepp_builtins -- Builtin commands in makepp 4 5=for vc $Id: makepp_builtins.pod,v 1.50 2012/02/07 22:26:15 pfeiffer Exp $ 6 7=head1 DESCRIPTION 8 9=for genindex '&?(?!export|I<)\w+' makepp_builtins.pod 10 11B<A:>E<nbsp>L<I<awk>|/awk>,E<nbsp> 12B<C:>E<nbsp>L<&cat|/cat_option_filename>, 13 L<I<chgrp>|/chgrp>, 14 L<&chmod|/chmod_option_mode_filename>, 15 L<I<chown>|/chgrp>, 16 L<&cp|/cp_option_sourcefile_destfile>, 17 L<&cut|/cut_option_filename>,E<nbsp> 18B<D:>E<nbsp>L<I<date>|/date>,E<nbsp> 19B<E:>E<nbsp>L<&echo|/echo_option_string>, 20 L<&expr|/expr_option_perlcode>,E<nbsp> 21B<F:>E<nbsp>L<I<false>|/false>, 22 L<I<fmt>|/fmt>,E<nbsp> 23B<G:>E<nbsp>L<&grep|/grep_option_perlcode_filename>,E<nbsp> 24B<H:>E<nbsp>L<I<head>|/head>,E<nbsp> 25B<I:>E<nbsp>L<&install|/install_option_sourcefile_destfile>,E<nbsp> 26B<L:>E<nbsp>L<&ln|/ln_option_sourcefile_destfile>,E<nbsp> 27B<M:>E<nbsp>L<I<m4>|/m4>, 28 L<&mkdir|/mkdir_option_directory>, 29 L<&mv|/mv_option_sourcefile_destfile>,E<nbsp> 30B<P:>E<nbsp>L<&perl|/grep_option_perlcode_filename>, 31 L<&preprocess|/preprocess_option_variable_definition_filename>, 32 L<&printf|/echo_option_string>,E<nbsp> 33B<R:>E<nbsp>L<&rm|/rm_option_filename>, 34 L<I<rmdir>|/rmdir>,E<nbsp> 35B<S:>E<nbsp>L<&sed|/grep_option_perlcode_filename>, 36 L<&sort|/sort_option_filename>,E<nbsp> 37B<T:>E<nbsp>L<I<tail>|/head>, 38 L<&template|/template_option_macro_definition_filename>, 39 L<&touch|/touch_option_filename>, 40 L<I<tr>|/tr>,E<nbsp> 41B<U:>E<nbsp>L<&uninstall|/uninstall_option_filename>, 42 L<&uniq|/uniq_option_filename>,E<nbsp> 43B<Y:>E<nbsp>L<&yes|/echo_option_string> 44 45There is a special Shell-like possibility to call built-in commands in a rule. 46The only metacharacters recognized are comment signs, backslashes, single and 47double quotes. Only one command may be given per line, and I/O redirection is 48not available (see C<-i> and C<-o> below instead). 49 50These commands start with C<&>, which is the function character in Perl and 51not a valid first character in Shell. If no builtin command of that name can 52be found, this is also the syntax for calling an external script within the 53Perl instance performing the rule. See L<C<run>|makepp_extending/run_script_arguments>. 54 55These commands, as well as your self defined ones and Perl scripts can also be 56called as a make function, returning the standard output. The newlines are 57converted to spaces, except when evaluated within a C<define> statement. 58 59 FIRST-WORDS ;= $(&cut -d' ' -f0 $(FILES)) 60 61When these commands are not indented as rule actions, they get 62L<performed|makepp_statements/Commands> while reading the makefile. You can 63also access these commands stand-alone, e.g. if you need some features not 64available in the Unix counterpart, via the L<makeppbuiltin|makeppbuiltin> 65command. 66 67These commands are mostly based on the GNU variant. But many options (like 68--backup, --interactive or --recursive) don't really make sense in a makefile. 69So, even though they'd be easy to implement in Perl, they have been left out. 70Also many Unix commands offer a variety of options that cover fairly 71complicated cases (e.g. sort field specifications) while still being 72inherently limited. Allowing access to Perl, which is present anyway, gives 73much more power here. 74 75Lists of filenames may be empty, making it safe to call these commands with an 76unchecked list. Options in their short form may be glued together as in 77C<-ab> instead of C<-a -b>. In the long form arguments may be given either 78glued on with an C<=> sign or separately. In the short form they may be given 79either glued on directly or separately. A few options are common to several 80builtins, though the short form is sometimes hidden by a command's own option 81(as in C<&cut -f>): 82 83=over 84 85=item -A I<filename> 86 87=item --args-file=I<filename> 88 89=item --arguments-file=I<filename> 90 91Read the file and parse it as possibly quoted whitespace- and/or newline-separated options. 92 93=item -f 94 95=item --force 96 97Force the creation of the file(s) intended by the parameters, even if a 98different kind of file or empty directory of that name already exists. This 99must precede the C<-o, --output=filename> option if it is to have any effect 100on that. 101 102=item -i I<shellcommand> 103 104=item --inpipe=I<shellcommand> 105 106Start the Shell command(s) and pipe the output into the builtin. There may 107optionally be a trailing C<|> character, to indicate this is a pipe. With 108this option no filenames need to be given. But if you want to perform the 109builtin on both files and the pipe output, you must use C<-> as a filename for 110the pipe output. This option is necessary because there is no redirection 111syntax. 112 113=item -I 114 115=item --infail 116 117If an C<--inpipe> Shell command fails, that also causes the current builtin to 118fail. 119 120=item -o I<filename> 121 122=item --output=I<filename> 123 124Write the output to this file, rather than stdout. Filename may have any of these forms: 125 126=over 127 128=item I<filename> 129 130=item >I<filename> 131 132Simply write to file. 133 134=item >>I<filename> 135 136Append to (not necessarily) existing file. 137 138=item +<I<filename> 139 140Also open the file for input, allowing inplace editing. With this option 141variant no input filenames need to be given. But if you want to perform the 142builtin on more files, you must use C<-> as an input filename for this one. 143In fact the output gets written to a temporary file which gets moved to 144filename at the end. 145 146=item |I<shellcommand> 147 148Pipe the builtin's output to the Shell command(s). 149 150=back 151 152This option is necessary because there is no redirection syntax. 153 154=item -O 155 156=item --outfail 157 158If an C<--output> Shell command fails, that also causes the current builtin to 159fail. 160 161=item -r I<number> 162 163=item --record-size=I<number> 164 165Locally sets C<$/> for the current builtin. This splits input into records of 166length I<number> rather than line by line. If I<number> is zero, each input 167file as a whole is one record. 168 169=item -s I<string> 170 171=item --separator=I<string> 172 173Locally sets C<$/> for the current builtin. This splits input on I<string> 174rather than line by line. 175 176=item -S 177 178=item --synclines 179 180Generate C<#line >I<C<NO>>C< ">I<C<FILE>>C<"> and C<#line >I<C<NO>> lines, 181understood by many C-like languages. 182 183=item -v 184 185=item --verbose 186 187Document the changes to the file system. This must precede other options if 188it is to document their effect. If you pass this option to makepp itself, it 189is as if you had given it for every single builtin command. 190 191=back 192 193There are two motivations for having builtin commands in makepp. The first is 194to offer a set of utilities, which, unlike Shell commands, are guaranteed to 195work the same everywhere, like L<C<&echo -n>|/echo_option_string> or 196L<C<&mkdir -p>|/mkdir_option_directory>, and saving you the hassle of finding 197the path to L<C<&install>|/install_option_sourcefile_destfile> and figuring 198out its wildly varying options. In a compilation environment, it's useful to 199have the C<--synclines> option, which normally only C<m4> provides, on all 200filters. 201 202The other is a question of efficiency. In general costly fork/execs should be 203avoided where reasonably possible. On Unix emulations like Cygwin or 204BS2000/Posix, this becomes a noticeable win. But, even on Linux, when the 205makepp test suite was converted from external commands to builtins, there was 206an overall saving of 3% user CPU usage and 15% system CPU usage. (The tests 207are of course heavy on primitive actions and hardly call the compiler.) 208 209Consistency is also an issue, though we're not going to reform Unix. Normally 210commands have various nuances of regular expressions. And many invent sort of 211languages, each different of course, for doing something (e.g. C<expr>, C<sed> 212...), or complex options for specifying fields, delimiters, columns 213(e.g. C<cut>, C<sort> ...). 214 215Here instead, anything fancy simply gets handled by Perl, giving both 216consistency across all commands, and far more power than a whole bunch of 217options. Better yet, any I<Perlcode> these commands run for you, gets run in 218the package of the Makefile. So, rather than stuff Perl code into the rule 219action, you can define functions and variables and use them within the 220commands: 221 222 sub my_filter { 223 # Return true iff $_ is desirable 224 } 225 %.out: %.in Makeppfile 226 &grep &my_filter $(input) -o $(output) 227 228If you use Perl functions or variables in your commands, makepp does not 229recognize this as a dependency. It is generally safer to tell makepp 230everything, so rules which use Perl elements should depend on the makefile or 231module providing those elements, as shown in the above example. 232 233On the other hand ignorance may be desirable if you have a program that mixes 234programmatic and configuration aspects in one file. An example would be a WSDL 235file containing both a web service interface definition and an IP address. 236You could preprocess this file with the C<&template> command to patch in the 237configuration, but not let makepp notice. 238 239=over 240 241 242=item awk 243 244Not built in, but L<C<&sed>|/grep_option_perlcode_filename> is comparable. 245 246 247=item &cat I<[option ...] filename ...> 248 249Concatenates all the files into a single one. 250 251Standard options: C<-A, --args-file, --arguments-file=filename, -f, --force, 252-i, --inpipe=shellcommand, -I, --infail, -o, --output=filename, -O, --outfail, 253-S, --synclines, -v, --verbose> 254 255 256 257=item chgrp 258 259=item chown 260 261These commands are mostly not portable! They will either quietly do nothing 262or fail, depending on the system. Generally only root may perform these 263operations, which is why they are only available through the 264L<C<&install>|/install_option_sourcefile_destfile> command. 265 266 267 268=item &chmod I<[option ...] mode filename ...> 269 270Sets I<mode> for all given files. Mode must be an octal string. 271 272Standard options: C<-A, --args-file, --arguments-file=filename, -v, --verbose> 273 274 275 276=item &cp I<[option ...] sourcefile destfile> 277 278=item &cp I<[option ...] sourcefile> 279 280=item &cp I<[option ...] sourcefile ... destdir> 281 282Copy I<sourcefile> to I<destfile>, one I<sourcefile> to current directory or 283multiple I<sourcefile>s to I<destdir> with the same name. 284 285Standard options: C<-A, --args-file, --arguments-file=filename, -f, --force, -v, 286--verbose> 287 288=over 289 290=item -l 291 292=item --link 293 294Try to link the files. If that fails, try symbolic link, if that is also 295requested, else copy. 296 297=item -s 298 299=item --symbolic 300 301=item --symbolic-link 302 303=item --symlink 304 305Try to symbolically link the files. If that fails, copy. 306 307=back 308 309See the note under L<&ln|/ln_option_sourcefile_destfile>. 310 311 312=item &cut I<[option ...] filename ...> 313 314Print selected parts of lines from each file or selected lines, counting 315across all files. The output is separated by the delimiter which defaults to 316TAB for fields and empty string for characters. 317 318Standard options: C<-A, --args-file, --arguments-file=filename, --force, -i, 319--inpipe=shellcommand, -I, --infail, -o, --output=filename, -O, --outfail, -r, 320--record-size=number, --separator=string, -S, --synclines, -v, --verbose> 321 322=over 323 324=item -c I<list> 325 326=item --characters=I<list> 327 328Print all the characters specified by I<list>. I<List> may be any Perl 329expression returning a list of integers. The integers can be either positive, 330starting at zero to count from the beginning, or negative to count from the 331end. Unlike Unix C<cut>, the order you request is respected. 332 333Unlike in Perl's slice operator where a ".." range must be either positive or 334negative, C<&cut> allows starting with a positive and ending with a negative. 335But this is only available if your expression consists only of numbers, commas 336and "..". E.g. C<1..-2> means everything but the first (0) and the last (-1). 337 338The list expression can look at the whole line in C<$_>. Changes to that will 339be ignored, however, because when this expression is evaluated the line has 340already been split to Perl's autosplit variable C<@::F>. The numbers you 341return are in fact indices to that list. 342 343=item -d I<string> 344 345=item --delimiter=I<string> 346 347Set a new delimiter for input fields and output. Unlike Unix C<cut>, this may 348have any length. 349 350=item -E 351 352=item --noescape 353 354Treat C<\> as normal literals for C<-p, --printf=format>. 355 356=item -f I<list> 357 358=item --fields=I<list> 359 360Print all the groups specified by I<list>. I<List> is as described under 361C<-c, --characters=list>. Note that this hides the standard option C<-f> 362which must be given as C<--force>. 363 364=item -l I<list> 365 366=item --lines=I<list> 367 368Print all the lines specified by I<list>. I<List> is as described under C<-c, 369--characters=list> with one major difference: The first line has number 1, 370there is no line 0. This is definitely inefficient for big files, if you have 371a mixed positive to negative range in your list, as it reads everything to 372memory. Otherwise Perl could optimize this, but I don't know if it does. 373 374=item -m 375 376=item --matching 377 378Print only matching lines, i.e. ones which have enough characters or fields. 379This implies C<--only-delimited>, which is why you will miss single-field 380lines with C<--fields=0>. 381 382=item -p I<format> 383 384=item --printf=I<format> 385 386Apply format (with \escapes) to all fields or characters. 387 388=item -s 389 390=item --only-delimited 391 392Print only lines containing delimiters. 393 394=back 395 396 &cut -c 10-20,-5,25- $(input) 397 &cut -c 'grep $$_ % 3, 0..99' $(input) # 1st 100 columns not multiple of 3 398 &cut -d: --fields 0,4 --printf='%10s is %s\n' /etc/passwd 399 400 401=item date 402 403Not built in, but either of these partially does the same thing: 404 405 &expr localtime 406 &expr gmtime 407 408 409=item &echo I<[option ...] string ...> 410 411=item &printf I<[option ...] format argument ...> 412 413=item &yes I<[option ...] string ...> 414 415Writes all strings to stdout or the given outfile. Both C<&echo> and C<&yes> 416add a newline at the end. The strings, or for C<&printf> the format, may 417contain C<\> escapes, as they are known from C or modern Unix or Shell 418C<echo>. They are however as in Perl double-quotes, which means some 419differences, like that a single trailing C<\> is not allowed. Perl has a few 420more interesting escapes, but the ones you might expect to do something 421different are: 422 423=over 424 425=item \cA 426 427Is a control character ^A. 428 429=item \u 430 431Upcases the following letter. 432 433=item \U 434 435Upcases the rest, or up to the next C<\L> if found. 436 437=item \xI<HH>, \x{I<HHHH>} 438 439Is the character value of the given Hex code. Note that numeric codes are not 440portable to EBCDIC platforms! 441 442=back 443 444Unlike Unix C<yes>, C<&yes> is exactly like C<&echo>, except that it repeats 445the output for as long as it can, typically until an C<--output '| I<command>'> 446terminates. And, if C<&yes> has no arguments, it defaults to C<y>. 447 448Standard options: C<-A, --args-file, --arguments-file=filename, -f, --force, -o, 449--output=filename, -O, --outfail, -v, --verbose> 450 451=over 452 453=item -E 454 455=item --noescape 456 457Treat C<\> as normal literals. 458 459=item -n 460 461=item --nonewline 462 463Do not add a newline after the last string. (Not understood by C<&printf>.) 464 465=back 466 467 468 469=item &expr I<[option ...] perlcode ...> 470 471Print the scalar value of perlcode, which may be written as one or several 472arguments. Note that builtin commands are not parsed by the Shell, so C<*>, 473C<(> or C<< > >> are not special. But string quotes are parsed by makepp, so 474Perl strings must be quoted twice, unless you want to use barewords. If the 475value is false, this fails. Note that -- unlike in Unix C<expr> -- Perl's index 476function starts at 0 (false) and returns -1 (true) for failure. 477 478Standard options: C<-A, --args-file, --arguments-file=filename, -f, --force, -o, 479--output=filename, -O, --outfail, -v, --verbose> 480 481=over 482 483=item -n 484 485=item --nonewline 486 487Do not add a newline after the output. 488 489=back 490 491 &expr ($(VAR) - 3) * 2 < 1 && -1 || 1 492 &expr "$(VAR) - 3 * 2 < 1 ? 'joy' : 'sorrow'" -o $(output) 493 -&expr $(VAR) - 3 * 2 -o >>$(output) 494 495 496 497=item false 498 499Not very constructive and thus not built in, but 500L<C<&expr>|/expr_option_perlcode> with no argument or C<0> is comparable. 501 502 503 504=item fmt 505 506Not built in, but mentioned here since Perl provides a related functionality. 507However I had problems using the C<format> declaration in a makefile. What 508does work is the underlying C<formline> function. E.g. to transform a csv file 509consisting of names and prices to a tabular format: 510 511 sub csv2txt { 512 formline "\@<<<<<<<<<<<<<<< ^###########.##\n", split ','; 513 $_ = $^A; 514 $^A = ''; 515 } 516 517 %.txt: %.csv 518 &sed &csv2txt $(input) -o $(output) 519 520 521 522=item &grep I<[option ...] perlcode filename ...> 523 524=item &perl I<[option ...] perlcode filename ...> 525 526=item &sed I<[option ...] perlcode filename ...> 527 528All the files get read line by line (unless you gave a C<--separator> option), 529and I<perlcode> gets evaluated for each line, before it gets printed. C<&sed> 530is similar to C<perl -pe>, while C<&grep> only outputs those lines for which 531I<perlcode> returns a true value. C<&perl> is similar to C<perl -ne>, only 532outputting whatever you explicitly print in the I<perlcode>. The line content 533is available in C<$_>, which may be modified. 534 535Of these three, only C<&grep> will fail if it outputs nothing. Note that 536there is no ignore-case option, since you would do that with C</I<regexp>/i>. 537 538Standard options: C<-A, --args-file, --arguments-file=filename, -f, --force, -i, 539--inpipe=shellcommand, -I, --infail, -o, --output=filename, -O, --outfail, -r, 540--record-size=number, -s, --separator=string, -S, --synclines, --verbose> 541 542The option C<--synclines> only makes sence with C<&perl> if you use 543C<&Mpp::Cmds::print> to output C<$_>. Only C<&grep> has extra options: 544 545=over 546 547=item -c 548 549=item --count 550 551Suppress normal output; instead print a count of matching lines. With the C<-v, 552--invert-match> option (see below), count non-matching lines. 553 554=item -l 555 556=item --list 557 558=item --files-with-matches 559 560Output only the name of those files with matches. When this is combined with 561C<-v, --invert-match>, output the name of files with lines that don't match (a 562bit absurdly but compatible with Unix -vl). When this is combined with a 563doubled C<-vv>, output the name of files with no matches. 564 565=item -v 566 567=item --vice-versa 568 569=item --revert-match 570 571=item --invert-match 572 573Invert the sense of matching, to select non-matching lines. Note that this 574hides the standard option C<-v> which must be given as C<--verbose>. 575 576=item -w I<filename> 577 578=item --waste-file=I<filename> 579 580An optional waste basket for collecting the rejected lines. This is not only 581for debugging your selection code, but also for splitting your input in two. 582As with the normal output, you may modify $_ before returning false. 583 584=back 585 586 &sed s/foo/bar/ f1 f2 f3 -o outfile # like sed s/foo/bar/ f1 f2 f3 >outfile 587 &sed '$$_ = uc' f1 f2 f3 -o outfile # like tr '[:lower:]' '[:upper:]' f1 f2 f3 588 &grep '$$. % 3' f1 f2 f3 -o outfile # eliminate every 3rd line 589 &grep -c /match/i f1 f2 f3 # count the lines matching 'match' to STDOUT 590 591Without pushing you to mass generate accessors, here's how you could do it by 592simply putting a comment of RO or RW between each type and desired variable 593name, all on one line. The generated getter and optionally setter methods go 594into the next found public or protected section: 595 596 # Create get and maybe set method from "type /* R[OW] */ member;". 597 sub cxx_accessors { 598 $acc ||= ''; # Candidate for 5.10.0 state 599 if( m!^\s*(.+?)\s*/\*\s*R([OW])\s*\*/\s*(.+?)\s*;! ) { 600 $acc .= "#line $.\n"; # Tell C++ where this came from 601 $acc .= "void set\u$3( const $1 &__tmp ) { $3 = __tmp; }" 602 if $2 eq 'W'; 603 $acc .= "const $1 &get\u$3() const { return $3; }\n"; 604 } elsif( /^\s*(?:public|protected)\s*:/ ) { 605 $_ .= $acc; 606 $acc = ''; 607 } 608 } 609 610 %.cc: %.cc.in # Use &sed for I/O handling 611 &sed --sync-lines &cxx_accessors $(input) -o $(output) 612 613 614 615=item head 616 617=item tail 618 619These are not provided, but you can achieve the same result with 620L<C<&grep>|/grep_option_perlcode_filename> or L<C<&cut --lines>|/cut_option_filename>: 621 622 &grep 1..10 file # first ten lines 623 &grep 10..eof file # all lines from tenth onwards 624 &cut --lines -10..-1 file # last ten lines 625 626Note that 1..10 in C<&grep> is Perl's line number flip-flop operator, which 627annoyingly starts at 1. Don't start at 0, or the flip-flop will never become 628true. 629 630 631 632=item &install I<[option ...] sourcefile destfile> 633 634=item &install I<[option ...] sourcefile ... destdir> 635 636=item &install --directory I<[option ...] directory ...> 637 638Move or rename I<sourcefile> to I<destfile>, or multiple I<sourcefile>s to 639I<destdir> with the same name. This is the preferred way of transferring 640build results to their final installation locations. 641 642Every file system modification performed by C<&install> gets logged to the end 643of the file pointed to by the environment variable C<$INSTALL_LOG>, or, if 644that is not set but we are under a directory with a F<RootMakeppfile(.mk)>, to 645a file of F<.install_log> in that directory, or else to that file in the 646current directory. You may want to delete the logfile before a series of 647C<&install> invocations. 648 649Standard options: C<-A, --args-file, --arguments-file=filename, -v, --verbose> 650 651=over 652 653=item -c 654 655=item --copy 656 657Copy the files rather than moving them. This is preferable, as it doesn't 658force makepp to rebuild the file next time. But it is not the default, for 659compatibility with other install programs. 660 661=item -d 662 663=item --directory 664 665In the third form form of this command create all the given directories and 666any necessary parent directories. 667 668=item -g I<group> 669 670=item --group=I<group> 671 672Change the group ownership of the destination files. The group may be given 673by name or numerically. 674 675=item -l 676 677=item --link 678 679Try to link the files. If that fails, copy. 680 681=item --log=I<filename> 682 683=item --logfile=I<filename> 684 685Use I<filename> instead of normal logfile. 686 687=item -m I<mode> 688 689=item --mode=I<mode> 690 691Sets I<mode> for all destination files or directories. Mode must be an octal 692string. 693 694=item -o I<owner> 695 696=item --owner=I<owner> 697 698Change the ownership of the destination files. The owner may be given by name 699or numerically. 700 701=item -r 702 703=item --resolve 704 705=item --resolve-symbolic 706 707=item --resolve-symbolic-link 708 709=item --resolve-symlink 710 711=item -S 712 713=item --symbolic 714 715=item --symbolic-link 716 717=item --symlink 718 719Creates symbolic links instead of moving. These options are passed to 720L<C<&ln>|/ln_option_sourcefile_destfile> and are described there. 721 722=item -s 723 724=item --strip 725 726Calls the C<strip> utility, which must be in the C<$PATH>, on the destination 727files. 728 729=back 730 731 732 733=item &ln I<[option ...] sourcefile destfile> 734 735=item &ln I<[option ...] sourcefile> 736 737=item &ln I<[option ...] sourcefile ... destdir> 738 739Link I<sourcefile> to I<destfile>, one I<sourcefile> to current directory or 740multiple I<sourcefile>s to I<destdir> with the same name. 741 742Standard options: C<-A, --args-file, --arguments-file=filename, -f, --force, -v, 743--verbose> 744 745=over 746 747=item -r 748 749=item --resolve 750 751=item --resolve-symbolic 752 753=item --resolve-symbolic-link 754 755=item --resolve-symlink 756 757This is what you always wanted C<ln -s> to do. Create symbolic rather than 758hard links, not to the strings specified, but really to the given files. 759 760=item -s 761 762=item --symbolic 763 764=item --symbolic-link 765 766=item --symlink 767 768Create symbolic rather than hard links. 769 770=back 771 772B<Note:> On various file or operating systems, this operation is not 773supported. Or it is, e.g. by Cygwin, but not understood by native Windows 774compilers, if you use one. For a makefile you can't change, to get at least 775some sort of result, C<&ln> and C<&cp -l -s> can copy the files for you 776instead (not directories though). To achieve this, you need to export the 777following variable before calling makepp: 778 779=over 780 781=item export MAKEPP_LN_CP=1 782 783C<&ln> --resolve or --symbolic will copy the files instead of creating a 784symbolic link. 785 786=item export MAKEPP_LN_CP=2 787 788C<&ln> will copy the files instead of creating a hard link. 789 790=item export MAKEPP_LN_CP=3 791 792All invocations of C<&ln> will copy the files instead of creating either kind 793of link. 794 795=back 796 797 798 799=item &mkdir I<[option ...] directory ...> 800 801Create the directories. 802 803Standard options: C<-A, --args-file, --arguments-file=filename, -f, --force, -v, 804--verbose> 805 806=over 807 808=item -m I<mode> 809 810=item --mode=I<mode> 811 812Sets I<mode> for all created directories, irrespective of the umask. Mode 813must be an octal string. 814 815=item -p 816 817=item --parent 818 819Also create any necessary parent directories. Ignore directory creation 820failure due to the directory already existing (even if it was created 821concurrently by another process). 822 823=back 824 825 826 827=item &mv I<[option ...] sourcefile destfile> 828 829=item &mv I<[option ...] sourcefile> 830 831=item &mv I<[option ...] sourcefile ... destdir> 832 833Move or rename I<sourcefile> to I<destfile>, one I<sourcefile> to current 834directory or multiple I<sourcefile>s to I<destdir> with the same name. 835 836Standard options: C<-A, --args-file, --arguments-file=filename, -f, --force, -v, 837--verbose> 838 839 840 841=item m4 842 843Not built in, but 844L<C<&preprocess>|/preprocess_option_variable_definition_filename> is, and 845L<C<&template>|/template_option_macro_definition_filename> is almost as powerful. 846 847 848 849=item &preprocess I<[option ...] variable=definition ... filename ...> 850 851This preprocesses the files exactly the same way makepp does for makefiles. 852This is more powerful than 853L<C<&template>|/template_option_macro_definition_filename> but syntactically 854not suited to files with lots of C<$>-signs, like Makefiles or scripts. 855 856L<Conditional statements|makepp_statements/Conditionals>, as well as the 857statements C<include>/C<_include> (which here neither build the file nor 858search upwards), C<perl>/C<makeperl>/C<perl_begin> or C<sub>/C<makesub>, or 859any statements you define within the file, are processed. Empty and comment 860lines are eliminated. 861 862But, instead of learning build rules, it will output all remaining lines after 863C<$(...)> expression expansion. To prevent statement from being recognized 864as such, you can precede them with an empty expression C<$()>. The same 865applies to lines you want to stay empty or which shall retain a leading 866comment sign. Likewise, if a trailing backslash is not to join a line with 867the next, put C<$()> after it. 868 869 A normal line gets output as is. 870 A line with $(MAKEEXPRESSIONS) gets expanded and output. 871 ifdef WANTTHIS # does not get output whether defined or not 872 might not get output 873 endif 874 include some files 875 _include some files that might not exist # or -include 876 $()include empty expression prevents keyword from being recognized. 877 # Comment lines and empty lines get swallowed. 878 879 $()# Unless they get masked with an empty expression. 880 $() 881 Empty expression prevents \$() 882 backslash continuation from being recognized. 883 884might give: 885 886 A normal line gets output as is. 887 A line with whatever gets expanded and output. 888 lots of slurped in content here... 889 include empty expression prevents keyword from being recognized. 890 # Unless they get masked with an empty expression. 891 892 Empty expression prevents \ 893 backslash continuation from being recognized. 894 895Standard options: C<-A, --args-file, --arguments-file=filename, -f, --force, -o, 896--output=filename, -O, --outfail, -S, --synclines, -v, --verbose> 897 898=over 899 900=item -a 901 902=item --assignment 903 904Also treat assignments within the files as makepp would. Alas such lines 905can't be masked with an empty C<$()>, because it is legal to construct 906variable names with expressions. This additionally recognizes the statements 907C<define>, C<export>/C<unexport> and C<override> (these can be masked with 908C<$()>). 909 910=item -h \\%I<hash> 911 912=item --hashref=\\%I<hash> 913 914This allows preallocation of the variable values, including long ones not easily 915passed in a command. The passed expression may be any Perl code that returns 916a hash reference. This is merged with any other variables passed to the command, 917including from another C<--hashref> option. 918 919=back 920 921 922 923=item &rm I<[option ...] filename ...> 924 925Delete files if you have directory write permission. This is what Unix 926C<rm -f> would delete, since it has a special protection for interactive use 927not needed in a Makefile. 928 929Standard options: C<-A, --args-file, --arguments-file=filename, -v, --verbose> 930 931=over 932 933=item -f 934 935=item --force 936 937This prevents complaining about inexistent files. That is a side effect this 938option has in Unix, and the only one that makes sense here. 939 940=item -m 941 942=item --metainfo 943 944In addition to the given files, this also deletes the meta information makepp 945stores about them in the .makepp directory. Thus makepp forgets all it ever 946knew about the given files. If the .makepp directory becomes empty after 947this, it too is deleted. 948 949=back 950 951This will also delete given directories, but only if they are empty. To 952facilitate this, it will delete directories last, in the order of descending 953depth. So you can use C<**> expressions to delete whole hierarchies. Here's 954an example to be found in many top level make files. Note that there is a 955L<C<makeppclean>|makeppclean> utility that can do this more efficiently. 956 957 $(phony cleanold): 958 &rm -fm $(only-stale **/*) 959 960 $(phony clean): cleanold 961 &rm -f $(wildcard **/*.[ao]) 962 963 $(phony distclean): clean 964 &rm -fm $(only-targets **/*) 965 966 967 968=item rmdir 969 970Not built in, but L<C<&rm>|/rm_option_filename> can handle this. 971 972 973 974=item &sort I<[option ...] filename ...> 975 976Sorts all files together in lexicographic order. This is inefficient for 977rather big files, because it happens completely in memory. It will fail if 978the combined size of all files exceeds the memory you are entitled to. 979 980Standard options: C<-A, --args-file, --arguments-file=filename, -f, --force, -i, 981--inpipe=shellcommand, -I, --infail, -o, --output=filename, -O, --outfail, 982--record-size=number, -s, --separator=string, -v, --verbose> 983 984=over 985 986=item -c I<perlcode> 987 988=item --compare=I<perlcode> 989 990I<perlcode> represents a Perl sort block, with the two sorting candidates in 991C<$a> and C<$b>. 992 993=item -n 994 995=item --numeric 996 997=item --numeric-sort 998 999This sorts sorts numerically on the beginnings of records. Leading whitespace 1000is skipped. You can use C<--transform> and C<--detransform> if the numbers 1001are not at the beginning. 1002 1003=item -r 1004 1005=item --reverse 1006 1007Output the results in the reverse order. Note that this hides the standard 1008option C<-r> which must be given as C<--record-size>. 1009 1010=item -t I<perlcode> 1011 1012=item --transform=I<perlcode> 1013 1014=item -d I<perlcode> 1015 1016=item --detransform=I<perlcode> 1017 1018If you have a complex code, sorting gets more and more expensive in proportion 1019to the number of records I<n>, because the code gets called O(I<n> log(I<n>)) 1020times. To avoid that, you can allow Perl to concentrate on sorting, by first 1021modifying the strings, such that complicated search criteria extraction 1022happens once per record, and modifying them back, once they are sorted. 1023 1024If these options are given, the C<--transform> I<perlcode> gets mapped to the 1025records in C<$_> one after another, and can modify them. After sorting, the 1026C<--detransform> I<perlcode> gets mapped to the modified records in C<$_> one 1027after another, and can modify them back. You will usually use neither or both 1028of these options, unless you want to output modified lines. 1029 1030Turning the strings into a structure of extracted sort criteria, which your 1031C<--compare> I<perlcode> can pick up is known as the Schwartzian Transform 1032(ST). Packing everything into the string itself, so that no C<--compare> 1033I<perlcode> is needed, allowing the whole sorting to happen without performing 1034expensive Perl code, is known as the Guttmann-Rosler Transform (GRT). You can 1035find tips by searching for those names on the web. 1036 1037 # Expensively sort numerical expressions by value ($$ protects $ from makepp expansion) 1038 &sort --compare 'eval( $$a ) <=> eval( $$b )' $(input) -o >>$(output) 1039 1040 # ST for case insensitive sorting 1041 &sort -t '$$_ = [lc, $$_]' -c '$$a->[0] cmp $$b->[0]' -d '$$_->[1]' $(input) -o >>$(output) 1042 1043 # GRT using modification functions defined elsewhere in the Makeppfile 1044 &sort -t &transform -d &detransform $(input) -o >>$(output) 1045 1046=item -u 1047 1048=item --uniq 1049 1050=item --unique 1051 1052After sorting, eliminate duplicates. These are either identical lines, or if 1053the C<--compare> option is given, ones which that I<perlcode> reports as 1054equivalent. 1055 1056=back 1057 1058 1059 1060=item &template I<[option ...] macro=definition ... filename ...> 1061 1062This is a macro preprocessor, not quite as powerful as C<m4>, but covers more 1063than is found in many makefiles. See L<C<&preprocess>|/preprocess_option_variable_definition_filename> for a 1064more powerful alternative. Any normal text goes through unchanged. It 1065replaces all occurrences of C<@macro@>, C<@macro(arg1,arg2...)@> or everything 1066between C<@@macro@@>, C<@@macro(arg1,arg2...)@@> and C<@@> with I<definition>. 1067If there are args, they replace C<$1> through C<$9> or C<${I<number>}> in 1068I<definition>. One level of macro nesting is possible in that the args in 1069parenthesis may contain plain C<@macro@> invocations, as in C<@f(@x@)@>, where 1070@x@ gets expanded before being replaced into the body of C<f>. 1071 1072The simple C<@...@> cases are single line, but may mask a trailing newline if 1073the closing C<@> is immediately followed by a backslash. The multiline 1074C<@@...@@> cases must also fit on one line, but the corresponding C<@@> may be 1075on a different line. This is useful if you have a workaround code block in an 1076unprocessed script, which is to get replaced with the configured code. 1077 1078In addition to passing macro definitions on the command line, you can also put 1079C<@macro=definition@> or C<@macro?=definition@> into the file. The latter 1080only takes effect if the macro was not defined, presumably on the command 1081line. You can also call C<@{ I<Perlcode> }@> or C<@@{ I<Perlcode> }@@ ... @@> 1082in the file. The Perl variable C<$ARGV> contains the name of the current 1083input file. If you call C<@macro { I<Perlcode> }@>, then you define a new 1084macro, the body of which is a Perl sub. The arguments, if there are any, get 1085passed in as C<@_>. 1086 1087 @m1=some definition@\ 1088 @m2=foo $1 bar@\ 1089 @middle_of_arg=iddl@\ 1090 @m1@ @m2(m@middle_of_arg@e)@ 1091 @@m2(many lines)@@ 1092 ... 1093 @@ plain text 1 + 2 = @{ 1 + 2 }@ 1094 1095becomes 1096 1097 some definition foo middle bar 1098 foo many lines bar plain text 1 + 2 = 3 1099 1100 1101Standard options: C<-A, --args-file, --arguments-file=filename, -f, --force, 1102-i, --inpipe=shellcommand, -I, --infail, -o, --output=filename, -O, --outfail, 1103-S, --synclines, -v, --verbose> 1104 1105=over 1106 1107=item -h \\%I<hash> 1108 1109=item --hashref=\\%I<hash> 1110 1111This allows preallocation of the macro values, including long ones not easily 1112passed in a command. The passed expression may be any Perl code that returns 1113a hash reference. This is merged with any other macros passed to the command, 1114including from another C<--hashref> option. A hash value may also be a code 1115reference, in that case the function gets called, as with C<@macro { 1116I<Perlcode> }@> definitions. 1117 1118=item -s I</prefix/suffix/> 1119 1120=item --simple=I</prefix/suffix/> 1121 1122This replaces C<@> before and after I<var> with I<prefix> and I<suffix> 1123respectively. The first character is the separator and need not be a slash. 1124 1125=item -m I</prefix/suffix/afterprefix/[aftersuffix/]> 1126 1127=item --multiline=I</prefix/suffix/afterprefix/[aftersuffix/]> 1128 1129This replaces C<@@> before and after I<var> and at the end of the block with 1130I<prefix>, I<suffix> and I<afterprefix> respectively. If I<aftersuffix> is 1131also given, the I<var> name must get repeated before it. The first character 1132is the separator and need not be a slash. E.g. an XML-ish 1133 1134 --simple=|<|/>| --multiline=|<|>|</|>| 1135 1136=item -d 1137 1138=item --defined 1139 1140Replace only instances of macros which are actually defined. 1141 1142=back 1143 1144 1145 1146=item &touch I<[option ...] filename ...> 1147 1148Updates the modification and access timestamps of each file to now. If the 1149file doesn't exist, it gets created. 1150 1151Standard options: C<-A, --args-file, --arguments-file=filename, -v, --verbose> 1152 1153 1154 1155=item &uninstall I<[option ...] [filename ...]> 1156 1157Uninstall files previously installed by L<C<&install>|/install_option_sourcefile_destfile>. The 1158I<filename>s are logfiles written by C<&install>. If none are given, nor an 1159C<--inpipe> option, reads the default logfile of C<&install>. 1160 1161Standard options: C<-A, --args-file, --arguments-file=filename, -i, 1162--inpipe=shellcommand, -I, --infail, -v, --verbose> 1163 1164 1165 1166=item &uniq I<[option ...] filename ...> 1167 1168Discard all but one of successive equal lines. 1169 1170Standard options: C<-A, --args-file, --arguments-file=filename, -f, --force, -i, 1171--inpipe=shellcommand, -I, --infail, -o, --output=filename, -O, --outfail, -r, 1172--record-size=number, -s, --separator=string, -S, --synclines, -v, --verbose> 1173 1174=over 1175 1176=item -c I<perlcode> 1177 1178=item --compare=I<perlcode> 1179 1180This I<Perlcode> gets the previous and current lines in C<$a> and C<$b> and 1181shall return true if it considers the two lines equal. 1182 1183=back 1184 1185 &uniq --compare='lc( $$a ) eq lc $$b' $(inputs) -o $(output) 1186 1187 1188 1189=item tr 1190 1191Not built in, but L<C<&sed>|/grep_option_perlcode_filename> can handle this. 1192 1193 1194=back 1195 1196 1197=head1 AUTHOR 1198 1199Daniel Pfeiffer (occitan@esperanto.org) 1200