kusano 7d535a
# Copyright (c) 2015, Louis P. Santillan <lpsantil@gmail.com></lpsantil@gmail.com>
kusano 7d535a
# All rights reserved.
kusano 7d535a
# See LICENSE for licensing details.
kusano 7d535a
DESTDIR ?= /opt/local
kusano 7d535a
kusano 7d535a
# Pulled the code below from lib/Makefile.  Might be nicer to derive this somehow without sed
kusano 7d535a
# Version numbers
kusano 7d535a
VERSION ?= 129
kusano 7d535a
RELEASE ?= r$(VERSION)
kusano 7d535a
LIBVER_MAJOR=$(shell sed -n '/define LZ4_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < lib/lz4.h)
kusano 7d535a
LIBVER_MINOR=$(shell sed -n '/define LZ4_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < lib/lz4.h)
kusano 7d535a
LIBVER_PATCH=$(shell sed -n '/define LZ4_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < lib/lz4.h)
kusano 7d535a
LIBVER=$(LIBVER_MAJOR).$(LIBVER_MINOR).$(LIBVER_PATCH)
kusano 7d535a
kusano 7d535a
######################################################################
kusano 7d535a
kusano 7d535a
CROSS ?= i586-pc-msdosdjgpp
kusano 7d535a
CC = $(CROSS)-gcc
kusano 7d535a
AR = $(CROSS)-ar
kusano 7d535a
LD = $(CROSS)-gcc
kusano 7d535a
kusano 7d535a
CFLAGS ?= -O3 -std=gnu99 -Wall -Wextra -Wundef -Wshadow -Wcast-qual -Wcast-align -Wstrict-prototypes -pedantic -DLZ4_VERSION=\"$(RELEASE)\"
kusano 7d535a
LDFLAGS ?= -s
kusano 7d535a
SRC = programs/bench.c programs/lz4io.c programs/lz4cli.c
kusano 7d535a
OBJ = $(SRC:.c=.o)
kusano 7d535a
SDEPS = $(SRC:.c=.d)
kusano 7d535a
IDIR = lib
kusano 7d535a
EDIR = .
kusano 7d535a
EXE = lz4.exe
kusano 7d535a
LNK = lz4
kusano 7d535a
LDIR = lib
kusano 7d535a
LSRC = lib/lz4.c lib/lz4hc.c lib/lz4frame.c lib/xxhash.c
kusano 7d535a
INC = $(LSRC:.c=.h)
kusano 7d535a
LOBJ = $(LSRC:.c=.o)
kusano 7d535a
LSDEPS = $(LSRC:.c=.d)
kusano 7d535a
LIB = $(LDIR)/lib$(LNK).a
kusano 7d535a
kusano 7d535a
# Since LDFLAGS defaults to "-s", probably better to override unless
kusano 7d535a
# you have a default you would like to maintain
kusano 7d535a
ifeq ($(WITH_DEBUG), 1)
kusano 7d535a
	CFLAGS += -g
kusano 7d535a
	LDFLAGS += -g
kusano 7d535a
endif
kusano 7d535a
kusano 7d535a
# Since LDFLAGS defaults to "-s", probably better to override unless
kusano 7d535a
# you have a default you would like to maintain
kusano 7d535a
ifeq ($(WITH_PROFILING), 1)
kusano 7d535a
	CFLAGS += -pg
kusano 7d535a
	LDFLAGS += -pg
kusano 7d535a
endif
kusano 7d535a
kusano 7d535a
%.o: %.c $(INC) Makefile
kusano 7d535a
	$(CC) $(CFLAGS) -MMD -MP -I$(IDIR) -c $< -o $@
kusano 7d535a
kusano 7d535a
%.exe: %.o $(LIB) Makefile
kusano 7d535a
	$(LD) $< -L$(LDIR) -l$(LNK) $(LDFLAGS) $(LIBDEP) -o $@
kusano 7d535a
kusano 7d535a
######################################################################
kusano 7d535a
######################## DO NOT MODIFY BELOW #########################
kusano 7d535a
######################################################################
kusano 7d535a
kusano 7d535a
.PHONY: all install uninstall showconfig gstat gpush
kusano 7d535a
kusano 7d535a
all: $(LIB) $(EXE)
kusano 7d535a
kusano 7d535a
$(LIB): $(LOBJ)
kusano 7d535a
	$(AR) -rcs $@ $^
kusano 7d535a
kusano 7d535a
$(EXE): $(LOBJ) $(OBJ)
kusano 7d535a
	$(LD) $(LDFLAGS) $(LOBJ) $(OBJ) -o $(EDIR)/$@
kusano 7d535a
kusano 7d535a
clean:
kusano 7d535a
	rm -f $(OBJ) $(EXE) $(LOBJ) $(LIB) *.tmp $(SDEPS) $(LSDEPS) $(TSDEPS)
kusano 7d535a
kusano 7d535a
install: $(INC) $(LIB) $(EXE)
kusano 7d535a
	mkdir -p $(DESTDIR)/bin $(DESTDIR)/include $(DESTDIR)/lib
kusano 7d535a
	rm -f .footprint
kusano 7d535a
	echo $(DESTDIR)/bin/$(EXE) >> .footprint
kusano 7d535a
	cp -v $(EXE) $(DESTDIR)/bin/
kusano 7d535a
	@for T in $(LIB); \
kusano 7d535a
	do ( \
kusano 7d535a
		echo $(DESTDIR)/$$T >> .footprint; \
kusano 7d535a
		cp -v --parents $$T $(DESTDIR) \
kusano 7d535a
	); done
kusano 7d535a
	@for T in $(INC); \
kusano 7d535a
	do ( \
kusano 7d535a
		echo $(DESTDIR)/include/`basename -a $$T` >> .footprint; \
kusano 7d535a
		cp -v $$T $(DESTDIR)/include/ \
kusano 7d535a
	); done
kusano 7d535a
kusano 7d535a
uninstall: .footprint
kusano 7d535a
	@for T in $(shell cat .footprint); do rm -v $$T; done
kusano 7d535a
kusano 7d535a
-include $(SDEPS) $(LSDEPS)
kusano 7d535a
kusano 7d535a
showconfig:
kusano 7d535a
	@echo "PWD="$(PWD)
kusano 7d535a
	@echo "VERSION="$(VERSION)
kusano 7d535a
	@echo "RELEASE="$(RELEASE)
kusano 7d535a
	@echo "LIBVER_MAJOR="$(LIBVER_MAJOR)
kusano 7d535a
	@echo "LIBVER_MINOR="$(LIBVER_MINOR)
kusano 7d535a
	@echo "LIBVER_PATCH="$(LIBVER_PATCH)
kusano 7d535a
	@echo "LIBVER="$(LIBVER)
kusano 7d535a
	@echo "CROSS="$(CROSS)
kusano 7d535a
	@echo "CC="$(CC)
kusano 7d535a
	@echo "AR="$(AR)
kusano 7d535a
	@echo "LD="$(LD)
kusano 7d535a
	@echo "DESTDIR="$(DESTDIR)
kusano 7d535a
	@echo "CFLAGS="$(CFLAGS)
kusano 7d535a
	@echo "LDFLAGS="$(LDFLAGS)
kusano 7d535a
	@echo "SRC="$(SRC)
kusano 7d535a
	@echo "OBJ="$(OBJ)
kusano 7d535a
	@echo "IDIR="$(IDIR)
kusano 7d535a
	@echo "INC="$(INC)
kusano 7d535a
	@echo "EDIR="$(EDIR)
kusano 7d535a
	@echo "EXE="$(EXE)
kusano 7d535a
	@echo "LDIR="$(LDIR)
kusano 7d535a
	@echo "LSRC="$(LSRC)
kusano 7d535a
	@echo "LOBJ="$(LOBJ)
kusano 7d535a
	@echo "LNK="$(LNK)
kusano 7d535a
	@echo "LIB="$(LIB)
kusano 7d535a
	@echo "SDEPS="$(SDEPS)
kusano 7d535a
	@echo "LSDEPS="$(LSDEPS)
kusano 7d535a
kusano 7d535a
gstat:
kusano 7d535a
	git status
kusano 7d535a
kusano 7d535a
gpush:
kusano 7d535a
	git commit
kusano 7d535a
	git push