Skip to content

Instantly share code, notes, and snippets.

@yowcow
Created June 11, 2016 08:29
Show Gist options
  • Save yowcow/49c7e362ba6914dc7ed5ae0ee92d27ad to your computer and use it in GitHub Desktop.
Save yowcow/49c7e362ba6914dc7ed5ae0ee92d27ad to your computer and use it in GitHub Desktop.
Makefile example for C
.PHONY: clean test nm
CFLAGS=-Wall -Werror -O3 -I. -fPIC
all: build/libexample.so build/libexample.a nm
build:
-mkdir -p build
build/libexample.so: build/example.o
$(CC) $(CFLAGS) -shared build/example.o -o $@
build/libexample.a: build/example.o
ar -r $@ build/example.o
build/example.o: build example.c
$(CC) $(CFLAGS) -c example.c -o $@
nm: build/libexample.a
nm build/libexample.a
clean:
-rm -rf build
test: build/example-test
./build/example-test
perl6 example-test.p6
build/example-test: build/example.o build/example-test.o
$(CC) $(CFLAGS) build/libexample.a build/example-test.o -o $@
build/example-test.o: build example-test.c
$(CC) $(CFLAGS) -c example-test.c -o $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment