###############################################################################
# Variable definitions for targets to build
###############################################################################
#___INFO__MARK_BEGIN__
##########################################################################
#
#  The Contents of this file are made available subject to the terms of
#  the Sun Industry Standards Source License Version 1.2
#
#  Sun Microsystems Inc., March, 2001
#
#
#  Sun Industry Standards Source License Version 1.2
#  =================================================
#  The contents of this file are subject to the Sun Industry Standards
#  Source License Version 1.2 (the "License"); You may not use this file
#  except in compliance with the License. You may obtain a copy of the
#  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
#
#  Software provided under this License is provided on an "AS IS" basis,
#  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
#  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
#  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
#  See the License for the specific provisions governing your rights and
#  obligations concerning the Software.
#
#  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
#
#  Copyright: 2001 by Sun Microsystems, Inc.
#
#  All Rights Reserved.
#
##########################################################################
#___INFO__MARK_END__
SPOOLCLIB_DIR = $(SDIR)/libs/spool/flatfile

SPOOLCLIB = libspoolc$(LIBEXT)

SPOOLCLIB_SRC = \
         sge_flatfile.c \
         sge_flatfile_obj.c \
         sge_spooling_flatfile.c \
         sge_spooling_flatfile_scanner.c

SPOOLCLIB_OBJS = $(SPOOLCLIB_SRC:.c=.o)

SPOOLCLIB_ADD_SRC = \
         read_write_job.c 

SPOOLCLIB_TEST_PROGS_OBJ = \
         test_sge_spooling_flatfile.o \
         test_flatfile_spool.o \

SPOOLCLIB_TEST_PROGS = \
         test_sge_spooling_flatfile \
         test_flatfile_spool

SPOOLCLIB_ADD_OBJS = $(SPOOLCLIB_ADD_SRC:.c=.o)

###############################################################################
# global rules: all, clean, depend, messages
###############################################################################
spoolclib: $(SPOOLCLIB) $(SPOOLCLIB_TEST_PROGS)

spoolclib_clean:
		$(RM) $(SPOOLCLIB_OBJS) libspoolc.a libspoolc$(SHAREDEXT) $(SPOOLCLIB_TEST_PROGS) \
             $(SPOOLCLIB_TEST_PROGS_OBJ) 

spoolclib_depend:
		$(DEPEND) -f$(SPOOLCLIB_DIR)/spoolc_dependencies $(SPOOLCLIB_DIR)/*.c

spoolclib_messages:
	@echo Creating $@
	@for i in `ls $(SPOOLCLIB_DIR)/*.c`; do \
	   $(CC) $(CFLAGS) -DEXTRACT_MESSAGES -E $$i | $(XGETTEXT) - ;\
	done

###############################################################################
# rules to build library
###############################################################################
libspoolc.a:	$(SPOOLCLIB_OBJS) $(SPOOLCLIB_ADD_OBJS)
	$(AR) $(ARFLAGS) libspoolc.a $(SPOOLCLIB_OBJS) $(SPOOLCLIB_ADD_OBJS)
	$(RANLIB) libspoolc.a \
   && ../scripts/nonreentrant.sh -a `../dist/util/arch` -w $@

libspoolc$(SHAREDEXT): $(SPOOLCLIB_OBJS) $(SPOOLCLIB_ADD_OBJS) $(SPOOLLIB) $(SCHEDLIB) $(SGEOBJLIB) $(SGEOBJDLIB) $(COMMLIB) $(COMMLISTSLIB) $(CULLLIB) $(UTILIB)
	$(SHAREDLD) $(SHARED_LFLAGS) -o libspoolc$(SHAREDEXT) $(SPOOLCLIB_OBJS) $(SPOOLCLIB_ADD_OBJS) -lspool -lsched -lsgeobj -lsgeobjd -lcomm -lcull -luti $(LIBS) -lcommlists $(SECLIB) \
   && ../scripts/nonreentrant.sh -a `../dist/util/arch` -w $@

###############################################################################
# include dependencies for object files generated by sge_depend
###############################################################################
include $(SPOOLCLIB_DIR)/spoolc_dependencies

###############################################################################
# rules to build object codes
###############################################################################
sge_spooling_flatfile.o: $(SPOOLCLIB_DIR)/sge_spooling_flatfile.c 
		$(CC) $(CFLAGS) $(SHARED_CFLAGS) -c $(SPOOLCLIB_DIR)/sge_spooling_flatfile.c

sge_flatfile.o: $(SPOOLCLIB_DIR)/sge_flatfile.c 
		$(CC) $(CFLAGS) $(SHARED_CFLAGS) -c $(SPOOLCLIB_DIR)/sge_flatfile.c

sge_flatfile_obj.o: $(SPOOLCLIB_DIR)/sge_flatfile_obj.c 
		$(CC) $(CFLAGS) $(SHARED_CFLAGS) -c $(SPOOLCLIB_DIR)/sge_flatfile_obj.c

# do not automatically rebuild the scanner c code
$(SPOOLCLIB_DIR)/sge_spooling_flatfile_scanner.c: $(SPOOLCLIB_DIR)/sge_spooling_flatfile_scanner.l $(SPOOLCLIB_DIR)/sge_spooling_flatfile_scanner.h
		echo "to rebuild the scanner c file call ./aimk -only-core flatfile_scanner" ;\
      touch $(SPOOLCLIB_DIR)/sge_spooling_flatfile_scanner.c

flatfile_scanner: $(SPOOLCLIB_DIR)/sge_spooling_flatfile_scanner.l $(SPOOLCLIB_DIR)/sge_spooling_flatfile_scanner.h
		$(LEX) $(LEXFLAGS) -fi8 -Pspool_ -o$(SPOOLCLIB_DIR)/sge_spooling_flatfile_scanner.c $(SPOOLCLIB_DIR)/sge_spooling_flatfile_scanner.l

sge_spooling_flatfile_scanner.o: $(SPOOLCLIB_DIR)/sge_spooling_flatfile_scanner.c $(SPOOLCLIB_DIR)/sge_spooling_flatfile.h
		$(CC) $(CFLAGS) $(SHARED_CFLAGS) $(NOERR_CFLAG) -c $(SPOOLCLIB_DIR)/sge_spooling_flatfile_scanner.c

#---------------------------------------------------------------------
# test programs
test_sge_spooling_flatfile: test_sge_spooling_flatfile.o sge_mt_init.o $(SPOOLLIB) $(GDILIB) $(SCHEDLIB) $(CULLLIB) $(COMMLIB) $(COMMLISTSLIB) $(SGEOBJLIB) $(COMMLIB) $(UTILIB) $(WINGRIDLIB_DEP)
	$(CC) $(CFLAGS) -o test_sge_spooling_flatfile $(LFLAGS) test_sge_spooling_flatfile.o sge_mt_init.o $(SPOOLCLIB) $(SPOOLLIB) $(COMMLIB) $(SCHEDLIB) $(GDILIB) $(SGEOBJLIB) $(SGEOBJDLIB) $(CULLLIB) $(COMMLIB) $(COMMLISTSLIB) $(UTILIB) $(WINGRIDLIB) $(SECLIB) $(DLLIB) $(SLIBS) $(LIBS) 

test_sge_spooling_flatfile.o: $(SPOOLCLIB_DIR)/test_sge_spooling_flatfile.c
	$(CC) $(CFLAGS) -c $(SPOOLCLIB_DIR)/test_sge_spooling_flatfile.c

test_flatfile_spool: test_flatfile_spool.o sig_handlers.o sge_mt_init.o $(SPOOLLIB) $(SPOOLCLIB) $(SCHEDLIB) $(SGEOBJLIB) \
                        $(SGEOBJDLIB) $(GDILIB) $(CULLLIB) $(COMMLIB) $(COMMLISTSLIB) \
                        $(UTILIB) $(WINGRIDLIB_DEP)
	$(CC) $(CFLAGS) -o test_flatfile_spool $(LFLAGS) test_flatfile_spool.o sge_mt_init.o sig_handlers.o $(SPOOLCLIB) \
                         $(SPOOLLIB) $(SCHEDLIB) $(GDILIB) $(SGEOBJLIB) $(SGEOBJDLIB) \
                         $(CULLLIB) $(COMMLIB) $(COMMLISTSLIB) \
                         $(UTILIB) $(WINGRIDLIB) $(LIBS) $(SECLIB) $(SLIBS) $(DLLIB) 

test_flatfile_spool.o: $(SPOOLCLIB_DIR)/test_flatfile_spool.c
	$(CC) $(CFLAGS) -c $(SPOOLCLIB_DIR)/test_flatfile_spool.c
