C ++ filter through perl script?

I have a perl script I would like to filter cpp / h files before gcc processes them normally - basically as an extra preprocessing step. Is there an easy way to do this? I understand that I can transfer cpp files to a script and get gcc from the output from stdin, but this does not help in the header files.

+3
source share
5 answers

The classic way to handle such a process is to consider the source code (input to the Perl filter) as a new language with a new file suffix. Then you indicate makethat the way to compile the C ++ source file from this new file type is with a Perl script.

For example:

  • New suffix: .ccp
  • ( .cc):

    .ccp.cc:
            ${FILTERSCRIPT} $<
    
  • - ++.

- . .ccp , make .ccp, .cc. .cc, , .ccp .cc . (: ".ccp.o" ".ccp.cc" , ".cc" , , make .cc ', .)

, script, ++.

+7

C ++ . - makefile ( - ) perl script . , , , , . , , ? , , .

+2

gcc, Perl script, gcc? - plgcc CC=plgcc makefile. script include - script , , , gcc.

+2

GCC . script , cpp ( gcc). gcc -B -no-integrated-cpp.

. , , (, , ++, ac, ).

+2

, - . , - , _pp.

# These are your source files to be preprocessed
SRC_RAW = mysrc_pp.cpp

# These are the source files after preprocessing
SRC_PP = $(patsubst %_pp.cpp, %.cpp, $(SRC_RAW))

ALL_SRC = $(SRC) main.cpp other.cpp

OBJ = $(patsubst %.cpp, %.o, $(ALL_SRC))

$(SRC): %.cpp: %_pp.cpp 
        $(PERL) $< > $@

$(OBJ): %.o: %.cpp
        $(CXX) ...

, , . .

+1

Source: https://habr.com/ru/post/1713547/


All Articles