1

I know this is a little bit unusual to do in Makefiles, but I would really like to do it. I would like to make so that if I run the Makefile it opens the program (Already done), but if there is nothing to be done it runs too :/. How can I do that?

Makefile =

#Compiler to use
CC = g++

#LUA STUFF
LUAHOME = /usr/local/Cellar/lua/5.3.2/src

#Boost Paths
BOOST_LIB = /usr/local/Cellar/boost/1.59.0/lib
BOOST_INCLUDE = /usr/local/Cellar/boost/1.59.0/include

#Steam Paths
STEAM_LIB = libs/steam/redistributable_bin/osx32
STEAM_INCLUDE = libs/steam/public/steam 

#Flags for the compiler
LFLAGS = -L$(LUAHOME) -I$(LUAHOME) -llua -L$(STEAM_LIB) -I$(STEAM_INCLUDE) -L$(BOOST_LIB) -I$(BOOST_INCLUDE) -lboost_system -lboost_filesystem -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo -lglew -lglfw3 -w -o Relieved
OFLAGS = -c -Wall

#Name of the Compiled Program
NAME = Relieved

#All CPPs
CPP = main.cpp jelly/lua_manager.cpp jelly/keysManager.cpp 

#Objects
OBJECTS = $(CPP:.cpp=.o)

all: $(CPP) $(NAME)

$(NAME): $(OBJECTS)
    $(CC) $(LFLAGS) $(OBJECTS) -o $@

    ./$(NAME)

.cpp.o:
    $(CC) $(OFLAGS) $< -o $@

clean:
    rm $(OBJECTS) $(NAME)

1 Answers1

2

You're going about it somewhat the wrong way. If there's nothing to be done, then nothing will be done.

Putting the command to run the program inside the binary's build recipe is not helping.

Your goal is to make a target that always needs to be built, and put the run command there. While you could use any non-existent file, the keyword PHONY makes such pseudo-targets more efficient, because then make doesn't even have to check whether the file exists.

all: RUN-IT

.PHONY: RUN-IT

RUN-IT : $(NAME)
# run the program here, remember to use TABs when defining build steps
Ben Voigt
  • 277,958
  • 43
  • 419
  • 720