Last active
August 13, 2018 08:17
-
-
Save yifanz/7161040 to your computer and use it in GitHub Desktop.
Generic Makefile
This file contains hidden or 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
http://stackoverflow.com/questions/7004702/how-can-i-create-a-makefile-for-c-projects-with-src-obj-and-bin-subdirectories | |
# ------------------------------------------------ | |
# Generic Makefile | |
# | |
# Author: [email protected] | |
# Date : 2011-08-10 | |
# | |
# Changelog : | |
# 2010-11-05 - first version | |
# 2011-08-10 - added structure : sources, objects, binaries | |
# thanks to http://stackoverflow.com/users/128940/beta | |
# ------------------------------------------------ | |
# project name (generate executable with this name) | |
TARGET = projectname | |
CC = gcc | |
# compiling flags here | |
CFLAGS = -std=c99 -Wall -I. | |
LINKER = gcc -o | |
# linking flags here | |
LFLAGS = -Wall -I. -lm | |
# change these to set the proper directories where each files shoould be | |
SRCDIR = src | |
OBJDIR = obj | |
BINDIR = bin | |
SOURCES := $(wildcard $(SRCDIR)/*.c) | |
INCLUDES := $(wildcard $(SRCDIR)/*.h) | |
OBJECTS := $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o) | |
rm = rm -f | |
$(BINDIR)/$(TARGET): $(OBJECTS) | |
@$(LINKER) $@ $(LFLAGS) $(OBJECTS) | |
@echo "Linking complete!" | |
$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.c | |
@$(CC) $(CFLAGS) -c $< -o $@ | |
@echo "Compiled "$<" successfully!" | |
.PHONEY: clean | |
clean: | |
@$(rm) $(OBJECTS) | |
@echo "Cleanup complete!" | |
.PHONEY: remove | |
remove: clean | |
@$(rm) $(BINDIR)/$(TARGET) | |
@echo "Executable removed!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment