include ../Makefile.cosm

SRC_CPUOS = cosmfile.c cosmio.c cosmnet.c cosmtask.c cosmmath.c \
  cosmmem.c cosmgui.c
HEAD_CPUOS = cosmfile.h cosmio.h cosmnet.h cosmtask.h cosmmath.h \
  cosmmem.h cosm.h cputypes.h cosmgui.h
OBJ_CPUOS = $(SRC_CPUOS:.c=.o)

SRC_UTIL = buffer.c email.c log.c config.c security.c cosmtime.c speed.c \
  compress.c bzip2.c language.c cosmtest.c
HEAD_UTIL = buffer.h email.h log.h config.h security.h cosmtime.h speed.h \
  compress.h bzip2.h language.h
OBJ_UTIL = $(SRC_UTIL:.c=.o)

SOURCES = $(SRC_CPUOS) $(SRC_UTIL)
HEADERS = $(HEAD_CPUOS) $(HEAD_UTIL)
OBJECTS = $(OBJ_CPUOS) $(OBJ_UTIL)

BINARIES = testlib.exe

LIBRARIES = libCosmCpuOs.a libCosmUtil.a

all: $(LIBRARIES) $(BINARIES)

libCosmCpuOs.a: $(OBJ_CPUOS)
	$(RM) $@
	$(AR) $@ $(OBJ_CPUOS)
	$(RNLIB) $@

libCosmUtil.a: $(OBJ_CPUOS) $(OBJ_UTIL)
	$(RM) $@
	$(AR) $@ $(OBJ_CPUOS) $(OBJ_UTIL)
	$(RNLIB) $@

testlib.exe: testlib.o $(LIBRARIES) $(HEADERS)
	$(CC) $(LDFLAGS) -o testlib.exe testlib.o libCosmUtil.a $(LDLIBS)
	$(STRIP) testlib.exe

install: $(BINARIES) install-header install-lib

install-header: $(HEADERS) ../Makefile.cosm
	mkdir -p /usr/local/include/cosm/v3
	cp $(HEADERS) /usr/local/include/cosm/v3
	cp ../Makefile.cosm /usr/local/include/cosm/v3
	chmod 664 /usr/local/include/cosm/v3/*

install-lib: $(LIBRARIES)
	mkdir -p /usr/local/lib/cosm/v3
	cp $(LIBRARIES) /usr/local/lib/cosm/v3
	chmod 664 /usr/local/lib/cosm/v3/*

clean:
	-$(RM) $(BINARIES)
	-$(RM) $(LIBRARIES)
	-$(RM) $(OBJECTS) testlib.o

.SUFFIXES:
.SUFFIXES: .c .o .h

.c.o:
	$(CC) -c $< $(CFLAGS) $(CDEFS)

cosmfile.o: cosmfile.c cosmmath.h cputypes.h cosmfile.h cosmtask.h \
  cosmmem.h cosmio.h
cosmio.o: cosmio.c cosmmem.h cputypes.h cosmio.h cosmmath.h cosmfile.h \
  cosmtask.h
cosmnet.o: cosmnet.c cosmmath.h cputypes.h cosmmem.h cosmnet.h \
  cosmtime.h cosmtask.h cosmio.h cosmfile.h
cosmtask.o: cosmtask.c cosmtask.h cputypes.h cosmmath.h cosmfile.h \
  cosmio.h cosmmem.h
cosmmath.o: cosmmath.c cosmmath.h cputypes.h
cosmmem.o: cosmmem.c cputypes.h cosmmem.h cosmmath.h cosmio.h \
  cosmfile.h cosmtask.h
cosmgui.o: cosmgui.c cosmgui.h cputypes.h

buffer.o: buffer.c buffer.h cputypes.h cosmtask.h cosmmath.h cosmmem.h
email.o: email.c email.h cputypes.h cosmnet.h cosmtime.h cosmtask.h \
  cosmmath.h cosmio.h cosmfile.h cosmmem.h
log.o: log.c log.h cputypes.h cosmfile.h cosmtask.h cosmmath.h \
  cosmio.h cosmmem.h
config.o: config.c config.h cputypes.h cosmtask.h cosmmath.h cosmio.h \
  cosmfile.h cosmmem.h
security.o: security.c security.h cputypes.h cosmmem.h cosmtime.h \
  cosmtask.h cosmmath.h cosmfile.h crypto.c
cosmtime.o: cosmtime.c cosmmath.h cputypes.h cosmtask.h cosmtime.h \
  cosmfile.h cosmnet.h
speed.o: speed.c speed.h cputypes.h
compress.o: compress.c compress.h cputypes.h buffer.h cosmtask.h \
  cosmmath.h bzip2.h cosmmem.h
bzip2.o: bzip2.c cosmmem.h cputypes.h cosmmath.h bzip2.h
language.o: language.c language.h cputypes.h cosmfile.h cosmtask.h \
  cosmmath.h
cosmtest.o: cosmtest.c cosm.h cputypes.h cosmfile.h cosmtask.h \
  cosmmath.h cosmio.h cosmmem.h cosmnet.h cosmtime.h buffer.h email.h \
  log.h config.h security.h speed.h compress.h language.h cosmgui.h

testlib.o: testlib.c cosm.h cputypes.h cosmfile.h cosmtask.h \
  cosmmath.h cosmio.h cosmmem.h cosmnet.h cosmtime.h buffer.h email.h \
  log.h config.h security.h speed.h compress.h language.h cosmgui.h

