Skip to content

Commit

Permalink
Improve Makefile
Browse files Browse the repository at this point in the history
* Remove "-c" from CFLAGS and hard-code it into the recipe -- CFLAGS
  should be overridable from the command-line but not including "-c"
  should never invoke the linker on object files
* Use real target names for library files instead of phony targets
* Add install and install-shared targets
* Use $(OBJECTS) instead of *.o
* Use .PHONY to properly mark phony targets
  • Loading branch information
craigbarnes committed Oct 14, 2012
1 parent 5bd4581 commit a7ddccf
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
CC=g++
CFLAGS=-c -Wall -O2 -fPIC
LDFLAGS= -fPIC
SOURCES = \
constants.cpp context.cpp functions.cpp document.cpp \
document_parser.cpp eval_apply.cpp node.cpp \
node_factory.cpp node_emitters.cpp prelexer.cpp \
sass_interface.cpp
CC = g++
CFLAGS = -Wall -O2 -fPIC
LDFLAGS = -fPIC

PREFIX = /usr/local
LIBDIR = $(PREFIX)/lib

SOURCES = constants.cpp context.cpp functions.cpp document.cpp \
document_parser.cpp eval_apply.cpp node.cpp \
node_factory.cpp node_emitters.cpp prelexer.cpp \
sass_interface.cpp

OBJECTS = $(SOURCES:.cpp=.o)

all: $(OBJECTS)
ar rvs libsass.a $(OBJECTS)
static: libsass.a
shared: libsass.so

libsass.a: $(OBJECTS)
ar rvs $@ $(OBJECTS)

shared: $(OBJECTS)
$(CC) -shared -o libsass.so *.o
libsass.so: $(OBJECTS)
$(CC) -shared $(LDFLAGS) -o $@ $(OBJECTS)

.cpp.o:
$(CC) $(CFLAGS) $< -o $@
$(CC) $(CFLAGS) -c -o $@ $<

install: libsass.a
install -Dpm0755 $< $(DESTDIR)$(LIBDIR)/$<

install-shared: libsass.so
install -Dpm0755 $< $(DESTDIR)$(LIBDIR)/$<

clean:
rm -rf *.o *.a *.so
rm -f $(OBJECTS) *.a *.so


.PHONY: static shared install install-static clean

0 comments on commit a7ddccf

Please sign in to comment.