Skip to content

Instantly share code, notes, and snippets.

@abiiranathan
Created April 4, 2023 15:59
Show Gist options
  • Save abiiranathan/e43dd1540c9c7e2727c70cc7d20dad8b to your computer and use it in GitHub Desktop.
Save abiiranathan/e43dd1540c9c7e2727c70cc7d20dad8b to your computer and use it in GitHub Desktop.
Same make file to simply compile and run C projects.
CC = gcc
CFLAGS = -Wall -Wextra -std=c11 -O2
LDFLAGS = -lcurl -ljansson -ldotenv
SRCDIR = src
OBJDIR = obj
BINDIR = bin
DATADIR = data
SRC = $(wildcard $(SRCDIR)/*.c)
OBJ = $(SRC:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
EXECUTABLE = $(BINDIR)/ghsearch
.PHONY: all clean
all: $(EXECUTABLE)
$(EXECUTABLE): $(OBJ)
$(CC) $^ -o $@ $(LDFLAGS)
$(OBJDIR)/%.o: $(SRCDIR)/%.c | $(OBJDIR) $(BINDIR) $(DATADIR)
$(CC) -c $< -o $@ $(CFLAGS)
$(OBJDIR) $(BINDIR) $(DATADIR):
mkdir -p $@
clean:
rm -rf $(OBJDIR) $(BINDIR)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment