Last active
April 17, 2020 02:26
-
-
Save thislooksfun/a6390b2ecff44f17cc2053bc4139d230 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ------------------------------------------------ | |
# Generic C Makefile | |
# | |
# Adapted from https://stackoverflow.com/questions/7004702 | |
# ------------------------------------------------ | |
##### START CONFIG ##### | |
### START BASIC CONFIG ### | |
# project name (generate executable with this name) | |
TARGET = assn1 | |
# change these to proper directories where each file should be | |
SRCDIR = src | |
DEPDIR = .dep | |
OBJDIR = .obj | |
BINDIR = bin | |
### END BASIC CONFIG ### | |
### START ADVANCED CONFIG ### | |
CC = gcc | |
CFLAGS = -std=gnu99 -g -Wall -I. | |
LINKER = gcc | |
LFLAGS = -Wall -I. -lm | |
DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.d | |
SOURCES := $(wildcard $(SRCDIR)/*.c) | |
DEPENDS := $(SOURCES:$(SRCDIR)/%.c=$(DEPDIR)/%.d) | |
OBJECTS := $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o) | |
rm = rm -f | |
### END ADVANCED CONFIG ### | |
##### END CONFIG ##### | |
##### BEGIN RULES ##### | |
.PHONY: bin | |
bin: dirs $(BINDIR)/$(TARGET) | |
.PHONY: dirs | |
dirs: | |
@mkdir -p $(DEPDIR) $(OBJDIR) $(BINDIR) | |
$(BINDIR)/$(TARGET): $(OBJECTS) | |
@$(LINKER) $(OBJECTS) $(LFLAGS) -o $@ | |
@echo "Linking complete!" | |
$(OBJDIR)/%.o : $(SRCDIR)/%.c | |
@$(CC) $(CFLAGS) $(DEPFLAGS) -c $< -o $@ | |
@echo "Compiled "$<" successfully!" | |
ifneq ($(MAKECMDGOALS),clean) | |
-include $(DEPENDS) | |
endif | |
.PHONY: clean | |
clean: | |
@$(rm) -r $(OBJDIR) $(DEPDIR) $(BINDIR) | |
@echo "Cleanup complete!" | |
##### END RULES ##### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment