From 27629ee025d18e084ccfbc3b432a603fd4402c9a Mon Sep 17 00:00:00 2001 From: Rudolf Jaksa Date: Sun, 30 Jun 2024 17:23:18 +0200 Subject: [PATCH] 0.8b --- Makefile | 37 ++++++++++++++++------- README.md | 51 ++++++++++++++------------------ pcpp | 16 ++++++++-- doc/pcpp.md => pcpp.md | 2 +- pcpp.pl | 4 ++- uninclude | 16 ++++++++-- doc/uninclude.md => uninclude.md | 2 +- uninclude.pl | 4 ++- usr/bin/pcpp | 16 ++++++++-- 9 files changed, 96 insertions(+), 52 deletions(-) rename doc/pcpp.md => pcpp.md (97%) rename doc/uninclude.md => uninclude.md (90%) diff --git a/Makefile b/Makefile index d1f226a..4409d32 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -28,15 +26,26 @@ $(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 @@ -44,7 +53,13 @@ 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 diff --git a/README.md b/README.md index daa7a06..fa68733 100644 --- a/README.md +++ b/README.md @@ -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 ``` @@ -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" @@ -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); @@ -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 @@ -277,8 +272,8 @@ only included files. The usage in the Makefile is: ### See also -   [pcpp -h](doc/pcpp.md) -   [uninclude -h](doc/uninclude.md) +   [pcpp -h](pcpp.md) +   [uninclude -h](uninclude.md) ### Installation diff --git a/pcpp b/pcpp index a4ee03d..96df86b 100755 --- a/pcpp +++ b/pcpp @@ -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=< .pcpp.d) VERSION - $SIGN + $PACKAGE-$VERSION$SUBVERSION CK($AUTHOR) CK(built $BUILT) EOF diff --git a/doc/pcpp.md b/pcpp.md similarity index 97% rename from doc/pcpp.md rename to pcpp.md index 6d0b217..8dbaa8e 100644 --- a/doc/pcpp.md +++ b/pcpp.md @@ -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 diff --git a/pcpp.pl b/pcpp.pl index 1e69d32..fb5377e 100644 --- a/pcpp.pl +++ b/pcpp.pl @@ -1,3 +1,5 @@ +# include .built.pcpp.pl .version.pl + $HELP=< .pcpp.d) VERSION - $SIGN + $PACKAGE-$VERSION$SUBVERSION CK($AUTHOR) CK(built $BUILT) EOF diff --git a/uninclude b/uninclude index e8dd36d..aeb0fed 100755 --- a/uninclude +++ b/uninclude @@ -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=< .pcpp.d) VERSION - $SIGN + $PACKAGE-$VERSION$SUBVERSION CK($AUTHOR) CK(built $BUILT) EOF