Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Makefile: how to avoid specifying all targets manually

I wrote this Makefile:

all: clean basedemo.exe

clean:
  rm -f *.exe

%.exe: %.s
  vasmm68k_mot -kick1hunks -Fhunkexe -o $@ -nosym $<

My goal would be to compile every .s file in the current folder to a separate .exe.

Right now, I have to append the new .exe file name to the line: all: clean basedemo.exe new_file.exe

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Is there a way to avoid having to do that?

Thank you

I tried using a wildcard:

all: clean $(wildcard *.exe)

But when I run make all only the clean recipe runs.

>Solution :

$(wildcard *.exe) searchs for existing .exe files, but they do not exist yet when you run make.

What you can do is to find all .s files and substitute their extension to .exe:

FILES_S:=$(wildcard *.s)
FILES_EXE:=$(FILES_S:%.s=%.exe)

all : clean $(FILES_EXE);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading