#**************************************************************************
#
#	Copyright (c) 2000-2001  ICP Electronics Inc.  All Rights Reserved.
#
#	FILE:
#		Makefile
#
#	Abstract: 
#		Makefile for uLinux utility library.
#
#	Commnet : 
#		Please use root user to make install & testlock
#
#	HISTORY:
#		03/26/01	Louis Tsai Added testlock (use testlock & testlock 
#				commnad to try exclusive lock)
#		03/23/01	Louis Tsai Created
#**************************************************************************

TARGET = libuLinux_Util
CC = $(CROSS_COMPILE)gcc
STRIP = $(CROSS_COMPILE)strip
#CFLAG = -fPIC -Wall -c
#Shone modified to correct model make error
CFLAG = -fPIC -Wall -c -I${KERNEL_PATH}/include
#LIB = -luLinux_config
INCLUDE = -I../uLinux -I../include -I../common
PHASE_ONE_DST_DIR = $(shell pwd)/../.build/usr/lib
#LIB = -L${PHASE_ONE_DST_DIR} -L$(ROOT_PATH)/usr/lib -luLinux_config -luLinux_NAS -luLinux_Storage -luLinux_quota -luLinux_PDC
LIB = -L${PHASE_ONE_DST_DIR} -luLinux_config
#To enable debug message dump, un-comment the following flag
#DEBUGFLAGS = -g -DDEBUG

OBJS = shm_util.o confutil.o mb.o file_lock.o instance.o pic_util.o ../common/nas_lib_common.o

MORE_OBJS = shm_util.o confutil.o mb.o file_lock.o instance.o pic_util.o ../common/nas_lib_common.o ../NAS/user_grp.o ../NAS/share.o ../NAS/security.o ../NAS/nasnfs.o ../NAS/bigcrypt.o ../config/cfg_system.o ../config/cfg_netware.o ../config/cfg_samba.o ../config/cfg_rtrr.o ../config/cfg_printer.o ../config/cfg_misc.o ../config/cfg_appletalk.o ../config/eventlog.o ../config/cfg_snmp.o ../config/msg.o ../config/cfg_ftp.o ../config/cfg_nfs.o ../config/cfg_nic.o ../config/cfg_network.o ../config/sys_update.o ../config/sem.o ../config/cfg_display.o ../config/cfg_fw.o ../config/cfg_webfs.o ../config/ifcfg.o ../config/gw.o ../config/cfg_alert.o ../pdc/naspdc.o ../storage/lvm.o ../storage/lvm_config.o ../storage/volume.o ../storage/nasdisk.o ../storage/disk.o ../storage/raid.o ../storage/interface.o ../quota/quota.o
ifeq ($(MODEL),TS-201)
	MORE_OBJS = shm_util.o confutil.o mb.o file_lock.o instance.o pic_util.o ../common/nas_lib_common.o ../NAS/user_grp.o ../NAS/share.o ../NAS/security.o ../NAS/nasnfs.o ../NAS/bigcrypt.o ../config/cfg_system.o ../config/cfg_netware.o ../config/cfg_samba.o ../config/cfg_rtrr.o ../config/cfg_printer.o ../config/cfg_misc.o ../config/cfg_appletalk.o ../config/eventlog.o ../config/cfg_snmp.o ../config/msg.o ../config/cfg_ftp.o ../config/cfg_nfs.o ../config/cfg_nic.o ../config/cfg_network.o ../config/sys_update.o ../config/sem.o ../config/cfg_display.o ../config/cfg_fw.o ../config/cfg_webfs.o ../config/ifcfg.o ../config/gw.o ../config/cfg_alert.o ../pdc/naspdc.o ../storage_201/lvm.o ../storage_201/lvm_config.o ../storage_201/volume.o ../storage_201/nasdisk.o ../storage_201/disk.o ../storage_201/raid.o ../storage_201/interface.o ../quota/quota.o
endif

all: 	$(OBJS)
	$(CC) $(DEBUGFLAGS) -shared -Wl,-soname,${TARGET}.so.0 -o ${TARGET}.so.0.0 ${OBJS} -lc -lcrypt ${LIB}

phase_one:	$(MORE_OBJS)
	$(CC) $(LFS) $(DEBUG_FLAG) -shared -Wl,-soname,$(TARGET).so.0 -o $(TARGET).so.0.0 $(OBJS) -lc -lcrypt
	[ -d $(PHASE_ONE_DST_DIR) ] || mkdir -p $(PHASE_ONE_DST_DIR)
	mv $(TARGET).so.0.0 $(PHASE_ONE_DST_DIR)
	ln -sf $(TARGET).so.0.0  $(PHASE_ONE_DST_DIR)/$(TARGET).so.0
	ln -sf $(TARGET).so.0  $(PHASE_ONE_DST_DIR)/$(TARGET).so

%.o : %.c 
	$(CC) $(DEBUGFLAGS) $(INCLUDE) $(CFLAG) $< -o $@

test_file_lock:		test_file_lock.c
	$(CC) $(INCLUDE) test_file_lock.c -o test_file_lock -lpthread -luLinux_Util -lc

test:	test.c $(OBJS) 
	rm -f test
	$(CC) $(INCLUDE) $(DEBUGFLAGS) test.c -o test -luLinux_Util -lc

test1:	test1.c test1.o
	rm -f test1
	$(CC) $(DEBUGFLAGS) test1.c -o test1 -luLinux_Util -lc

testlock:	testlock.c $(OBJS) 
	rm -f testlock
	$(CC) $(DEBUGFLAGS) testlock.c -o testlock -luLinux_Util -lc

install:
	$(STRIP) $(TARGET).so.0.0
	install -m 644 $(TARGET).so.0.0 $(TARGET_PREFIX)/usr/lib
	ln -sf $(TARGET).so.0.0  $(TARGET_PREFIX)/usr/lib/$(TARGET).so.0
	ln -sf $(TARGET).so.0  $(TARGET_PREFIX)/usr/lib/$(TARGET).so

clean:
	rm -f *.o 
	rm -f $(TARGET).so.0.0
	rm -f *~
