alex
alex

Reputation: 1439

Just make again that file which I changed

I have a program on ubuntu, my program is consisted of a lot of C files, also when I make the program, it is so time tackle. But the problem is, every time I just change a bit of one specific file from those and every time I should write make on terminal and the gcc start to make again all files. Is there any way to tell gcc please make that file which I change ?

Upvotes: 0

Views: 78

Answers (1)

danish
danish

Reputation: 359

Make file are meant for this purpose. Write a proper makefile,include dependencies and every time your run it only change files will be compiled/linked.

C_SRCS := $(shell find $(SRC_DIR) -type f -name "*.c") #finds all C source file or you can explicitly give the names here
C_OBJS := $(C_SRCS:.c=.o) #lists all the obj files
CFLAGS := -c #required CFLAGS
CC := #path to your c compiler

$(C_OBJS): %.o : %.c
   $(CC) $(CFLAGS) -c $< -o $@

all:$(C_OBJS)
    echo done

So every time you run make all or make all keyword will be triggered and it has a dependency on C_OBJS, so if last changed timestamp of last obj file is less than that of source file then those source files will be re-compiled.

Upvotes: 2

Related Questions