简体   繁体   中英

How to do looping in perl for makefile

I am trying to automate the creation of php class with makefile and perl oneliner .

I have this file document.txt

[ENTITY]
Document
MyDefaultBundle
number:string(200)
issueDate:datetime
expiryDate:datetime
file_path:string(200)
filename:string(200)
description:text
document_type:string(200)

Basically firstline is classname , second is Bundlename and third is fields

I am using this in make file to execute symfony command to generate classes

MYFILE = Entity/document.txt
READ_ENTITY=eval `perl -l -00pe 'y/\n\r[]/ /d; s/([A-Z]+) (\w+) (\w+) (.*)/$$1=$$3:$$2\nFIELDS="$$4"\n/g' $1`
mytest:
        $(call READ_ENTITY,$(MYFILE)) && $(SYMFONY_COMMAND) --entity=$$ENTITY --fields="$$FIELDS" 

This is working fine for one entity. (i have escaped $ with $$)

Now my condition is that i have multiple ENTITIES in loop

document.txt

[ENTITY]
Document
MyDefaultBundle
number:string(200)
issueDate:datetime
expiryDate:datetime
file_path:string(200)
filename:string(200)
description:text
document_type:string(200)

[ENTITY]
Document2
MyDefaultBundle
number:string(200)
issueDate:datetime
expiryDate:datetime
file_path:string(200)
filename:string(200)
description:text
document_type:string(200)

[ENTITY]
Document3
MyDefaultBundle
number:string(200)
issueDate:datetime
expiryDate:datetime
file_path:string(200)
filename:string(200)
description:text
document_type:string(200)

so i want to execute that statement in loop. I am not sure how to do that inside make file.

basically with eval i ama making shell variable ENTITY AND FIELDS and then using that in symfony command line

Any ideas??

EDIT:

For the perl command the document.txt shown above, that is input

The output of perl coomand is

ENTITY=MyDefaultBundle:Document
FIELDS="number:string(200) issueDate:datetime expiryDate:datetime file_path:string(200) filename:string(200) description:text document_type:string(200)"

which basically makes them as shell variable so that i can insert them with $ENTITY

The problem is when i have multiple [ENTITY] seprated by space then i can't use that as last entry with overwrite the ENTITY VARIABLE.

i want some thing like

for [ENTITY] IN document.txt
   EXECUTE $(call READ_ENTITY,$(MYFILE)) && $(SYMFONY_COMMAND) --entity=$$ENTITY --fields="$$FIELDS"

So that in each loop i have different ENTITY and FIELDS variable

You may not need a loop here if you put makefile pattern rules to use.

  1. Create one input file for each output php document.
  2. Create a pattern rule that takes one input file and produces one php document. Make sure the command produces the file that is the target name:

     # Take input files from Entity/, produce outputs in Documents/ Documents/Document%.php : Entity/document%.txt EXECUTE $(call READ_ENTITY,$<) && $(SYMFONY_COMMAND) --entity=$$ENTITY --fields="$$FIELDS" --output-filename=$@ 
  3. Create a rule that depends on the documents that need to be built:

     all : Documents/Document1.php Documents/Document2.php Documents/Document3.php .PHONY: all 
  4. Invoke make all . If target all is the first target in your makefile (it is a convention), then just make .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM