I wrote a makefile which contains some wildcard target for building and running. My makefile contents are the following.
ALL_EXES=$(shell ls *.exe 2>/dev/null)
.PHONY: all clean $(ALL_EXES) foo
CC=gcc
CFLAGS=-g -Wall
GTKFLAGS=$(shell pkg-config --cflags gtk+-3.0)
GTKLIBS=$(shell pkg-config --libs gtk+-3.0)
PWD=$(shell pwd)
clean:
@echo cleanning
$(shell sh -c "rm *.exe 2>/dev/null")
%: %.c
$(CC) $(GTKFLAGS) -o $@ $< $(GTKLIBS) $(CFLAGS)
%.exe: %
@echo running $@
$(shell sh -c "$(PWD)/$@")
I can run make some-program
successfully, but Nothing to be done for 'some-program.exe' is always occurs when I run make some-program.exe
.
Finally, my workaround makefile is the followings.
ALL_EXES=$(shell ls *.exe 2>/dev/null)
.PHONY: all clean
CC=gcc
CFLAGS=-g -Wall
GTKFLAGS=$(shell pkg-config --cflags gtk+-3.0)
GTKLIBS=$(shell pkg-config --libs gtk+-3.0)
PWD=$(shell pwd)
clean:
@echo cleanning $(shell ls *.exe 2>/dev/null)
$(shell sh -c "rm *.exe 2>/dev/null")
%.exe: %.c
@echo building $<
$(CC) $(GTKFLAGS) -o $@ $< $(GTKLIBS) $(CFLAGS)
run_%.exe: %.exe
@echo running $<
$(PWD)/$<
example-stack.exe: example-stack.c stack.c
$(CC) -I. -o $@ $^ $(CFLAGS)