#!/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 ($(ARCH),um)
  CKERNOPS+=-I$(KERNEL_DIR)/arch/um/include -I$(KERNEL_DIR)/arch/um/kernel/tt/include -I$(KERNEL_DIR)/arch/um/kernel/skas/include
endif
LDFLAGS=-lz

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: compressloop create_compressed_fs extract_compressed_fs

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

clean:
	rm -f cloop.o $(KERNOBJ) compressloop 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 $@
%.s: %.c
	$(CC) -g $(CFLAGS) $(CKERNOPS) $< -S -o $@

compressed_loop.o create_compressed_fs.o extract_compressed_fs.o compressloop.o: compressed_loop.h
