Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'make' does not recompile when source file has been edited

I'm writing a little implementation of Conway's Game of Life in C. The source code is split in three files: main.c and functions.c/functions.h, where I put my functions definitions and declarations.

Now, to create a grid of cell, I have a matrix of this type:

Cell grid[GRID_HEIGHT][GRID_WIDTH];

where GRID_HEIGHT and GRID_WIDTH are constants defined in functions.h:

#define GRID_HEIGHT 10
#define GRID_WIDTH 10

The program runs fine, compiled with make and Makefile. But the problem is: if I try to change GRID_HEIGHT or GRID_WIDTH, when I run again my Makefile it says that all files are up-to-date! I've tried to compile using the good ol' way gcc main.c etc. and it runs as it should. So, why make does not recompile the source?

This is my Makefile:

CC = gcc
OBJECTS = main.o functions.o

Game\ of\ Life : $(OBJECTS)
    $(CC) $(OBJECTS) -o Game\ of\ Life -lncurses

%.o : %.c
    $(CC) -c $< 
like image 630
Lubulos Avatar asked Dec 12 '22 06:12

Lubulos


1 Answers

Because you haven't told it that recompilation depends on functions.h.

Try adding this to your Makefile:

%.o : functions.h

Alternatively, modify your existing rule to be:

%.o : %.c functions.h
    $(CC) -c $< -o $@
like image 192
Oliver Charlesworth Avatar answered Jan 09 '23 14:01

Oliver Charlesworth