
# Shared libraries will be installed to this
# direcrory
LIB_DIR = lib


# Name of the crypt library used to encrypt user passwords
LCRIPTLIB =-lcrypt

# Compiler flags used for each program
CC= gcc
CFLAGS= -O2 -Wall -Iinclude

# The CGI programs run by students and teachers will be 
# installed to this directory.
BIN_DIR = ../bin

# The CGI programs run by Manhattan admins will be installed to
# this directory.
SBIN_DIR = ../sbin


IMAGES_DIR = ../images


# Manhattan uses it's own tmp directory for the storage
# of temporary files
TMP_DIR = ../tmp


# The 'users' directory holds subdirectories for each user
# on the system.  
USERS_DIR = ../users

# Adminstrator's accounts are stored here.
ADMIN_DIR = ${USERS_DIR}/admin

# A place to store session files.
KEYS_DIR = ${USERS_DIR}/keys

# Login logs are stored here. 
LOGS_DIR = ${USERS_DIR}/logs

# Actual course data is stored here.
COURSES_DIR = ../courses

# Course templates are Manhattan courses with only one user-
# the teacher.  They are stored here.
TEMPLATES_DIR = ../templates

# The clipboards directory is a holding place for messages that
# the teachers have copied to their clipboard
CLIPBOARDS_DIR = ../clipboards

# The surveys directory holds surveys created by teachers and 
# admins
SURVEYS_DIR = ../surveys

# This Makefile copies a few JavaScript files from this directory
# into the ${IMAGES_DIR}.  There files support the spell check
# capability
SPELLER_DIR = speller


# Location of the source code for the unzip program
UNZIP_DIR = unzip-5.52


# Location of the source code for the zip program
ZIP_DIR = zip-2.3


# Location of the source code for the jpgtn utility
JPGTN_DIR = jpgtn-2.06









#location of the source code for the expat library
EXPAT_DIR = expat

# this is the 'expat' XML parser, generated by source code in the above directory
XML_LIB = libexpat.a



SHARED_LIB_PATH = -L${LIB_DIR} 




#location of the source code for the ClearSilver library
CS_DIR = ClearSilver


#name of installed ClearSilver library

CS_INSTALLED_LIB= ${LIB_DIR}/libneo.so

#name of the ClearSilver shared library
CS_SO_FILE = ${CS_DIR}/dso/libneo.so

#additional compiler flags used to compile programs
# that require ClearSilver
CSFLAGS += -I$(CS_DIR)

#linker option for ClearSilver
CS_LIB = -lneo



SQLITE3_DIR = SQLite3
SQLITE3_INSTALLED_LIB = ${LIB_DIR}/libsqlite3.so
SQLITE3_SO_FILE = ${SQLITE3_DIR}/build/.libs/libsqlite3.so

#sqlite lib 
SQLITE3_LIB =-lsqlite3




# Location of the source code for the "manhattan" library
MANHATLIB_DIR = manhat-lib

# the manhattan library, built from sources in the above directory
MANHAT_LIB = libmanhat.a


# Location of the JavaScript source files used to create bar graphs
# from survey data.  This Makefile will copy these files to the ${IMAGES_DIR}
# directory
SURVEY_JAVASCRIPT_DIR = survey_javascript

# Location of the source code for the melange chat server
MELANGE_DIR = melange/src/server

# Location of the Java code for the melange chat client.  This Makefile
# copies the class files to the ${IMAGES_DIR} directory
MELANGE_CLIENT_DIR = melange/src/client

# Where the melange executable and configuration file is installed
MELANGE_BIN_DIR = ../chat

# Since nearly every program in the system #includes these files,
# they are used as dependencies for all programs.
STANDARD_INCLUDES = global.h  custom.h


TEST_OBJS = sqlite3_test.o hello.o clearsilver_test.o

clean_tests:
	rm -f $(TEST_OBJS)


hello: clean_tests
	${CC} ${CFLAGS} -c $@.c
	${CC} ${CFLAGS}  $@.o  -o $@
	

sqlite3_test: clean_tests
	${CC} ${CFLAGS} -c $@.c
	${CC} ${CFLAGS}  $@.o   ${SQLITE3_LIB} -o $@


clearsilver_test: clean_tests
	${CC} ${CFLAGS}  $(CSFLAGS) -c $@.c
	${CC} ${CFLAGS} $@.o  ${CS_LIB} -o $@

# End-user (teacher and student) programs that make use of the clearsilver library
# The executables will be stored in BIN_DIR
#


CLEARSILVER_PROGS = main_menu doorstep mymanhattan news_topic grades_fac_menu grades_upload_form grades_upload grades_view grades_info gradequick_parser send_img gradequick_upload_form gradequick_view\
	grades_view_form grades_delete_form grades_download admin_download_passwd grades_delete\
	survey_new_form  survey_custom_form survey_memo_form survey_text_form survey_likert_form\
	survey_choice_form survey_manage_teacher_survey survey_www_access_code survey_display_frameset\
	survey_clean_up survey_deliver_form calendar_pick survey_deliver_course_list\
	admin_main_menu admin_list_passwd admin_search_form admin_course_search_form admin_list_students_in_courses\
	admin_del_student_form admin_del_student admin_reset_pass_form admin_chg_form admin_chg_student admin_del_group_students\
	admin_assign_team_form admin_assign_team stats_menu stats_recent_logins stats_ind_calendar stats_calendar_select\
	stats_disk admin_module_form admin_write_config admin_add_student_form logout passwd_form mymanhattan_logout\
	bio_edit_form bio_edit bio_send_photo bio_list chat_close chat_delete chat_enter clipboard_copy\
	clipboard_delete news_filter_set chat_transcript news_new_memo  news_expand_topic\
	news_info survey_new_memo survey_send_mail survey_take_verify survey_info link_new_memo link_send_mail\
	link_visit web_page_back mymanhat_semester_order  web_page_link send_file news_kill spellchecker\
	post_inbox post_delete post_inbox_info post_new_memo post_send_mail post_outbox post_outbox_info\
	hotpot_exam_reset hotpot_exam_release hotpot_exam_release_all assign_student_work\
	news_manage_topic_list news_manage_topic_order news_manage_protect news_manage_sched_form news_manage_topic_hide\
	news_manage_topic_sched post_forward_mail post_send_forward news_mark_hidden news_flag post_mark_hidden\
	web_page.zip check_cookie news_unlock news_team_list hotpotato_record news_read assign_read assign_gather\
	news_members clipboard_view post_inbox_gather post_outbox_gather post_read_inbox post_read_outbox bio_view news_gather\
	exam_util admin_add_course_form show_add_drop lectern_handler podcasting_send_mail podcaster podcast_send_file.mp3\
	podcast_subscribe podcast_launch_framaplayer podcast_frama_playlist wnec_login wnec_redirect apache_group config_test

CLEARSILVER_XML_PROGS = hotpot_exam_present hotpot_exam_score hotpot_exam_check bb_to_hotpot examview_to_hotpot news_send_mail hotpot_exam_verify assign_fac_expand web_page_start admin_get_course_list 


CLEARSILVER_SURVEY_XML_PROGS = survey_title_save survey_new survey_title_modify_form survey_title_modify\
	survey_custom_save survey_custom_modify_form survey_custom_modify\
	survey_delete_tag\
	survey_memo_save survey_memo_modify_form survey_memo_modify\
	survey_text_save survey_text_modify_form survey_text_modify\
	survey_likert_save survey_likert_modify_form survey_likert_modify\
	survey_choice_save survey_choice_modify_form survey_choice_modify\
	survey_read_info survey_page survey_finish_save survey_info_detail\
	survey_delete_survey survey_reuse survey_public_form survey_mymanhattan_bar_graph\
	survey_www_bar_graph survey_mymanhattan_table survey_www_table survey_module_bar_graph survey_module_table\
	survey_www_survey survey_display survey_submit survey_www_submit survey_class_submit\
	survey_deliver baypath_send_survey   

# user programs that use the clearsilver library plus sqlite 
#The executables will be stored in BIN_DIR

CLEARSILVER_SQLITE3_PROGS = grade_book_items grade_book_categories grade_book_final grade_book_release grade_book_export\
	grade_book_final_save grade_book_items_save grade_book_categories_save grade_book_release_save grade_book_cat_members grade_book_letter_grades grade_book_due_date grade_book_enter_grades grade_book_score_log grade_book_std_comment\
	calendar calendar_slot calendar_event_edit calendar_event_detail calendar_event_action calendar_event_modify\
	calendar_system calendar_system_detail 

CLEARSILVER_SQLITE3_MATH_PROGS = grade_book grade_book_std grade_book_std_bar_graph  grade_book_bar_graph grade_book_export_save 

#Super-user (system administrator) programs that use the clearsilver library
#The executables will be stored in SBIN_DIR
#
	
CLEARSILVER_SUPER_CGI_PROGS = super_admin_page super_course_search_form super_delete_course_form super_delete_course_confirm\
	super_config_course_list super_config_course super_chg_crs_access\
	super_group_description super_info_form super_info super_modify_profile_form\
	super_modify_profile super_log_data super_remove super_delete_student super_manwho_cgi super_stat_list\
	super_login_graphs super_server_disk super_lock super_unlock\
	super_delete_stat_log super_clean super_chat super_chat_enter super_chat_close super_chat_kill\
	super_chat_start  super_chat_log super_chat_delete_log super_chat_passwd\
	super_add_admin_form super_del_admin_form super_del_admin super_grant_admin_form super_grant_admin super_grant\
	super_conf  super_doorstep  super_chg_passwd_form super_exit super_check_cookie super_new_course_form\
	super_upload_roster super_upload_xml_roster_form super_upload_xml_roster super_download_tar\
	super_import_course_form super_enter_this_course super_change_course_access_form super_archive_course_form\
	super_wnec_sis_form  super_roster_log_list super_detail_roster_log\
	super_purge_postoffice_message_form super_purge_postoffice_confirm\
	super_analyze_course_group super_list_usage_reports super_view_usage_report super_use_auto_file super_auto_update_form 
	


# A utility to upgrade Manhattan from prior releases
# See the UPGRADE-HOWTO file
#
SCRIPT_PROGS=upgrade_from_2.0




# Super-user (system administrator) programs that use the expat XML parser, in addition
#  clearsilver library.  Executables get stored in SBIN_DIR
#

CLEARSILVER_SUPER_XML_PROGS = super_xml_create_courses super_delete_drop 

# Programs that require the clearsilver library, plus the crypt library used for password encryption
CLEARSILVER_LIB_CRYPT_PROGS = admin_add_group_students admin_add_new_student admin_reset_password admin_add_standalone_student\
	passwd login


CLEARSILVER_XML_CRYPT_PROGS = admin_add_courses


CLEARSILVER_SUPER_CRYPT_PROGS = super_delete_course super_reset_password super_add_admin super_conf_action super_login super_chg_passwd super_capture_login super_purge_postoffice

CLEARSILVER_SUPER_XML_CRYPT_PROGS =  super_xml_course_create super_upload_tar super_update_courses super_auto_add_faculty\
	super_add_new_courses super_do_both baypath_xml_course_create baypath_xml_student_drop


#default target gives instructions on how to install Manhattan
default:
	@echo
	@echo "To install the Manhattan Virtual Classroom, type 'make clean'"
	@echo "then type 'make install'"
	@echo





#target for typical programs that use the clearsilver library

${CLEARSILVER_PROGS}: %: %.c  ${MANHAT_LIB} ${STANDARD_INCLUDES}  #${CS_INSTALLED_LIB}
	${CC} ${CFLAGS} ${CSFLAGS} -c $@.c
	${CC} ${CFLAGS} ${SHARED_LIB_PATH} $@.o ${MANHAT_LIB}  ${CS_LIB} -o $@

${CLEARSILVER_SUPER_CGI_PROGS}: %: %.c  ${MANHAT_LIB} ${STANDARD_INCLUDES} #${CS_INSTALLED_LIB}
	${CC} ${CFLAGS} ${CSFLAGS} -c $@.c
	${CC} ${CFLAGS} ${SHARED_LIB_PATH} $@.o ${MANHAT_LIB}  ${CS_LIB} -o $@


${CLEARSILVER_SQLITE3_PROGS}: %: %.c  ${MANHAT_LIB}  ${STANDARD_INCLUDES} #${CS_INSTALLED_LIB}
	${CC} ${CFLAGS} ${CSFLAGS} -c $@.c
	${CC} ${CFLAGS}    ${SHARED_LIB_PATH} $@.o   ${MANHAT_LIB} ${SQLITE3_LIB}   ${CS_LIB} -o $@

${CLEARSILVER_SQLITE3_MATH_PROGS}: %: %.c  ${MANHAT_LIB}  ${STANDARD_INCLUDES} #${CS_INSTALLED_LIB} 
	${CC} ${CFLAGS} ${CSFLAGS} -c $@.c
	${CC} ${CFLAGS} -lm   ${SHARED_LIB_PATH} $@.o   ${MANHAT_LIB} ${SQLITE3_LIB}     ${CS_LIB} -o $@



#target for programs that use clearsilver, plus the libexpat.a (XML_LIB)
#library for parsing XML

${CLEARSILVER_XML_PROGS}: %: %.c ${MANHAT_LIB} ${XML_LIB} ${STANDARD_INCLUDES} #${CS_INSTALLED_LIB}
	${CC} ${CFLAGS} ${CSFLAGS} -c $@.c
	${CC} ${CFLAGS} ${SHARED_LIB_PATH} $@.o  ${MANHAT_LIB}  ${XML_LIB} ${CS_LIB} -o $@

${CLEARSILVER_SURVEY_XML_PROGS}: %: %.c ${MANHAT_LIB} ${XML_LIB} ${STANDARD_INCLUDES} #${CS_INSTALLED_LIB}
	${CC} ${CFLAGS} ${CSFLAGS} -c $@.c
	${CC} ${CFLAGS} ${SHARED_LIB_PATH} $@.o  ${MANHAT_LIB}  ${XML_LIB} ${CS_LIB} -o $@

${CLEARSILVER_SUPER_XML_PROGS}: %: %.c ${MANHAT_LIB} ${XML_LIB} ${STANDARD_INCLUDES} #${CS_INSTALLED_LIB}
	${CC} ${CFLAGS} ${CSFLAGS} -c $@.c
	${CC} ${CFLAGS} ${SHARED_LIB_PATH} $@.o  ${MANHAT_LIB} ${XML_LIB} ${CS_LIB} -o $@




#target for programs that use the clearsilver library plus the 'crypt' library for password encryption

${CLEARSILVER_LIB_CRYPT_PROGS} : %: %.c  ${MANHAT_LIB}  ${STANDARD_INCLUDES}
	${CC} ${CFLAGS} ${CSFLAGS} -c $@.c
	${CC} ${CFLAGS} ${SHARED_LIB_PATH} $@.o  ${MANHAT_LIB} ${LCRIPTLIB} ${CS_LIB} -o $@

${CLEARSILVER_SUPER_CRYPT_PROGS} : %: %.c  ${MANHAT_LIB}  ${STANDARD_INCLUDES}
	${CC} ${CFLAGS} ${CSFLAGS} -c $@.c
	${CC} ${CFLAGS} ${SHARED_LIB_PATH} $@.o  ${MANHAT_LIB} ${LCRIPTLIB} ${CS_LIB} -o $@
	
# target for programs that use clearsilver plus XML_LIB plus crypt library

${CLEARSILVER_SUPER_XML_CRYPT_PROGS}: %: %.c  ${MANHAT_LIB} ${XML_LIB} ${STANDARD_INCLUDES} 
	${CC} ${CFLAGS} ${CSFLAGS} -c $@.c
	${CC} ${CFLAGS} ${SHARED_LIB_PATH} $@.o   ${MANHAT_LIB} ${XML_LIB} ${LCRIPTLIB} ${CS_LIB} -o $@

${CLEARSILVER_XML_CRYPT_PROGS}: %: %.c  ${MANHAT_LIB} ${XML_LIB} ${STANDARD_INCLUDES} 
	${CC} ${CFLAGS} ${CSFLAGS} -c $@.c
	${CC} ${CFLAGS} ${SHARED_LIB_PATH} $@.o   ${MANHAT_LIB} ${XML_LIB} ${LCRIPTLIB} ${CS_LIB} -o $@
	

#target for a utility to test whether MD5 encryption is available
md5: md5.c
	${CC} ${CFLAGS} -lcrypt  -o md5 md5.c


${MANHAT_LIB}:  ${XML_LIB} #${CS_SO_FILE} 
	@echo
	@echo
	@echo "Building libmanhat.a - a library of Manhattan utility functions ..."
	@echo
	cd ${MANHATLIB_DIR}; make install	
	@echo
	@echo
	@echo
	




${XML_LIB}:
	@echo
	@echo
	@echo "Building James Clark's expat XML parser..."
	@echo
	cd ${EXPAT_DIR}; make xmlparse/libexpat.a


clearsilver ${CS_SO_FILE} : 
	@echo
	@echo
	@echo "Building the Neotonic ClearSilver libraries..."
	@echo
	cd ${CS_DIR}; ./configure --enable-remote-debugger --disable-compression --disable-apache --disable-python --disable-perl --disable-ruby --disable-java --disable-csharp ; make clean;  make; 
	cd ${CS_DIR}/dso ; make
	mkdir -p ${LIB_DIR}
	cp ${CS_SO_FILE} ${LIB_DIR}



sqlite3 ${SQLITE3_INSTALLED_LIB} : 
	@echo
	@echo
	@echo "Building the SQL Lite 3 library ..."
	@echo
	cd ${SQLITE3_DIR} ; mkdir -p build ; cd build ; ../configure ; make 
	mkdir -p ${LIB_DIR}
	cp ${SQLITE3_SO_FILE} ${LIB_DIR}




manhattan: ${CLEARSILVER_PROGS} ${CLEARSILVER_XML_PROGS} ${CLEARSILVER_SURVEY_XML_PROGS} ${CLEARSILVER_SQLITE3_PROGS}  ${CLEARSILVER_SQLITE3_MATH_PROGS} ${CLEARSILVER_SUPER_CGI_PROGS} ${CLEARSILVER_SUPER_XML_PROGS} ${CLEARSILVER_LIB_CRYPT_PROGS} ${CLEARSILVER_SUPER_CRYPT_PROGS} ${CLEARSILVER_SUPER_XML_CRYPT_PROGS} ${CLEARSILVER_XML_CRYPT_PROGS}

all: manhattan melange_chat zip unzip jpgtn


install_manhat:
	@echo
	@echo "Copying executables run by super-users to ${SBIN_DIR}"
	@echo
	mkdir -p ${SBIN_DIR}
	cp -f ${CLEARSILVER_SUPER_CGI_PROGS} ${CLEARSILVER_SUPER_XML_PROGS} ${CLEARSILVER_SUPER_CRYPT_PROGS} ${CLEARSILVER_SUPER_XML_CRYPT_PROGS}  ${SBIN_DIR}
	@echo
	@echo "Copying executables run by students/teachers to ${BIN_DIR}"
	@echo
	mkdir -p ${BIN_DIR}
	cp -f ${CLEARSILVER_PROGS} ${CLEARSILVER_XML_PROGS} ${CLEARSILVER_SURVEY_XML_PROGS} ${CLEARSILVER_LIB_CRYPT_PROGS} ${CLEARSILVER_SQLITE3_MATH_PROGS} ${CLEARSILVER_SQLITE3_PROGS} ${CLEARSILVER_XML_CRYPT_PROGS} ${BIN_DIR}
	cp -f podcast_send_file.mp3 ${BIN_DIR}/podcast_send_file.mov
	cp -f podcast_send_file.mp3 ${BIN_DIR}/podcast_send_file.m4a
	cp -f podcast_send_file.mp3 ${BIN_DIR}/podcast_send_file.mp4
	cp -f podcast_send_file.mp3 ${BIN_DIR}/podcast_send_file.m4v
	cp -f podcast_send_file.mp3 ${BIN_DIR}/podcast_send_file.m4b	
	


install_melange:
	@echo
	@echo "Copying Melange chat server to ${MELANGE_BIN_DIR}"
	@echo
	mkdir -p ${MELANGE_BIN_DIR}
	cp -f ${MELANGE_DIR}/melange ${MELANGE_DIR}/melange.conf ${MELANGE_BIN_DIR}
	@echo


install_images:
	@echo
	@echo "Copying Java, and JavaScript files to ${IMAGES_DIR}"
	@echo
	mkdir -p ${IMAGES_DIR}
	mkdir -p ${IMAGES_DIR}/links
	cp -f ${MELANGE_CLIENT_DIR}/*.class ${MELANGE_CLIENT_DIR}/*.au ${IMAGES_DIR}
	cp -f ${SURVEY_JAVASCRIPT_DIR}/*.gif ${SURVEY_JAVASCRIPT_DIR}/*.jpg ${SURVEY_JAVASCRIPT_DIR}/*.js  ${IMAGES_DIR}
	cp -f ${SPELLER_DIR}/*.* ${IMAGES_DIR}	



install_unzip:
	cp -f ${UNZIP_DIR}/unzip ${BIN_DIR}

install_zip:
	cp -f ${ZIP_DIR}/zip ${BIN_DIR}

install_jpgtn:
	cp -f ${JPGTN_DIR}/src/jpgtn ${BIN_DIR}


strip:
	@echo
	@echo "Stripping executables to make them smaller ..."
	@echo
	strip ${BIN_DIR}/*
	strip ${SBIN_DIR}/*


install_it: install_manhat  install_images install_zip install_unzip install_jpgtn strip install_melange
	@echo
	@echo "Done!"
	@echo



install: all
	make install_it

melange_chat: 
	@echo
	@echo
	@echo "Building the melange chat server..."
	@echo
	cd ${MELANGE_DIR}; make eng




unzip:
	@echo
	@echo
	@echo "Building the unzip utility ..."
	@echo
	cd ${UNZIP_DIR}; make linux



zip:
	@echo
	@echo
	@echo "Building the zip utility ..."
	@echo
	cd ${ZIP_DIR}; make -f unix/Makefile generic




jpgtn:
	@echo
	@echo
	@echo "Building the jpgtn utility used to create thumbnails of photos"
	@echo 
	cd ${JPGTN_DIR};  make -fmakejpgtn 

	



clean:
	rm -f *~
	rm -f ${CLEARSILVER_PROGS} ${CLEARSILVER_XML_PROGS} ${CLEARSILVER_SURVEY_XML_PROGS} ${CLEARSILVER_SQLITE3_PROGS} ${CLEARSILVER_SQLITE3_MATH_PROGS}  ${CLEARSILVER_SUPER_CGI_PROGS} ${CLEARSILVER_SUPER_XML_PROGS} ${CLEARSILVER_LIB_CRYPT_PROGS} ${CLEARSILVER_XML_CRYPT_PROGS} ${CLEARSILVER_SUPER_CRYPT_PROGS} ${CLEARSILVER_SUPER_XML_CRYPT_PROGS} 
	rm -f ${XML_LIB} ${MANHAT_LIB} 
	rm -f xmlparse.h 
	rm -f *.o
	rm -Rf ${CS_DIR} ${SQLITE3_DIR} ${JPGTN_DIR}
	tar -xvzf jpgtn.tgz
	tar -xvzf ClearSilver.tgz
	mkdir -p ${LIB_DIR}
	rm -f ${LIB_DIR}/*.so
	cd ${MELANGE_DIR}; make clean
	cd ${UNZIP_DIR}; make clean
	cd ${ZIP_DIR}; make -f unix/Makefile clean
	cd ${EXPAT_DIR}; make clean
	cd ${MANHATLIB_DIR}; make clean
	cd ${CS_DIR} ; make clean
	cd ${JPGTN_DIR} ; make clean


	






