Difference between revisions of "Make"

From Computer Science
Jump to: navigation, search
 
Line 14: Line 14:
  
 
%.o : %.c
 
%.o : %.c
        gcc $(CFLAGS) $< -o $@
+
gcc $(CFLAGS) $< -o $@
  
 
clean:
 
clean:
        rm -f *.o
+
rm -f *.o
 
</pre>
 
</pre>
  
Line 26: Line 26:
  
 
hello : hello.c hello.h
 
hello : hello.c hello.h
        gcc  $(CFLAGS) hello.c -o hello.o
+
gcc  $(CFLAGS) hello.c -o hello.o
  
 
clean:
 
clean:
        rm -f *.o
+
rm -f *.o
 
</pre>
 
</pre>

Latest revision as of 10:49, 19 March 2025

This page will be filled in with information about GNU Make. Some places where you can get documentation and information are the following:

The following can be used as a default Makefile for C. This will take all .c files and compile them into .o. You would create a file with the filename Makefile in the directory, and then when you want to compile all of the files you type make in the terminal. If you want to remove all of the .o files you would type make clean in the terminal.

SHELL = /bin/sh
CFLAGS = -g -Wall -O0 -lm
SRCS = $(wildcard *.c)
OBJS = $(SRCS:.c=.o)

all: $(OBJS)

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

clean:
	rm -f *.o

A simpler Makefile to compile hello.c would be something like this

SHELL = /bin/sh
CFLAGS = -g -Wall -O0 -lm

hello : hello.c hello.h
	gcc  $(CFLAGS) hello.c -o hello.o

clean:
	rm -f *.o