0

Based on this stackoverflow response, I've created a Makefile that compiles all .c files into separate executables. I've added a clean section that removes all programs. It now looks like:

CFLAGS=-Wall -g

SRCS = $(wildcard *.c)

PROGS = $(patsubst %.c,%,$(SRCS))

all: $(PROGS)

clean:
    rm -f $(PROGS)

%: %.c
    $(CC) $(CFLAGS)  -o $@ $<

My questions are:

  1. How would you have Makefile read additional command line arguments so that it can clean just the programs specified?
Community
  • 1
  • 1
antigravityguy
  • 157
  • 1
  • 7
  • 1
    You want `clean` to only clean programs for which the `.c` files are newer than the built binaries? `make ` will build just the program in question. – Etan Reisner Feb 12 '15 at 02:41
  • Changed part of the first question that asks about what you mentioned. Thanks for pointing it out. Would still appreciate an answer to the other question :) – antigravityguy Feb 12 '15 at 02:47

1 Answers1

3

You could add a clean-% target that only cleaned specific binaries or other such games but why? Your "clean" recipe is just rm so just run rm yourself.

As to building only specific binaries just run make $binary instead of make or make all.

All make/make all is doing is running the target for each listed binary by name.

Etan Reisner
  • 77,877
  • 8
  • 106
  • 148
  • the .c part in the question was leftover from earlier. changed it to reflect what I was asking about cleaning binaries. thanks :) – antigravityguy Feb 12 '15 at 02:56