#Copyright 2023, Arani Chakravarti
#
#This file is part of Homoeopim.
#
#Homoeopim is free software: you can redistribute it and/or modify it under
#the terms of the GNU Affero General Public License as published by the 
#Free Software Foundation, either version 3 of the License or any later
#version.
#
#Homoeopim is distributed in the hope that it will be useful, but WITHOUT
#ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
#FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
#License for more details.
#
#You should have received a copy of the GNU Affero General Public License
#along with Homoeopim. If not, see <https://www.gnu.org/licenses/>.
#
CFLAGS = -c -O3 -Wall -I/usr/lib/ghc/include

default: build_chikitsha_clp check_symptom_clips_lhs create_words_table \
 clips_strings_for_fuzzy_search

libbuild_chikitsha_clp.a: build_chikitsha_clp.o ~bhutum.o bhutum.o \
  build_chikitsha_clp.o check_for_errors.o create_clp_aggravation_defrules.o \
  create_clp_amelioration_defrules.o create_clp_compounded_symptom_defrules.o \
  create_clp_deffacts.o create_clp_defglobals.o create_clp_deftemplates.o \
  create_clp_symptom_defrules.o
	ar rcs libbuild_chikitsha_clp.a build_chikitsha_clp.o ~bhutum.o bhutum.o \
  build_chikitsha_clp.o check_for_errors.o create_clp_aggravation_defrules.o \
  create_clp_amelioration_defrules.o create_clp_compounded_symptom_defrules.o \
  create_clp_deffacts.o create_clp_defglobals.o create_clp_deftemplates.o \
  create_clp_symptom_defrules.o
	ranlib libbuild_chikitsha_clp.a

build_chikitsha_clp.h: isunique_stub.h

isunique_stub.h: isunique.o

isunique.o: isunique.hs
	ghc -c -O3 isunique.hs

build_chikitsha_clp: build_chikitsha_clp.h libbuild_chikitsha_clp.a
	ghc --make -no-hs-main -L. isunique.o build_chikitsha_clp.o -o build_chikitsha_clp -lbuild_chikitsha_clp -lstdc++ -lclips -lrt -lpq
	strip build_chikitsha_clp

build_chikitsha_clp.o: build_chikitsha_clp.C build_chikitsha_clp.h
	clang++ $(CFLAGS) build_chikitsha_clp.C

~bhutum.o: ~bhutum.C build_chikitsha_clp.h
	clang++ $(CFLAGS) ~bhutum.C

bhutum.o: bhutum.C build_chikitsha_clp.h
	clang++ $(CFLAGS) bhutum.C

check_for_errors.o: check_for_errors.C build_chikitsha_clp.h
	clang++ $(CFLAGS) check_for_errors.C

create_clp_aggravation_defrules.o: create_clp_aggravation_defrules.C build_chikitsha_clp.h
	clang++ $(CFLAGS) create_clp_aggravation_defrules.C

create_clp_amelioration_defrules.o: create_clp_amelioration_defrules.C build_chikitsha_clp.h
	clang++ $(CFLAGS) create_clp_amelioration_defrules.C

create_clp_compounded_symptom_defrules.o: create_clp_compounded_symptom_defrules.C build_chikitsha_clp.h
	clang++ $(CFLAGS) create_clp_compounded_symptom_defrules.C

create_clp_deffacts.o: create_clp_deffacts.C build_chikitsha_clp.h
	clang++ $(CFLAGS) create_clp_deffacts.C

create_clp_defglobals.o: create_clp_defglobals.C build_chikitsha_clp.h
	clang++ $(CFLAGS) create_clp_defglobals.C

create_clp_deftemplates.o: create_clp_deftemplates.C build_chikitsha_clp.h
	clang++ $(CFLAGS) create_clp_deftemplates.C

create_clp_symptom_defrules.o: create_clp_symptom_defrules.C build_chikitsha_clp.h
	clang++ $(CFLAGS) create_clp_symptom_defrules.C

check_symptom_clips_lhs: check_symptom_clips_lhs.o
	clang++ check_symptom_clips_lhs.o -o check_symptom_clips_lhs -lclips -lrt -lpq
	strip check_symptom_clips_lhs

check_symptom_clips_lhs.o: check_symptom_clips_lhs.C
	clang++ $(CFLAGS) check_symptom_clips_lhs.C

create_words_table: create_words_table.hs
	ghc -O --make create_words_table
	strip create_words_table

clips_strings_for_fuzzy_search: clips_strings_for_fuzzy_search.hs
	ghc -O --make clips_strings_for_fuzzy_search
	strip clips_strings_for_fuzzy_search
