Make

From Computer Science
Jump to: navigation, search

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