- 1 year ago
GNU make directory listing using $(shell dir ) command
In GNU Make, you can use the $(shell ...)
function to execute shell commands and capture their output. To list the contents of a directory using the dir
command, you can use the following syntax:
makefileDIRECTORY := /path/to/directory
list_files:
$(info Directory listing: $(shell dir $(DIRECTORY)))
In this example, the DIRECTORY
variable is set to the path of the directory you want to list. The $(shell dir $(DIRECTORY))
command is executed inside the $(info ...)
function to print the output to the console.
To run this makefile and see the directory listing, you can execute the list_files
target by running make list_files
. Make sure to replace /path/to/directory
with the actual directory path you want to list.
Note that the dir
command is specific to the Windows command prompt (cmd.exe). If you're using a different shell or operating system, you may need to adjust the command accordingly.