# This is the standalone Makefile for texttopdf.
# For integration with cups, just use Makefile.cups instead
# of the one provided with cups

SOURCES=texttopdf.c pdfutils.c common.c textcommon.c
EXEC=texttopdf

CPPFLAGS=-O3 -march=pentium -funroll-all-loops -finline-functions -Wall -g
LDFLAGS=-Lfontembed -lfontembed
CPPFLAGS+=
LDFLAGS+=/usr/lib/libcups.so.2

OBJECTS=$(patsubst %.c,$(PREFIX)%$(SUFFIX).o,\
        $(patsubst %.cpp,$(PREFIX)%$(SUFFIX).o,\
$(SOURCES)))
DEPENDS=$(patsubst %.c,$(PREFIX)%$(SUFFIX).d,\
        $(patsubst %.cpp,$(PREFIX)%$(SUFFIX).d,\
        $(filter-out %.o,""\
$(SOURCES))))

all: $(EXEC)
test: test_pdf1 test_pdf2
ifneq "$(MAKECMDGOALS)" "clean"
  -include $(DEPENDS)
endif 

clean:
	rm -f $(EXEC) $(LIB) $(OBJECTS) $(DEPENDS) 

%.d: %.c
	@$(SHELL) -ec '$(CXX) -MM $(CPPFLAGS) $< \
                      | sed '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@;\
                      [ -s $@ ] || rm -f $@'

%.d: %.cpp
	@$(SHELL) -ec '$(CXX) -MM $(CPPFLAGS) $< \
                      | sed '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@;\
                      [ -s $@ ] || rm -f $@'

pdfutils.o: fontembed/libfontembed.a

fontembed/libfontembed.a:
	$(MAKE) -C fontembed

$(EXEC): $(OBJECTS)
	$(CC) -o $@ $^ $(LDFLAGS)

test_pdf1: test_pdf1.c pdfutils.o 
	$(CC) -o $@ $^ $(LDFLAGS)

test_pdf2: test_pdf2.c pdfutils.o
	$(CC) -o $@ $^ $(LDFLAGS)

