Skip to content

Instantly share code, notes, and snippets.

@mxswd
Created January 31, 2013 10:33
Show Gist options
  • Save mxswd/4682000 to your computer and use it in GitHub Desktop.
Save mxswd/4682000 to your computer and use it in GitHub Desktop.
Example Makefile
# Makefile
# Copyright (c) 2009, Natacha Porté
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
DEPDIR=depends
CFLAGS=-c -g -O3 -Wall -Werror -fPIC
LDFLAGS=-g -O3 -Wall -Werror
CC=gcc
all: libsoldout.a mkd2html
.PHONY: all clean
# libraries
libsoldout.a: markdown.o array.o buffer.o renderers.o
ar rcs $@ $^
# executables
mkd2html: mkd2html.o libsoldout.a
$(CC) $(LDFLAGS) $^ -o $@
# housekeeping
benchmark: benchmark.o libsoldout.a
$(CC) $(LDFLAGS) $^ -o $@
clean:
rm -f *.o
rm -f libsoldout.a
rm -f mkd2html benchmark
rm -rf $(DEPDIR)
# dependencies
include $(wildcard $(DEPDIR)/*.d)
# generic object compilations
%.o: %.c
@mkdir -p $(DEPDIR)
@$(CC) -MM $< > $(DEPDIR)/$*.d
$(CC) $(CFLAGS) -o $@ $<
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment