# 2003-05-16 Per Mildner qpsupport@sics.se # # Make a C or C++ run-time system that calls Prolog and where Prolog # can call back into the executable. # This make file assumes GNU make and GCC # # Quintus Prolog tools (qld, qpc) are assumed to be in the PATH, if # not, set QLD and QPC make variables. ## Interesting make targets: ## check -- Build everything and run the test program ## all -- Build everything ## clean -- remove all generated files ## Interesting make variables: ## C_DIALECT -- c or cpp (lowercase) for C or C++ respectively, You need to do make clean first. ## ## Examples: ## Make everything as C code and run check ## make clean check C_DIALECT=c ## ## Make everything as C++ code and run check ## make clean check C_DIALECT=cpp ##################################################################################### # default target .PHONY: default default: all # c or cpp to use C or C++ respectively C_DIALECT = c ##### C compiler specifics CC = gcc # Flags for compiling for shared opjects (e.g., enable Position # Independant Code) PIC = -fPIC # Flags for $(CC) to turn on appropriate warnings C_WARNING_OPTS = -Wall -Werror ################################################################# QPC = qpc QLD = qld QPC_VERBOSE = -v QLD_VERBOSE = -v ################################################################# SED = sed ################################################################# # QP paths, use qld -P to get search paths # QP installation dir QP_DIR = $(shell $(QLD) -P quintus | $(SED) -e 's/^.*:.*://') # There is no direct way to get the include directory but 'messages' are in the same folder. QP_INCLUDE_DIR = $(shell $(QLD) -P messages | $(SED) -e 's/^.*:.*://') QP_RUNTIME_DIR = $(shell $(QLD) -P runtime | $(SED) -e 's/^.*:.*://') QP_LIBRARY_DIR = $(shell $(QLD) -P library | $(SED) -n -e 's/^.*:qplib(library)://p') # First line (the most specific) of system path QP_SYSTEM = $(shell $(QLD) -p system | $(SED) -e 's/^.*://' -e 'q') QP_LIBRARY_SYSTEM_DIR = $(QP_LIBRARY_DIR)/$(QP_SYSTEM) QP_INCLUDE_FLAGS = "-I$(QP_INCLUDE_DIR)" OS_LIBS = -lm -ldl QP_LIBS = $(QP_RUNTIME_DIR)/qprte.o $(QP_RUNTIME_DIR)/libqp.a $(QP_LIBRARY_SYSTEM_DIR)/libplm.a ################################################################# DDEBUG = -DDEBUG CFLAGS += $(C_WARNING_OPTS) CPPFLAGS += $(DDEBUG) $(QP_INCLUDE_FLAGS) ################################################################################## PROLOG_SOURCES = testmodule.pl FOREIGN_FILES = myforeign.o .PHONY: all all: myapp .PHONY: check # Use explicit directory part since current directory may not be first on PATH if at all check: myapp $( $@ cat $< >> $@ chmod a-w $@ myapp : myapp.o myforeign.o my_pl_code.qof.o $(CC) $^ -o $@ $(QP_LIBS) $(OS_LIBS) .PHONY: clean clean: rm -f *.o *.qof myapp rm -f myforeign.cpp myapp.cpp