Skip to content

Instantly share code, notes, and snippets.

@reecer
Last active August 22, 2024 04:19
Show Gist options
  • Save reecer/11065346 to your computer and use it in GitHub Desktop.
Save reecer/11065346 to your computer and use it in GitHub Desktop.
A general makefile for general-purpose C projects.
CC=gcc
CCFLAGS=-Wall
LDFLAGS=
SOURCES=$(wildcard *.c)
OBJECTS=$(SOURCES:.c=.o)
TARGET=des
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) -o $@ $^ $(LDFLAGS)
%.o: %.c %.h
$(CC) $(CCFLAGS) -c $<
%.o: %.c
$(CC) $(CCFLAGS) -c $<
clean:
rm -f *.o $(TARGET)
@pattrickrice
Copy link

@MMBC-Chris if there error is the same as below:
Makefile:11: *** missing separator (did you mean TAB instead of 8 spaces?). Stop.
replace the spaces with a tab character

@sampanes
Copy link

Cool, thanks!

@Sasa554
Copy link

Sasa554 commented Aug 22, 2024

CC=gcc
CCFLAGS=-Wall
LDFLAGS=
SOURCES=$(wildcard *.c)
OBJECTS=$(SOURCES:.c=.o)
TARGET=des

all: $(TARGET)

$(TARGET): $(OBJECTS)
$(CC) -o $@ $^ $(LDFLAGS)

%.o: %.c %.h
$(CC) $(CCFLAGS) -c $<

%.o: %.c
$(CC) $(CCFLAGS) -c $<

clean:
rm -f *.o $(TARGET)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment