#!/usr/bin/make

KERNEL_DIR=/usr/src/linux

CFLAGS:=-Wall -Wstrict-prototypes -Wno-trigraphs -O2 -s -I. -fno-strict-aliasing -fno-common -fomit-frame-pointer -DINFLATE_C=\"$(KERNEL_DIR)/lib/inflate.c\"
CKERNOPS:=-D__KERNEL__ -DMODULE -fno-builtin -nostdlib -I$(KERNEL_DIR)/include

ifeq ($(shell ls $(KERNEL_DIR)/.config), $(KERNEL_DIR)/.config)
ifndef APPSONLY
include $(KERNEL_DIR)/.config
endif
endif

ifdef CONFIG_MODVERSIONS
MODVERSIONS:= -DMODVERSIONS -include $(KERNEL_DIR)/include/linux/modversions.h
CKERNOPS += $(MODVERSIONS)
endif

# Check for SMP in config and #define __SMP__ if necessary.
# This is ESSENTIAL when compiling a SMP version of cloop.o
# Otherwise, the module will block the entire block buffer management on read.

ifdef CONFIG_SMP
CKERNOPS += -D__SMP__
endif

KERNOBJ:=compressed_loop.o

all: cloop.o utils

# Add compressloop when it has been fixed
utils: create_compressed_fs extract_compressed_fs

cloop.o: compressed_loop.o
	$(LD) -r -o $@ $^

create_compressed_fs: create_compressed_fs.o
	$(CC) -o $@ $< -lz

extract_compressed_fs: extract_compressed_fs.o
	$(CC) -o $@ $< -lz

clean:
	rm -f cloop.o $(KERNOBJ) create_compressed_fs extract_compressed_fs zoom *.o

dist: clean
	cd .. ; \
	tar -cf - cloop/{Makefile,*.[ch],CHANGELOG,README} | \
	bzip2 -9 > $(HOME)/redhat/SOURCES/cloop.tar.bz2

$(KERNOBJ): %.o : %.c
	$(CC) $(CFLAGS) $(CKERNOPS) $< -c -o $@

compressed_loop.o create_compressed_fs.o: compressed_loop.h
