# File: makefile_SOLARIS
# Why:  Creates the o2linker compaion to o2 compiler /compiler
# Library placement: 
#   Rlse:   /usr/local/yacco2/bin/o2linker
#   Dbg:    /usr/local/yacco2/bin/o2linker_debug
#   Genw:   for the pdf file: yacco2/docs
#           for the *.cpp files
#
# How to run: U must choose the label to execute: Rlse, Dbg
#   Rlse --- gen the fast version of library with no debug support
#   Dbg --- gen the debug version of library
#   Genw --- gen the pdf document and the cpp code 
#            from cweb see www.tug.org for details on obtaining code
#            for the literate programming environment aka CWEB
#            and please join Tug. It is a marvalous FOSS
#            Note: U do not need to use Genw as *.cpp and pdf 
#                  document are included in the ``yacco2'' package
# Notice: Some possible construction to be done
#  1) Adjust base_dir variable if the ``yacco2'' package is moved elsewhere. 
#     For example, if u installed the ``yacco2'' package in /opt/yacco2
#       Set the base_dir variable in this file to: base_dir = /opt/
#       The trailing / must be there or ugly things will happen.
#
#  2) Make sure u know where the ``ranlib'' utility resides on your system
#     If it's already defined in your ``bash'' ``PATH'' varable then 
#     just space out the below ``RANLIB'' variable
#     RANLIB =
#     or set it to point to its residence as what this file has done
#
# Example: gen the debug version of the library
#  cd /usr/local/yacco2/compiler/grammars
#  make Dbg -f Solaris_makefile
#

o2_eternals :=$(O2)/externals/
o2_docs := $(O2)/docs/
o2_lib = $(O2)/library/
o2_lib_grms := $(O2)/library/grammars/
o2_grms := $(O2)/compiler/grammars/
o2linker := $(O2)/o2linker/
O2_includes :=  -I'$(o2)' -I'$(o2_grms)' -I'$(o2_lib)' -I'$(o2_lib_grms)'
o2_req_libraries := -lyacco2 -lo2grammars 

files_to_cc := \
$(o2linker)o2linker_defs.cpp \
$(o2linker)common_externs.cpp \
$(o2linker)o2linker_externs.cpp \
$(o2linker)o2linker.cpp
files_to_o := $(files_to_cc:.cpp=.o) 
 
Rlse: BASICOPTS := -c -fast -m64  -lpthread
Rlse: Bld_BASICOPTS := -m64 -lpthread -xs 
Rlse: o2_lib_directories := -L $(o2_grms)lib/Release/ -L $(o2_lib)lib/Release/ 

Dbg: BASICOPTS := -c -m64 -lpthread -g 
Dbg: Bld_BASICOPTS := -m64 -lpthread -xs -g
Dbg: o2_lib_directories := -L $(o2_grms)lib/Debug/ -L $(o2_lib)lib/Debug/

Rlse: Compile Rlse_o2
Rlse := BASICOPTS = -c -fast -m64  -mt -lpthread 
Rlse := Bld_BASICOPTS = -fast -m64  -mt -lpthread
Rlse := o2_lib_directories = -L $(o2_grms)lib/Release/ -L $(o2_lib)lib/Release/ 
Rlse_o2:
	mv o2linker $(base_dir)yacco2/bin/o2linker
	rm -f *.o

Dbg: $(files_to_o) Dbg_o2
Dbg := BASICOPTS = -c -m64 -mt -lpthread -xs -g 	
Dbg := Bld_BASICOPTS = -m64 -mt -lpthread -xs -g
Dbg := o2_lib_directories = -L $(o2_grms)lib/Debug/ -L $(o2_lib)lib/Debug/
Dbg_o2:
	mv o2linker $(base_dir)yacco2/bin/o2linker_debug
	rm -f *.o

Compile: $(files_to_o)
$(o2linker)common_externs.o: $(o2)common_externs.cpp
	CC $(BASICOPTS) $(O2_includes) $(o2)common_externs.cpp -o $@  
$(o2linker)o2linker_externs.o: $(o2)o2linker_externs.cpp
	CC $(BASICOPTS) $(O2_includes)  $(o2)o2linker_externs.cpp -o $@
$(o2linker)o2linker_defs.o: $(o2)o2linker_defs.cpp
	CC $(BASICOPTS) $(O2_includes) $(o2)o2linker_defs.cpp -o $@ 
$(o2linker)o2linker.o: $(o2)o2linker.cpp
	CC $(Bld_BASICOPTS) $(O2_includes) $(o2)o2linker.cpp -o o2linker \
$(o2linker)o2linker_defs.o $(o2)common_externs.o $(o2)o2linker_externs.o \
$(o2_lib_directories) $(o2_req_libraries)
Genw:
	cweave types.w
	ctangle -l +e types.w
	pdftex types
	mv types.pdf $(o2_docs)
	cweave $(o2_eternals)common_externs.w
	ctangle -l +e $(o2_eternals)common_externs.w
	pdftex common_externs
	mv common_externs.pdf $(o2_docs)
	cweave o2linker_externs.w
	ctangle -l +e o2linker_externs.w
	pdftex o2linker_externs
	pdftops o2linker_externs.pdf
	mv o2linker_externs.pdf $(o2_docs)
	mv o2linker_externs.ps $(o2_docs)
	cweave o2linker.w
	ctangle -l +e o2linker.w
	sh Makefile_Edit_cweb
	pdftex o2linker
	pdftops o2linker.pdf
	mv o2linker.pdf $(o2_docs)
	mv o2linker.ps $(o2_docs)
	cweave o2linker_doc.w
	pdftex o2linker_doc
	pdftops o2linker_doc.pdf
	mv o2linker_doc.pdf $(o2_docs)
	mv o2linker_doc.ps $(o2_docs)
	rm types.idx
	rm types.scn
	rm types.toc
	rm types.tex
	rm types.log
	rm types.c
	rm common_externs.idx
	rm common_externs.scn
	rm common_externs.toc
	rm common_externs.tex
	rm common_externs.log
	rm common_externs.c
	rm o2linker_externs.idx
	rm o2linker_externs.scn
	rm o2linker_externs.toc
	rm o2linker_externs.tex
	rm o2linker_externs.log
	rm o2linker_externs.c
	rm o2linker.idx
	rm o2linker.scn
	rm o2linker.toc
	rm o2linker.tex
	rm o2linker.log
	rm o2linker.c
	rm o2linker_doc.idx
	rm o2linker_doc.scn
	rm o2linker_doc.toc
	rm o2linker_doc.tex
	rm o2linker_doc.log