Created
May 3, 2019 14:36
-
-
Save xiangchu0/2024c733a9dc9c0076842ff2a7a2a477 to your computer and use it in GitHub Desktop.
makefile template
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
| # ------------------------------------------------ | |
| # Generic Makefile | |
| # | |
| # Author: yanick.rochon@gmail.com | |
| # 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 | |
| # 2017-04-24 - changed order of linker params | |
| # ------------------------------------------------ | |
| # project name (generate executable with this name) | |
| TARGET = projectname | |
| CC = gcc | |
| # compiling flags here | |
| CFLAGS = -std=c99 -Wall -I. | |
| LINKER = gcc | |
| # linking flags here | |
| LFLAGS = -Wall -I. -lm | |
| # change these to proper directories where each file should 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) $(OBJECTS) $(LFLAGS) -o $@ | |
| @echo "Linking complete!" | |
| $(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.c | |
| @$(CC) $(CFLAGS) -c $< -o $@ | |
| @echo "Compiled "$<" successfully!" | |
| .PHONY: clean | |
| clean: | |
| @$(rm) $(OBJECTS) | |
| @echo "Cleanup complete!" | |
| .PHONY: 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