Difference between revisions of "Make"

From Computer Science
Jump to: navigation, search
(Created page with "=Make=")
 
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Make=
+
This page will be filled in with information about GNU Make. Some places where you can get documentation and information are the following:
 +
* https://www.gnu.org/software/make/
 +
* https://linux.die.net/man/1/make
 +
* https://www.gnu.org/software/make/manual/html_node/Quick-Reference.html
 +
 
 +
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 <code>make</code> in the terminal. If you want to remove all of the .o files you would type <code>make clean</code> in the terminal.
 +
<pre>
 +
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
 +
</pre>
 +
 
 +
A simpler Makefile to compile hello.c would be something like this
 +
<pre>
 +
SHELL = /bin/sh
 +
CFLAGS = -g -Wall -O0 -lm
 +
 
 +
hello : hello.c hello.h
 +
        gcc  $(CFLAGS) hello.c -o hello.o
 +
 
 +
clean:
 +
        rm -f *.o
 +
</pre>

Latest revision as of 16:29, 31 January 2024

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