Skip to content

Commit

Permalink
0.8b
Browse files Browse the repository at this point in the history
  • Loading branch information
rudojaksa committed Jun 30, 2024
1 parent 8dc82f8 commit 27629ee
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 52 deletions.
37 changes: 26 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
PACKAGE := pcpp
VERSION := 0.8
AUTHOR := R.Jaksa 2008,2024 GPLv3
SUBVERSION := a
SUBVERSION := b

SHELL := /bin/bash
PATH := usr/bin:$(PATH)
PKGNAME := $(PACKAGE)-$(VERSION)$(SUBVERSION)
SIGN := "$(PKGNAME) $(AUTHOR)"
PRJNAME := $(shell getversion -prj)
PROJECT := $(shell getversion -prj)
DATE := $(shell date '+%Y-%m-%d')

BIN := pcpp uninclude
DEP := $(BIN:%=.%.d)
DOC := $(BIN:%=doc/%.md)
DOC := $(BIN:%=%.md)

all: $(BIN) $(DOC)

$(BIN): %: %.pl .%.d Makefile
$(BIN): %: %.pl .%.d .version.pl .built.%.pl Makefile
echo -e '#!/usr/bin/perl' > $@
echo -e "# $@ generated from $(PKGNAME)/$< $(DATE)\n" >> $@
echo -e '$$SIGN = $(SIGN);\n' >> $@
usr/bin/pcpp $< >> $@
chmod 755 $@
@sync # to ensure pcpp is saved before used in the next rule
Expand All @@ -28,23 +26,40 @@ $(BIN): %: %.pl .%.d Makefile
$(DEP): .%.d: %.pl
pcpp -d $(<:%.pl=%) $< > $@

$(DOC): doc/%.md: % | doc
$(DOC): %.md: %
./$* -h | man2md > $@
doc:
mkdir -p doc

.version.pl: Makefile
@echo 'our $$PACKAGE = "$(PACKAGE)";' > $@
@echo 'our $$VERSION = "$(VERSION)";' >> $@
@echo 'our $$AUTHOR = "$(AUTHOR)";' >> $@
@echo 'our $$SUBVERSION = "$(SUBVERSION)";' >> $@
@echo "update $@"

.PRECIOUS: .built.%.pl
.built.%.pl: %.pl .version.pl Makefile
@echo 'our $$BUILT = "$(DATE)";' > $@
@echo "update $@"

# /map install
ifneq ($(wildcard /map),)
install: $(BIN)
mapinstall /box/$(PRJNAME)/$(PKGNAME) /map/$(PACKAGE) bin $(BIN)
install: $(BIN) $(DOC) README.md
mapinstall -v /box/$(PROJECT)/$(PKGNAME) /map/$(PACKAGE) bin $(BIN)
mapinstall -v /box/$(PROJECT)/$(PKGNAME) /map/$(PACKAGE) doc $(DOC) README.md

# /usr/local install
else
install: $(BIN)
install $(BIN) /usr/local/bin
endif

# copy current pcpp to local usr/bin
copy:
cp pcpp usr/bin

clean:
rm -f .version.pl
rm -f .built.*.pl
rm -f $(DEP)

mrproper: clean
Expand Down
51 changes: 23 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ handles:
To "use" the pcpp pre-processed code it is necessary to run the pcpp first,
like:

```
``` sh
pcpp abc.in.pl > abc.pl
perl abc.pl
```
Expand Down Expand Up @@ -101,7 +101,7 @@ comments without any effect:
Included content in the pcpp output is "watermarked" by the `# included` and
`# end` comments/directives (in C/C++ `// included` and `// end`):

```
``` perl
# included "abc.pl"
...
# end "abc.pl"
Expand All @@ -110,14 +110,14 @@ Included content in the pcpp output is "watermarked" by the `# included` and
Indentation of the include statement is propagated into output. For instance
a two-spaces indentation of the hash of include statement in perl code:

```
``` perl
some(code);
# include abc.pl
```

will lead to added two spaces to the original indentation in included file:

```
``` perl
some(code);
# included abc.pl
originally_unindented_abc_pl(code);
Expand Down Expand Up @@ -213,53 +213,48 @@ which when included back will become:
# end def.pl
```

### Use in Makefile
### Pcpp in Makefile

Follows a Makefile rule example to create the perl executable `xyz` from its source
`xyz.pl` and two included files. First the #! interpreter identifier is generated,
then any initialization content added and then pcpp is called:
Example to make `xyz` from from its source `xyz.pl` and two included files:

``` makefile
xyz: xyz.pl inc1.pl inc2.pl
echo '#!/usr/bin/perl' > $@
pcpp $< >> $@
@chmod 755 $@
@sync
@sync # to ensure the result is saved before used in the next rule
```

The `sync` is needed only if the xyz will be used in another rule in Makefile.
This will ensure that the pcpp output is realy saved before the use, otherwise
it might fail randomly. Or with the header comment and `$SIGN` variable to be
used inside the script:
1. generate #! interpreter identifier
2. build `xyz` from `xyz.pl`
3. make it executable
4. sync the result before it is used by other makefile rule (otherwise it can be incomplete)

More complex example:

``` makefile
OUTPUT := xyz
DEPENDENCIES := $(shell pcpp -lp $(OUTPUT:%=%.pl))
SIGN := "$(PKGNAME) $(AUTHOR)"
DATE := $(shell date '+%Y-%m-%d')

xyz: %: %.pl $(DEPENDENCIES) Makefile
$(OUTPUT): %: %.pl $(DEPENDENCIES) Makefile
echo -e '#!/usr/bin/perl' > $@
echo -e "# $@ generated from $(PKGNAME)/$< $(DATE)\n" >> $@
echo -e '$$SIGN = $(SIGN);\n' >> $@
pcpp $< >> $@
@chmod 755 $@
@sync # to ensure the result is saved before used in the next rule
@sync
```

To obtain dependencies of pcpp-ed file, the `pcpp -lp` can be used, like in
this example for the xyz perl script: (dependencies are a list of files to be
included)

``` makefile
BIN := xyz
DEP := $(shell pcpp -lp $(BIN:%=%.pl))
```
* `DEPENDENCIES` are a list of files to be included obtained by `pcpp -lp`
* `SIGN` is a variable made available from Makefile into script

### Dependency files

The `pcpp -d target_name` can be used to generate a dependency file for
Makefile. Compared to the `-lp` option, the `-d` and `-dd` options also
include the input file into the list. The `pcpp -lp input | xargs` will list
only included files. The usage in the Makefile is:
Makefile. Compared to the `-lp` option, the `-d` and `-dd` options also add
the input file into the list. Example Makefile:

``` makefile
# require rebuild of the dependencies file .abc.d when processing abc.pl
Expand All @@ -277,8 +272,8 @@ only included files. The usage in the Makefile is:

### See also

&nbsp;&nbsp; [pcpp -h](doc/pcpp.md)
&nbsp;&nbsp; [uninclude -h](doc/uninclude.md)
&nbsp;&nbsp; [pcpp -h](pcpp.md)
&nbsp;&nbsp; [uninclude -h](uninclude.md)

### Installation

Expand Down
16 changes: 13 additions & 3 deletions pcpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
#!/usr/bin/perl
# pcpp generated from pcpp-0.8a/pcpp.pl 2024-06-30
# pcpp generated from pcpp-0.8b/pcpp.pl 2024-06-30

$SIGN = "pcpp-0.8a R.Jaksa 2008,2024 GPLv3";

# included ".built.pcpp.pl"
our $BUILT = "2024-06-30";
# end ".built.pcpp.pl"

# included ".version.pl"
our $PACKAGE = "pcpp";
our $VERSION = "0.8";
our $AUTHOR = "R.Jaksa 2008,2024 GPLv3";
our $SUBVERSION = "b";
# end ".version.pl"

$HELP=<<EOF;
Expand Down Expand Up @@ -65,7 +75,7 @@ EXAMPLES
CW(pcpp -d pcpp pcpp.pl > .pcpp.d)
VERSION
$SIGN
$PACKAGE-$VERSION$SUBVERSION CK($AUTHOR) CK(built $BUILT)
EOF

Expand Down
2 changes: 1 addition & 1 deletion doc/pcpp.md → pcpp.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ Simple Perl/Python/C/C++ preprocessor for in-comment directives.
pcpp -d pcpp pcpp.pl > .pcpp.d

### VERSION
pcpp-0.8a R.Jaksa 2008,2024 GPLv3
pcpp-0.8b R.Jaksa 2008,2024 GPLv3 built 2024-06-30

4 changes: 3 additions & 1 deletion pcpp.pl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# include .built.pcpp.pl .version.pl

$HELP=<<EOF;
NAME
Expand Down Expand Up @@ -60,7 +62,7 @@
CW(pcpp -d pcpp pcpp.pl > .pcpp.d)
VERSION
$SIGN
$PACKAGE-$VERSION$SUBVERSION CK($AUTHOR) CK(built $BUILT)
EOF

Expand Down
16 changes: 13 additions & 3 deletions uninclude
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
#!/usr/bin/perl
# uninclude generated from pcpp-0.8a/uninclude.pl 2024-06-30
# uninclude generated from pcpp-0.8b/uninclude.pl 2024-06-30

$SIGN = "pcpp-0.8a R.Jaksa 2008,2024 GPLv3";

# included ".built.uninclude.pl"
our $BUILT = "2024-06-30";
# end ".built.uninclude.pl"

# included ".version.pl"
our $PACKAGE = "pcpp";
our $VERSION = "0.8";
our $AUTHOR = "R.Jaksa 2008,2024 GPLv3";
our $SUBVERSION = "b";
# end ".version.pl"

$HELP=<<EOF;
Expand All @@ -23,7 +33,7 @@ OPTIONS
-ni Don't return back #include statements.
VERSION
$SIGN
$PACKAGE-$VERSION$SUBVERSION CK($AUTHOR) CK(built $BUILT)
EOF

Expand Down
2 changes: 1 addition & 1 deletion doc/uninclude.md → uninclude.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ but they are flattened to a single level direct includes.
-ni Don't return back #include statements.

### VERSION
pcpp-0.8a R.Jaksa 2008,2024 GPLv3
pcpp-0.8b R.Jaksa 2008,2024 GPLv3 built 2024-06-30

4 changes: 3 additions & 1 deletion uninclude.pl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# include .built.uninclude.pl .version.pl

$HELP=<<EOF;
NAME
Expand All @@ -18,7 +20,7 @@
-ni Don't return back #include statements.
VERSION
$SIGN
$PACKAGE-$VERSION$SUBVERSION CK($AUTHOR) CK(built $BUILT)
EOF
Expand Down
16 changes: 13 additions & 3 deletions usr/bin/pcpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
#!/usr/bin/perl
# pcpp generated from pcpp-0.8a/pcpp.pl 2024-06-30
# pcpp generated from pcpp-0.8b/pcpp.pl 2024-06-30

$SIGN = "pcpp-0.8a R.Jaksa 2008,2024 GPLv3";

# included ".built.pcpp.pl"
our $BUILT = "2024-06-30";
# end ".built.pcpp.pl"

# included ".version.pl"
our $PACKAGE = "pcpp";
our $VERSION = "0.8";
our $AUTHOR = "R.Jaksa 2008,2024 GPLv3";
our $SUBVERSION = "b";
# end ".version.pl"

$HELP=<<EOF;
Expand Down Expand Up @@ -65,7 +75,7 @@ EXAMPLES
CW(pcpp -d pcpp pcpp.pl > .pcpp.d)
VERSION
$SIGN
$PACKAGE-$VERSION$SUBVERSION CK($AUTHOR) CK(built $BUILT)
EOF

Expand Down

0 comments on commit 27629ee

Please sign in to comment.