Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22027

Makefile unexpected behavior after adding targets for build-release and build-debug

$
0
0

Can someone please help me fix the following makefile:

#-----------------------------------------------------------------#EXEC = progCC   = gcc#-----------------------------------------------------------------#.PHONY : default build-release build-debug run-release run-debug run-gdb run-valgrind clean install uninstall helpINC_DIR = ./includeSRC_DIR = ./srcOBJ_DIR = ./buildTST_DIR = ./testCFLAGS   = -Wall -Wextra -pedanticCDEBUG   = -g -DDEBUGCRELEASE = -O3build-release : CFLAGS+=$(CRELEASE)build-release : OBJ_DIR:=$(OBJ_DIR)/releasebuild-release : $(OBJ_DIR)/$(EXEC)build-debug   : CFLAGS+=$(CDEBUG)build-debug   : OBJ_DIR:=$(OBJ_DIR)/debugbuild-debug   : $(OBJ_DIR)/$(EXEC)default : build-release#-----------------------------------------------------------------## --- Linking$(OBJ_DIR)/$(EXEC) : $(OBJ_DIR)/main.o $(OBJ_DIR)/gol.o    $(CC) -o $(OBJ_DIR)/$(EXEC) $(CFLAGS) $(OBJ_DIR)/main.o $(OBJ_DIR)/gol.o# --- Compiling$(OBJ_DIR)/main.o : $(SRC_DIR)/main.c    $(CC) -o $(OBJ_DIR)/main.o $(CFLAGS) -I$(INC_DIR) -c $(SRC_DIR)/main.c$(OBJ_DIR)/gol.o : $(SRC_DIR)/gol.c $(INC_DIR)/gol.h    $(CC) -o $(OBJ_DIR)/gol.o $(CFLAGS) -I$(INC_DIR) -c $(SRC_DIR)/gol.c#-----------------------------------------------------------------## --- Testingunit_test : build/test/unit_test.o build/gol.o    gcc -o build/test/unit_test build/test/unit_test.o build/gol.o $(CFLAGS)build/test/unit_test.o : test/unit_test.c    gcc -o build/test/unit_test.o -c test/unit_test.c $(CFLAGS) -I$(INC_DIR)# --- Other targetsrun-release : build-release    $(OBJ_DIR)/$(EXEC)run-debug : build-debug    $(OBJ_DIR)/$(EXEC)run-test : build-debug    $(TST_DIR)/$(EXEC)run-gdb : build-debug    gdb $(OBJ_DIR)/$(EXEC)run-valgrind : build-debug    valgrind --leak-check=yes --show-reachable=yes --tool=memcheck $(OBJ_DIR)/$(EXEC)install: build-release    @echo "[INSTALL] Copying executable to bin"    cp $(OBJ_DIR)/$(PROG) ~/bin/$(EXEC)uninstall:    @echo "[UNINSTALL] Removing executable from bin"    rm ~/bin/$(EXEC)clean :    echo "[CLEAN] Removing all compiled files"    rm build/release/* build/debug/* build/test/*help :    @printf "Available targets:\n\n"    @printf "\t1. build-release\n"    @printf "\t2. build-debug\n"    @printf "\t3. build-test\n"    @printf "\t4.run-release\n"    @printf "\t5.run-debug\n"    @printf "\t6.run-test\n"    @printf "\t7.run-gdb\n"    @printf "\t8.run-valgrind\n"    @printf "\t9.run-install\n"    @printf "\t10.run-uninstall\n"    @printf "\t11.clean\n"

I am having two issues:

  1. When I run make build-release twice in a row without changing any files, the entire code base is recompiled and relinked.
  2. When I run make run-release the executable is not ran because the OBJ_DIR variable goes back to ./build even though I append to it when build-release target is ran.

Any help would be appreciated.


Viewing all articles
Browse latest Browse all 22027

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>