epics-modules / iocStats

EPICS IOC Status and Control
Other
12 stars 40 forks source link

Use perl instead of sed #63

Open FreddieAkeroyd opened 1 month ago

FreddieAkeroyd commented 1 month ago

Windows does not have sed so change to use perl that is already needed for building EPICS

See epics-modules/iocStats#62

FreddieAkeroyd commented 1 month ago

Have converted to draft as though it works on windows it doesn't on linux. The problem is that ' does not work on windows but using " means the perl variables $ get interpreted by the linux shell. Tried adding \ which makes it work on linux but then stops working on windows. Could get round this by putting the perl code in a separate file rather than using -e but maybe there is some cleverer quoting that can be done

simon-ess commented 1 month ago

It might be possible to do something like

ifeq ($(strip $(OS_CLASS)),WIN32)
 QUOTE="
else
 QUOTE='
endif

$(COMMON_DIR)/siteEnvVars.substitutions: $(EPICS_BASE)/configure/CONFIG_SITE_ENV
    @echo Expanding siteEnvVars.substitutions from CONFIG_SITE_ENV....
    @echo file iocEnvVar.template> $@
    @echo {>> $@
    @echo pattern>> $@
    @echo { ENVNAME, ENVVAR, ENVTYPE }>> $@
    @perl -n -e $(QUOTE)$$m = s/^EPICS_([A-Z_]*).*/{$${1}, EPICS_$${1}, epics}/; print $$_ if $$m;$(QUOTE) < $< >> $@
    @echo }>> $@

though I am not sure this is much better... 😄

simon-ess commented 1 month ago

See e.g. https://stackoverflow.com/questions/13631551/make-echo-includes-quotes-in-generated-file

FreddieAkeroyd commented 1 month ago

Well it makes it clear what we are trying to do at least, I am happy to go with that if you are - thanks

FreddieAkeroyd commented 1 month ago

Unless you think putting the s/ command into a separate file for perl to execute from Make is cleaner

anjohnson commented 1 month ago

Surely it would be simpler to use a stand-alone Perl script to do the whole job of generating the siteEnvVars.substitutions file? There'd be no need to mess around with the $(QUOTE) variable, and the Perl code would also be easier to read and modify. That might even fix the Base-3.14 build failure, but I haven't looked at that properly to be sure.

simon-ess commented 1 month ago

Oh no more perl scripts

😄

Anyhow, I think you are correct in this case that a standalone script is easier; this is a pretty simple parsing, but the solution is better.