1

I'm trying to add new feature to the current build. to compile, I've add obj-y += mynewfeature.c into the makefile in the same directory. But i still need to generate or update existing header file using a perl script from the same directory. the problem i can't deal with is how to call this perl script from kbuild file. it seems makefile cannot locate the right path to perl script. So what should I add to top of kbuild file to call this perl script file

Thanks

dir
 |- mynewfeature.c
 |- generator.pl
 |- some_template //perl script will read this file and generate a header file
 |- Makefile

Makefile:
code_to_call_perl_script // how to write this line
obj-y += mynewfeature.o

I've tried Ian's code, perl script not even executed. so is there a way to force a perl execution?

3
  • Did you try $(shell perl_script) to call the script?
    – kurtfu
    Nov 14, 2019 at 8:09
  • @kurtfu Yes, But what bother me is that i dont know how to get right path to file, running this command failed with no such file or directory error
    – X.Z
    Nov 14, 2019 at 10:18
  • What was the exact command that you used to call the script from the Makefile? And are there any other perl scripts? If not, maybe you can use the find command to get the exact path?
    – kurtfu
    Nov 14, 2019 at 10:58

1 Answer 1

2

The Makefile rules should be something like this:

obj-y += mynewfeature.o

# Add dependency: mynewfeature.o depends on generated header mynewheader.h.
# Note: Generated sources go in $(obj).
$(obj)/mynewfeature.o: $(obj)/mynewheader.h

# Add rule to generate the header file mynewheader.h.
# It depends on the script and the template file.
# Note: Generated sources go in $(obj).
$(obj)/mynewheader.h: $(src)/generator.pl $(src)/some_template
    # (I don't know the exact command you use, but here is an example)
    $(PERL) -s $(src)/generator.pl $(src)/some_template > $@

# Allow generated header file to be cleaned by "make clean".
clean-files := mynewheader.h

Reference: Special Rules in Linux Kernel Makefiles in Kernel Build System in The Linux Kernel documentation.

For a concrete example, see the generation of "53c700_d.h" in drivers/scsi/Makefile.

1
  • it seems that $(src) is not pointed to current folder, but its parent folder and out/target folder. is it possible to force makefile executed in current folder? Thanks
    – X.Z
    Nov 15, 2019 at 2:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.