Makefile composed rule not executing defined other rule

eat_a_lemon

Executing make fails because it cannot find the previously defined rule in the make file. Also the "dir" rule only works if I use "make dir" but when I added it to the composed rule it lists the files in the working directory....

make test_tester
dir
base_types.c  dynamic_array.c  gists  hashtable.c  linked_list.c  Makefile  Makefile_OLD  object.c  object_table.c  out.txt  READ_THIS.txt  sstring.c  tester.c  tests  ttime.c
build/test_tester.o
make: build/test_tester.o: Command not found
Makefile:7: recipe for target 'test_tester' failed
make: *** [test_tester] Error 127

CC=gcc
CFLAGS=-Wall -I ../include
TEST_DIR=tests
BUILD_DIR=build

test_tester:
        dir
        $(BUILD_DIR)/test_tester.o
        $(BUILD_DIR)/tester.o
        $(BUILD_DIR)/base_types.o
        $(BUILD_DIR)/object.o
        $(BUILD_DIR)/sstring.o
        $(CC) $(CFLAGS) $(BUILD_DIR)/test_tester.o $(BUILD_DIR)/tester.o $(BUILD_DIR)/base_types.o \ 
        $(BUILD_DIR)/object.o $(BUILD_DIR)/sstring.o

$(BUILD_DIR)/test_tester.o:
        $(CC) $(CFLAGS) -c $(TEST_DIR)/test_tester.c -o $@

$(BUILD_DIR)/tester.o: tester.c
        $(CC) $(CFLAGS) -c tester.c -o $@

$(BUILD_DIR)/base_types.o: base_types.c
        $(CC) $(CFLAGS) -c base_types.c -o $@

$(BUILD_DIR)/object.o: object.c
        $(CC) $(CFLAGS) -c object.c -o $@

$(BUILD_DIR)/sstring.o: sstring.c
        $(CC) $(CFLAGS) -c sstring.c -o $@

dir: mkdir -p $(BUILD_DIR)

.PHONY: clean
clean: 
        rm -f $(BUILD_DIR)/*.o
eat_a_lemon

I figured it out thanks.

CC=gcc
CFLAGS=-Wall -I ../include
TEST_DIR=tests
BUILD_DIR=build

test_tester: dir test_tester.o tester.o base_types.o object.o sstring.o
        $(CC) $(CFLAGS) $(BUILD_DIR)/test_tester.o $(BUILD_DIR)/tester.o $(BUILD_DIR)/base_types.o $(BUILD_DIR)/object.o $(BUILD_DIR)/sstring.o -o $@

test_tester.o:
        $(CC) $(CFLAGS) -c $(TEST_DIR)/test_tester.c -o $(BUILD_DIR)/$@

tester.o: tester.c
        $(CC) $(CFLAGS) -c tester.c -o $(BUILD_DIR)/$@

base_types.o: base_types.c
        $(CC) $(CFLAGS) -c base_types.c -o $(BUILD_DIR)/$@

object.o: object.c
        $(CC) $(CFLAGS) -c object.c -o $(BUILD_DIR)/$@

sstring.o: sstring.c
        $(CC) $(CFLAGS) -c sstring.c -o $(BUILD_DIR)/$@

dir: 
        mkdir -p $(BUILD_DIR)

.PHONY: clean
clean: 
        rm -fr $(BUILD_DIR)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related