put /local/fungw/OFS ?/tmpasm/OFS
put /tmpasm/OFS { }
put /local/fungw/src {
 fungw.c
 fungw_conv.c
 fungw_ptr.c
 fungw_debug.c
 fungw_call.c
}

uniq /local/fungw/src
put /local/fungw/obj /local/fungw/src
gsub /local/fungw/obj {.c[ \t\r\n]} {.o }

put /local/fungw/cflags ?cc/argstd/Wall
if /local/fungw/debug then
	append /local/fungw/cflags [@-g @/host/cc/argstd/ansi@ @/host/cc/cflags@ -Dinline= @]
end

put /local/fungw/ldflags [@ @/host/cc/ldflags@ @/target/cc/rdynamic@ @]

if ?/local/fungw/disable_dynlib
then
	put /local/fungw/dyntarget {}
else
	put /local/fungw/dyntarget {$(FUNGW_DYN) $(FUNGW_DYN_VER_X) $(FUNGW_DYN_VER_XY) $(FUNGW_DYN_VER_XYZ)}
end

switch /target/cc/soname
	case {^$}
		put /local/fungw/soname {}
		end
	default
		put /local/fungw/soname [@@/target/cc/soname@$(FUNGW_DYN_VER_X)@]
		end
end


print [~# Generated by ./configure, do not edit

SCCBOX=../scconfig/sccbox

PREFIX=~/local/fungw/prefix~
INCDIR=$(install_root)$(DESTDIR)$(PREFIX)/include/libfungw
LIBDIR=$(install_root)$(DESTDIR)$(PREFIX)/~/local/fungw/libdirname~
PUPDIR_RAW=$(PREFIX)/~/local/fungw/pupdirname~
CFLAGS = -I.. ~cc/cflags~ ~/local/fungw/cflags~ ~/target/cc/fpic~ -I../src_3rd -DFGW_PUPDIRNAME=\"$(PUPDIR_RAW)\" $(FUNGW_CFLAGS)
LDFLAGS = ~/local/fungw/ldflags~ ~/target/cc/fpic~
OBJS = ~/local/fungw/obj~


FUNGW_DYN = libfungw~/target/sys/ext_dynlib~
FUNGW_DYN_VER_X = $(FUNGW_DYN).~/local/fungw/ver1~
FUNGW_DYN_VER_XY = $(FUNGW_DYN_VER_X).~/local/fungw/ver2~
FUNGW_DYN_VER_XYZ = $(FUNGW_DYN_VER_XY).~/local/fungw/ver3~


all: libfungw.a $(FUNGW_DYN)

libfungw.a: $(OBJS) ~/local/fungw/dyntarget~
	@$(SCCBOX) rm -f libfungw.a
	@~/host/fstools/ar~ r libfungw.a $(OBJS)
	-@~/host/fstools/ranlib~ libfungw.a

$(FUNGW_DYN_VER_XYZ): $(OBJS)
	$(CC)  $(OBJS) -o $(FUNGW_DYN_VER_XYZ) $(LDFLAGS) ~?/target/cc/ldflags_dynlib~ ~?/local/fungw/soname~ ~?/target/cc/so_undefined~

$(FUNGW_DYN_VER_XY): $(FUNGW_DYN_VER_XYZ)
	$(SCCBOX) ln -f $(FUNGW_DYN_VER_XYZ) $(FUNGW_DYN_VER_XY)

$(FUNGW_DYN_VER_X): $(FUNGW_DYN_VER_XYZ)
	$(SCCBOX) ln -f $(FUNGW_DYN_VER_XYZ) $(FUNGW_DYN_VER_X)

$(FUNGW_DYN): $(FUNGW_DYN_VER_XYZ)
	$(SCCBOX) ln -f $(FUNGW_DYN_VER_XYZ) $(FUNGW_DYN)

include Makefile.dep

clean:
	$(SCCBOX) rm -f $(OBJS) libfungw.a $(FUNGW_DYN) $(FUNGW_DYN_VER_X) $(FUNGW_DYN_VER_XY) $(FUNGW_DYN_VER_XYZ)

distclean:
	rm Makefile

# Universal install rule (can uninstall as well)
install_:
	$(MKDR) $(LIBDIR) $(INCDIR)
	$(INST) fungw.h $(INCDIR)/fungw.h
	$(INST) fungw_conv.h $(INCDIR)/fungw_conv.h
	$(INST) scconfig_hooks.h $(INCDIR)/scconfig_hooks.h
	$(INST) $(FUNGW_DYN_VER_XYZ) $(LIBDIR)/$(FUNGW_DYN_VER_XYZ)

install_link_:
	$(SCCBOX) $(HOW) $(FUNGW_DYN_VER_XYZ) $(LIBDIR)/$(FUNGW_DYN)
	$(SCCBOX) $(HOW) $(FUNGW_DYN_VER_XYZ) $(LIBDIR)/$(FUNGW_DYN_VER_X)
	$(SCCBOX) $(HOW) $(FUNGW_DYN_VER_XYZ) $(LIBDIR)/$(FUNGW_DYN_VER_XY)

install:
	$(MAKE) install_ "INST=$(SCCBOX) install -i" "MKDR=$(SCCBOX) mkdir -p -i"
	$(MAKE) install_link_ "HOW=ln -f"

linstall:
	$(MAKE) install_ "INST=$(SCCBOX) install -l -f -a" "MKDR=$(SCCBOX) mkdir -p -i"
	$(MAKE) install_link_ "HOW=ln -f"

uninstall:
	$(MAKE) install_link_ "HOW=install -u"
	$(MAKE) install_ "INST=$(SCCBOX) install -u -f" "MKDR=$(SCCBOX) mkdir -u"

dep:
	echo "### Generated file, do not edit, run make dep ###" > Makefile.dep
	echo "" >> Makefile.dep
~]

foreach /local/fungw/c in /local/fungw/src
	print [~	@gcc -MM ~/local/fungw/c~ -I. >> Makefile.dep
~]
end

print {\n### Rules for compiling objects ###\n}
foreach /local/fungw/c in /local/fungw/src
	put /local/fungw/o /local/fungw/c
	sub /local/fungw/o {.c$} {.o}
	print [~
~/local/fungw/o~: ~/local/fungw/c~
	$(CC) -c $(CFLAGS) -o ~/local/fungw/o~ ~/local/fungw/c~
~]
end



put /tmpasm/OFS /local/fungw/OFS
