kusano 7d535a
# Copyright (C) 1996-2008 Markus F.X.J. Oberhumer
kusano 7d535a
#
kusano 7d535a
# this is modelled after build.sh; needs GNU make 3.80 or better
kusano 7d535a
kusano 7d535a
SHELL = /bin/sh
kusano 7d535a
kusano 7d535a
##
kusano 7d535a
## setup flags
kusano 7d535a
##
kusano 7d535a
kusano 7d535a
##top_srcdir ?= ../..
kusano 7d535a
top_srcdir ?= $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))../..
kusano 7d535a
AR ?= ar
kusano 7d535a
CC ?= cc
kusano 7d535a
CFLAGS ?= -O
kusano 7d535a
kusano 7d535a
CFI = -I$(top_srcdir)/include -I$(top_srcdir)
kusano 7d535a
BNAME = lzo2
kusano 7d535a
BLIB = lib$(BNAME).a
kusano 7d535a
kusano 7d535a
CF = $(CPPFLAGS) $(CFI) $(CFLAGS)
kusano 7d535a
LF = $(LDFLAGS) $(LZO_EXTRA_LDFLAGS)
kusano 7d535a
LL = $(BLIB) $(LIBS) $(LZO_EXTRA_LIBS)
kusano 7d535a
kusano 7d535a
kusano 7d535a
##
kusano 7d535a
## setup files
kusano 7d535a
##
kusano 7d535a
kusano 7d535a
__map = $(foreach __map_v,$(2),$(call $(1),$(__map_v)))
kusano 7d535a
__object_filename = $(addsuffix .o,$(basename $(notdir $(1))))
kusano 7d535a
kusano 7d535a
BLIB_SOURCES := $(wildcard $(top_srcdir)/src/*.c)
kusano 7d535a
BLIB_SOURCES += $(LZO_EXTRA_SOURCES)
kusano 7d535a
BLIB_OBJECTS := $(call __map,__object_filename,$(BLIB_SOURCES))
kusano 7d535a
PROGRAMS = dict.out lzopack.out precomp.out precomp2.out simple.out lzotest.out
kusano 7d535a
kusano 7d535a
kusano 7d535a
##
kusano 7d535a
## rules
kusano 7d535a
##
kusano 7d535a
kusano 7d535a
all.targets ?= $(BLIB) $(PROGRAMS) testmini.out
kusano 7d535a
all: $(all.targets)
kusano 7d535a
kusano 7d535a
clean:
kusano 7d535a
	rm -f *.d *.o $(BLIB) $(PROGRAMS) testmini.out
kusano 7d535a
kusano 7d535a
$(BLIB): $(BLIB_OBJECTS) $(LZO_EXTRA_OBJECTS)
kusano 7d535a
	rm -f $@
kusano 7d535a
	$(AR) rcs $@ $^
kusano 7d535a
kusano 7d535a
# dynamically construct object rules
kusano 7d535a
define BLIB_OBJECT_template
kusano 7d535a
    $(call __object_filename,$(1)) : $(1) ; $$(CC) $$(CF) $$(LZO_EXTRA_CPPFLAGS) $$(LZO_EXTRA_CFLAGS) -c $$<
kusano 7d535a
endef
kusano 7d535a
$(foreach s,$(BLIB_SOURCES),$(eval $(call BLIB_OBJECT_template,$(s))))
kusano 7d535a
kusano 7d535a
dict.out: $(top_srcdir)/examples/dict.c
kusano 7d535a
	$(CC) $(CF) $(LF) -o $@ $< $(LL)
kusano 7d535a
lzopack.out: $(top_srcdir)/examples/lzopack.c
kusano 7d535a
	$(CC) $(CF) $(LF) -o $@ $< $(LL)
kusano 7d535a
precomp.out: $(top_srcdir)/examples/precomp.c
kusano 7d535a
	$(CC) $(CF) $(LF) -o $@ $< $(LL)
kusano 7d535a
precomp2.out: $(top_srcdir)/examples/precomp2.c
kusano 7d535a
	$(CC) $(CF) $(LF) -o $@ $< $(LL)
kusano 7d535a
simple.out: $(top_srcdir)/examples/simple.c
kusano 7d535a
	$(CC) $(CF) $(LF) -o $@ $< $(LL)
kusano 7d535a
lzotest.out: $(top_srcdir)/lzotest/lzotest.c
kusano 7d535a
	$(CC) $(CF) $(LF) -o $@ $< $(LL)
kusano 7d535a
kusano 7d535a
testmini.out: $(top_srcdir)/minilzo/testmini.c $(top_srcdir)/minilzo/minilzo.c
kusano 7d535a
	$(CC) $(CF) $(LF) -I$(top_srcdir)/include/lzo -o $@ $^ $(LIBS)
kusano 7d535a
kusano 7d535a
kusano 7d535a
# dependencies
kusano 7d535a
$(PROGRAMS): $(BLIB)
kusano 7d535a
# object dependencies are generated via -MMD
kusano 7d535a
-include *.d
kusano 7d535a
kusano 7d535a
kusano 7d535a
# debug
kusano 7d535a
show_vars:
kusano 7d535a
	@echo "BLIB_SOURCES = $(BLIB_SOURCES)"
kusano 7d535a
	@echo "BLIB_OBJECTS = $(BLIB_OBJECTS)"
kusano 7d535a
	@echo "PROGRAMS = $(PROGRAMS)"
kusano 7d535a
	@echo "LZO_EXTRA_SOURCES = $(LZO_EXTRA_SOURCES)"
kusano 7d535a
	@echo "LZO_EXTRA_OBJECTS = $(LZO_EXTRA_OBJECTS)"
kusano 7d535a
kusano 7d535a
.PHONY: all clean show_vars
kusano 7d535a