Makefile: ../../../deco-0.8//Makefile.head
# Standard Makefile header for Shag/OS

# NOTE:	** DO NOT MAKE IMPORTANT CHANGES IN THIS FILE **
#	All Makefiles containing this header are dynamically generated
#	Makefiles, which will be recreated every time the build directory
#	is configured, or whenever the source 'Make' files, or 
#	'config.var' are changed.
#	Therefore, any changes made here should be for temporary
#	testing purposes only, and in most cases, it is better to
#	make temporary changes in 'config.var', and then run
#	'make config' again to fully incorporate those changes.
#	Also, individual '.mak' files can be edited for temporary 
#	overrides for individual targets.
 
export

REQUIRES=
XINCPATH=
XINCFILES=
INCFILES=
SRCFILES=
LINKFILES=
XLINKFILES=
COPYFILES=
TARGETS=
SUBDIRS=
SFILES=
STFILES=
XFILES=
LXFILES=
RXFILES=
DXFILES=
LIBFILES=

PRECONFIGFILES=
CONFIGFILES=

BINDIR=$(BASE)/bin
LIBDIR=$(BASE)/lib
FCONFIG=$(BINDIR)/fconfig
DCONFIG=$(SRC)/bin/dconfig

DECO=$(BINDIR)/deco
GENOFS=$(BINDIR)/cgenofs
EXTRACT=$(BINDIR)/extract

Makefile: config.var
Variables = Variables Extensions 	Makedepend Cpp Command Rule 	Includes Includes_Wanted Includes_Needed Includes_Banned 	Flags Flags_Wanted Flags_Needed Flags_Banned 	CPP INCLUDES MAKEFLAGS 	AR_RC RANLIB NECHO AWK 	CONF_SYS CONF_HOST CONF_USER CONF_DATE CONF_ARCH 	SRC SPATH BASE SHELL
Extensions = c cc S h hh o do gcc gxx gas fpic deco
Makedepend = g++ -M -MG $$(Includes) -x c++ $$<
Makedepend_gcc = gcc -M -MG $$(Includes) $$<
Makedepend_gas = g++ -DASM -M -MG $$(Includes) -x c++ $$<
Cpp = g++ -E -x c++ $$(Includes) $$<
Cpp_gcc = gcc -E $$(Includes) $$<
Cpp_gas = g++ -E -x c++ -DASM $$(Includes) $$<
Command_gcc = gcc -c $$(Flags) $$(Includes) $$< -o $$@
Command_gxx = g++ -c $$(Flags) $$(Includes) $$< -o $$@
Command_gas = g++ -DASM -c $$(Includes) $$< -o $$@
Command_deco = g++ -E $$(Includes) -D__dynamic__ -D__dynamic_interface__ -x c++ $$< 	| $$(BASE)/$$(DECO) > $$@
Rule_c_o = gcc c
Rule_c_do = fpic gcc c
Rule_cc_o = gxx cc
Rule_cc_do = fpic gxx cc
Rule_S_o = gas S
Rule_S_do = fpic gas S
Includes_Wanted = -I$$BASE/include -idirafter $$BASE/include/posix -nostdinc
Includes_Wanted_cc = -I$$BASE/include/c++ -nostdinc++
Includes_Wanted_S = -nostdinc++
Flags_Wanted_c = -static -m486 -O6 -msoft-float 		-malign-loops=0 -malign-jumps=0 -malign-functions=0
Flags_Wanted_cc = -static -m486 -O6 -msoft-float 		-malign-loops=0 -malign-jumps=0 -malign-functions=0
Flags_Wanted_gcc = -Wall -Wpointer-arith -Wstrict-prototypes 	-Wmissing-prototypes -fforce-mem -fforce-addr 	-fomit-frame-pointer -finline-functions 	-freg-struct-return -fshort-enums 	-save-temps -fverbose-asm 	 -static
Flags_Wanted_gxx = -Wall -Wpointer-arith -Wstrict-prototypes 	-Wmissing-prototypes -fforce-mem -fforce-addr 	-fomit-frame-pointer -finline-functions 	-freg-struct-return -fshort-enums 	-save-temps -fverbose-asm 	 -static
Flags_Needed_fpic = -fPIC
CPP = g++ -E -x c++
INCLUDES = 
MAKEFLAGS = --no-print-directory -r
AR_RC = ar rc
RANLIB = ranlib
NECHO = echo -n
AWK = awk
CONF_SYS = test
CONF_ARCH = isa_bus pc i486sx i486 i386dx i386 ix86 . gen
SRC = ../../../deco-0.8/
SPATH = /lib/stdc++/
BASE = ../../.
SHELL = /bin/sh -e
Makefile: Make-mi
# Standard C++ libraries and includes

SUBDIRS = 

XINCPATH = c++
XINCFILES += defines.hh new.hh
#XINCFILES += string.hh defines.hh
#SRCFILES += string.cc
SRCFILES += empty.cc	# just so we get a lib...
LIBFILES += libstdc++.a
TARGETS += ${LIBFILES}

#libstdcxx_OBJS += string.o
libstdc++.a_OBJS += empty.o
libstdc++.a: $(libstdc++.a_OBJS)


all: ${TARGETS}


Makefile: ../../../deco-0.8//Makefile.tail
.SUFFIXES: .c .cc .s .S .h .hh .o .x 

# Disable default rules:

%.o: %.cc
%.o: %.c
%.o: %.S
%.o: %.s


#############################################################################
# Makefile building:
#############################################################################

Makefile:
	@set -e; echo "Rebuilding $(BASE)$(SPATH)/Makefile..."; \
	echo "# Rebuilt Makefile:" > Makefile; \
	for i in $^; do \
		if [ $$i = "broken_config" ] ; then \
			$(MAKE) config; \
		else \
			echo "Makefile: $$i" >> Makefile; \
			cat $$i >> Makefile; \
		fi \
	done 


.PHONY: broken_config
broken_config:
	@echo "Must fix incomplete configuration first:"


#############################################################################
# Configuration:
#############################################################################

.PHONY: everything
everything: preconfigall configall all

.PHONY: config
config:
	@set -e; $(DCONFIG) "$(CONF_ARCH)" $(SRC) $(SPATH) $(BASE); \
	$(MAKE) configfiles

#$(FCONFIG):
#	@set -e; $(MAKE) $(BASE)/fconfig/all

.PHONY: preconfigfiles
preconfigfiles: $(FCONFIG) $(PRECONFIGFILES)
	@set -e; for req in $$REQUIRES; do \
		if [ ! -r $req ] ; then \
			echo $$req; \
			if [ `dirname $$req` = . \
				 -o `dirname $$req` = / ] ; then \
				echo "missing requirement: $$req"; \
				exit 1; \
			else \
				$(MAKE) -r $$req; \
			fi \
		fi; \
	done

	@set -e; TINCFILES="$$XINCFILES $$INCFILES"; \
	 if [ "$$TINCFILES" != " " ]; then \
		if [ "$(XINCFILES)" != "" ]; then \
			FSPATH=..; \
			if [ "$(XINCPATH)" = "." ] ; then \
				FINCPATH=$(BASE)/include; \
			else \
				FINCPATH=$(BASE)/include/$(XINCPATH); \
				XX=$(XINCPATH); \
				while [ $$XX != '.' ] ; do \
					FSPATH=$$FSPATH/..; \
					XX=`dirname $$XX`; \
				done \
			fi; \
			FSPATH=$$FSPATH$(SPATH); \
			echo "Installing include files in $$FINCPATH:"; \
			echo $(XINCFILES); \
			mkdir -p $$FINCPATH; \
			set +e; \
			for i in $$XINCFILES; do \
				xincfile=$$FINCPATH/`basename $$i .hh`; \
				echo "#include \"$$FSPATH`basename $$i`\"" \
				      > $$xincfile.new; \
				(cmp -s $$xincfile $$xincfile.new ); \
				if [ $$? != 0 ] ; then \
					mv $$xincfile.new $$xincfile; \
				else \
					rm -f $$xincfile.new; \
				fi; \
			done; \
			set -e; \
		fi; \
		FINCFILES=;\
		for i in $$TINCFILES; do \
			if [ `dirname $$i` = 'make' ]; then \
				if [ "$$FINCFILES" != "" ] ; then \
					$(FCONFIG) "$(CONF_ARCH)" \
						$(SRC) $(SPATH) $$FINCFILES; \
					FINCFILES=;\
				fi; \
				$(MAKE) `basename $$i`; \
			else \
				FINCFILES="$$FINCFILES $$i"; \
			fi \
		done; \
		if [ "$$FINCFILES" != "" ] ; then \
			$(FCONFIG) "$(CONF_ARCH)" \
				$(SRC) $(SPATH) $$FINCFILES; \
			FINCFILES=;\
		fi \
	fi; \
	for lib in $$LIBFILES; do \
		echo "Makefile: $$lib.mak" > $(LIBDIR)/$$lib.mak; \
		echo "$$lib:" >> $(LIBDIR)/$$lib.mak; \
		echo "	@set -e; cd "`$(BINDIR)/relpath . $(LIBDIR)` \
			"; \$$(MAKE) $$lib" >> $(LIBDIR)/$$lib.mak; \
		cat $(LIBDIR)/$$lib.mak >> $(LIBDIR)/Makefile; \
	done

.PHONY: configfiles
configfiles: $(FCONFIG) preconfigfiles $(CONFIGFILES)
	@set -e; rm -f *.mak.old; \
	for i in *.mak; do \
		if [ $$i != "*.mak" ] ; then \
			mv -f $$i $$i.old; \
		fi \
	done; \
	set +e; \
	$(FCONFIG) "$(CONF_ARCH)" $(SRC) $(SPATH) $(SRCFILES); \
	if [ $$? != 0 ] ; then \
		echo "*** error: fconfig failed (.$(SPATH))"; \
		echo "	(adding 'config' as make dependency)"; \
		echo "Makefile: broken_config" >> Makefile; \
		exit 1; \
	fi; \
	set -e; \
	for i in *.mak.old; do \
		if [ $$i != "*.mak.old" ] ; then \
			mkf=`basename $$i .old`; \
			echo `basename $$i .mak.old`: $$mkf > $$mkf; \
		fi \
	done; \
	for i in *.mak; do \
		if [ $$i != "*.mak" ] ; then \
			echo "Makefile: $$i" >> Makefile; \
			cat $$i >> Makefile; \
		fi \
	done; \
	#rm -f *.mak.old

.PHONY: reconfig
reconfig:
	$(BINDIR)/config $(CONF_SYS)

.PHONY: preconfigall
preconfigall:
	@set -e; $(DCONFIG) "$(CONF_ARCH)" $(SRC) $(SPATH) $(BASE); \
	$(MAKE) preconfigfiles; \
	$(MAKE) dopreconfigall 

.PHONY: configall
configall: 
	@set -e; $(DCONFIG) "$(CONF_ARCH)" $(SRC) $(SPATH) $(BASE); \
	$(MAKE) configfiles; \
	$(MAKE) doconfigall

.PHONY: dopreconfigall
dopreconfigall: 
	@set -e; for i in $$SUBDIRS; do \
		if [ ! -d $$i ] ; then \
			mkdir $$i; \
		fi; \
		( cd $$i; \
		  if [ ! -f Makefile ] ; then \
		  	../$(DCONFIG) "$(CONF_ARCH)" \
				../$(SRC) $(SPATH)$$i/ ../$(BASE); \
		  fi; \
		  $(MAKE) preconfigfiles dopreconfigall;  \
		) \
	done

.PHONY: doconfigall
doconfigall: 
	@set -e; for i in $$SUBDIRS; do \
		set -e; \
		if [ -d $$i ] ; then \
			( cd $$i; \
			  ../$(DCONFIG) "$(CONF_ARCH)" \
					../$(SRC) $(SPATH)$$i/ ../$(BASE); \
			  $(MAKE) configfiles doconfigall;  \
			) \
		fi \
	done 

.PHONY: tree
tree: 
	@set -e; for i in $$SUBDIRS; do \
		$(MAKE) $$i/tree; \
	done


.PHONY: testshell
testshell:
	@PATH=$$PATH:`$$BINDIR/abspath $$BINDIR`; sh


#############################################################################
# Executable creation:
#############################################################################

# files to be linked from source tree 
$(LINKFILES): # config.var
	@for i in $(CONF_ARCH); do \
		if [ $$i != . ] ; then \
			i=m-$$i; \
		fi; \
		if [ -f $(SRC)$(SPATH)$$i/$@ ] ; then \
			sh -xc "rm -f `basename $@`; \
				ln -s $(SRC)$(SPATH)$$i/$@ ."; \
			break; \
		fi; \
	done

# files to be linked in from other (external) directories
$(XLINKFILES): 
	@rm -f $@
	ln -s $< $@

# files to be copied from source tree
$(COPYFILES): config.var
	@for i in $(CONF_ARCH); do \
		if [ $$i != . ] ; then \
			i=m-$$i; \
		fi; \
		if [ -f $(SRC)$(SPATH)$$i/$@ ] ; then \
			sh -xc "cp -f $(SRC)$(SPATH)/$@ `basename $@`"; \
			break; \
		fi; \
	done

# This is all very Unix/GCC-specific right now, and needs to be moved
# into platform-specific sections...

# standalone files to be run from SOLO
# default start address can be overridden by flags
$(SFILES): config.var \
		$(BASE)/lib/srt0.o \
		$(BASE)/lib/crt_head.o $(BASE)/lib/crt_tail.o
	$(CXX) -nostdlib -nodefaultlibs -nostartfiles \
		-L$(BASE)/lib -Wl,-Ttext,10000000 $($@_FLAGS) \
		-o $@ $(BASE)/lib/srt0.o $(BASE)/lib/crt_head.o \
		$($@_OBJS) $($@_LIBS) -lgcc \
		$(BASE)/lib/crt_tail.o

# standalone test files to be run locally
# assumes that a corresponding $@.x rule exists
$(STFILES): config.var
	$(CXX) -nostdlib -nodefaultlibs -nostartfiles \
		-L$(BASE)/lib $($@.x_FLAGS) -r \
		-o $@.ro \
		$($@.x_OBJS) $($@.x_LIBS)
	$(CXX) $($@_FLAGS) -o $@ $@.ro $($@_OBJS) $($@_LIBS) \
		$(BASE)/lib/libemsolo.a

# executable files for Shag/OS
$(XFILES): config.var
	$(CXX) -nostdlib -nodefaultlibs -nostartfiles \
		-L$(BASE)/lib $($@_FLAGS) \
		-o $@ crt0.o crt_head.o \
		$($@_OBJS) $($@_LIBS) -lgcc \
		crt_tail.o

# relocatable executable modules (old-style dynamic)
$(RXFILES): config.var
	$(CXX) -nostdlib -nodefaultlibs -nostartfiles \
		-L$(BASE)/lib -r $($@_FLAGS) -o $@ $($@_OBJS) $($@_LIBS) -lgcc

# dynamic executable modules
# XXX - this needs major modification...
$(DXFILES): config.var
	$(CXX) -nostdlib -nodefaultlibs -nostartfiles \
		-shared -L$(BASE)/lib $($@_FLAGS) -Wl,-soname,$@ -o $@ \
		$(BASE)/lib/boot/crt_head.o \
		$($@_OBJS) $($@_LIBS) -lgcc \
		$(BASE)/lib/boot/crt_tail.o 

# local executable files for host development system
$(LXFILES): config.var
	$(CXX) $($@_FLAGS) -o $@ $($@_OBJS) $($@_LIBS) 

$(LIBFILES): config.var
	$(AR_RC) $($@_FLAGS) $@ $($@_OBJS)
	$(RANLIB) $@
	@set -e; rpath=`$(BINDIR)/relpath . $(LIBDIR)`; \
	if [ $$rpath != "." ] ; then \
		rm -f $(LIBDIR)/$@; \
		ln -s $$rpath""$@ $(LIBDIR)/$@; \
	fi

$(SUBDIRS): 
	@set -e; mkdir $@; cd $@; \
	../$(DCONFIG) "$(CONF_ARCH)" ../$(SRC) $(SPATH)$@/ ../$(BASE); \
	$(MAKE) configfiles

.PHONY: libs
libs:
	@set -e; $(MAKE) $(BASE)/lib/all


# declare these so the default rule doesn't pick them up:

.PHONY: all everything $(COMMANDS)

#############################################################################
# Default rule:  (used for configuration, generally)
#############################################################################

%::
	@set -e; dir=`dirname $@`; base=`basename $@`; \
	if [ $$dir = . ] ; then \
	    for ext in $$Extensions; do \
		if [ `basename $$base .$$ext` != $$base ] ; then \
			$(FCONFIG) "$(CONF_ARCH)" \
				$(SRC) $(SPATH) $$base; \
			mkf=$$base.mak; \
			mkf=`echo $$mkf`; \
			if [ ! -r $$mkf ] ; then \
				echo "*** error: $@: cannot create target"; \
				exit 1; \
			fi; \
			echo "Makefile: $$mkf" >> Makefile; \
			cat $$mkf >> Makefile; \
			$(MAKE) -r $$base; \
			exit 0; \
		fi; \
	    done; \
	fi; \
	while [ `dirname $$dir` != . ] ; do \
		base=`basename $$dir`/$$base; \
		dir=`dirname $$dir`; \
	done; \
	if [ "$$dir" = "." ] ; then \
		echo "** error: $@: no such target"; \
		exit 1; \
	fi; \
	if [ ! -d $$dir ] ; then \
		for i in $$SUBDIRS; do \
			if [ $$i = "$$dir" ]; then \
				mkdir $$dir; \
			fi; \
		done; \
		if [ ! -d $$dir ] ; then \
			echo "** error: $$dir: unknown subdirectory"; \
			exit 1; \
		fi; \
	fi; \
	cd $$dir; \
	if [ ! -f Makefile ] ; then \
		../$(DCONFIG) "$(CONF_ARCH)" ../$(SRC) \
			 $(SPATH)$$dir/ ../$(BASE); \
		$(MAKE) configfiles; \
	fi; \
	set +e; \
	if [ "$$dir/$$base/" = "$@" ] ; then \
		$(MAKE) -r "$$base/"; \
		if [ $$? != 0 ]; then \
			echo "*** error: $$base/ failed (.$(SPATH)$$dir)"; \
			exit 1; \
		fi; \
	else \
		$(MAKE) -r "$$base"; \
		if [ $$? != 0 ]; then \
			echo "*** error: $$base failed (.$(SPATH)$$dir)"; \
			exit 1; \
		fi; \
	fi 

 
#############################################################################
# Commands found outside this file:
#############################################################################


# Code-size info:
.PHONY: print_sizes print_semi_sizes

# Searching for bugs/etc:
.PHONY: find_old find_fixes find_bugs find_adds find_opts \
	find_cleans find_deps find_questions find_xxx

# Cleaning up:
.PHONY: tidy clean cleanconf cleantemp cleanconf_all cleantemp_all rmtree

# informative commands:
.PHONY: purpose showsrctree showtree showsrc_sizes showtree_sizes list

# Archival commands:
.PHONY: tar tarz ftarz

# Distribution-creation commands:
.PHONY: solo_dist solo_bindist sos_dist sos_bindist deco_dist deco_bindist

# Misc:
.PHONY: listsrc headers help


.DEFAULT:
	@PATH=$$PATH:`pwd`/$$BINDIR; \
	( $(BINDIR)/makecmds $@; ); \
	if [ $$? != 0 ] ; then \
		echo "*** error: '$@' failed"; \
	fi

Makefile: empty.o.mak
empty.o: empty.cc config.h empty-mi.cc
empty.o: empty.o.mak
	g++ -c  -Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -fforce-mem -fforce-addr -fomit-frame-pointer -finline-functions -freg-struct-return -fshort-enums -save-temps -fverbose-asm -static -m486 -O6 -msoft-float -malign-loops=0 -malign-jumps=0 -malign-functions=0  -I$$BASE/include/c++ -nostdinc++ -I$$BASE/include -idirafter $$BASE/include/posix -nostdinc empty.cc -o empty.o
empty.o.mak:
	../.././bin/fconfig "isa_bus pc i486sx i486 i386dx i386 ix86 . gen" "../../../deco-0.8/" /lib/stdc++/ empty.o


