# Makefile for pcrelib

# Define MODULE to true if you wish to build the relocatable module
# instead of the linkable C library
ifeq (${MODULE},true)
CFLAGS = -c -zM -DPCRE2_CODE_UNIT_WIDTH=8 -DHAVE_CONFIG_H -IC:
else
CFLAGS = -c -DPCRE2_CODE_UNIT_WIDTH=8 -DHAVE_CONFIG_H -IC:
endif
LIBFLAGS = -c -o
LIBOBJS1 = o.pcre2_auto_possess o.pcre2_chartables o.pcre2_compile o.pcre2_config\
o.pcre2_context o.pcre2_convert o.pcre2_dfa_match o.pcre2_error o.pcre2_extuni\
o.pcre2_find_bracket o.pcre2_jit_compile o.pcre2_maketables
LIBOBJS2 = o.pcre2_match o.pcre2_match_data o.pcre2_newline o.pcre2_ord2utf\
o.pcre2_pattern_info o.pcre2_script_run o.pcre2_serialize o.pcre2_string_utils o.pcre2_study
LIBOBJS3 = o.pcre2_substitute o.pcre2_substring o.pcre2_tables o.pcre2_ucd\
o.pcre2_valid_utf o.pcre2_xclass

.SUFFIXES: .o .c

ifeq (${MODULE},true)
all: pcremod
else
all: pcre2lib pcretest
endif

install: pcre2lib
	cdir <C/C++$dir>.Export.APCS-32.Lib.pcre2
	cdir <C/C++$dir>.Export.APCS-32.Lib.pcre2.h
	cdir <C/C++$dir>.Export.APCS-32.Lib.pcre2.o
	copy pcre2lib <C/C++$dir>.Export.APCS-32.Lib.pcre2.o.pcre2lib ~c v
	copy h.pcre2 <C/C++$dir>.Export.APCS-32.Lib.pcre2.h.pcre2 ~c v

pcremod: cmhg.PCREHeader c.PCREModule pcre2lib
	cmhg -o o.PCREHeader cmhg.PCREHeader
	cc -c -zM -DPCRE2_CODE_UNIT_WIDTH=8 -IC: -o o.PCREModule c.PCREModule
	link -RMF o.PCREHeader o.PCREModule pcre2lib C:o.stubs -Output pcremod

pcretest: c.pcre2test c.pcre2_printint pcre2lib pcre2posix
	cc -DHAVE_CONFIG_H -DNOPOSIX -IC: -lpcre2lib,pcre2posix,C:o.stubs -o pcretest c.pcre2test

pcre2lib: ${LIBOBJS1} ${LIBOBJS2} ${LIBOBJS3}
	libfile ${LIBFLAGS} pcre2lib ${LIBOBJS1}
	libfile -i -o pcre2lib ${LIBOBJS2}
	libfile -i -o pcre2lib ${LIBOBJS3}

# This is needed to build the test program
pcre2posix: c.pcre2posix
	cc $(CFLAGS) -o o.pcre2posix c.pcre2posix
	libfile $(LIBFLAGS) pcre2posix o.pcre2posix

dftables: c.dftables
	cc -DHAVE_CONFIG_H -IC: -o dftables c.dftables
                
.c.o:;  cc $(CFLAGS) -o $@ c.$*

c.pcre_chartables: dftables
	dftables c.pcre2_chartables

