RGSRC=../
include $(RGSRC)/envir.mak

ifeq ($(CONFIG_GLIBC),y)
  ARCHCONFIG_FIRST_TASKS+=rg_gcc
  SUBDIRS_y+=syslog/glibc
endif

ifneq ($(CONFIG_RG_OS_LINUX)$(CONFIG_RG_PERM_STORAGE),)
  ifndef CONFIG_LSP_DIST
    NEED_ZLIB=y
  else
    NEED_ZLIB=$(CONFIG_CRAMFS_FS)
  endif
endif

ifdef CONFIG_ULIBC
  SUBDIRS=ulibc
endif
SUBDIRS_y+=util
SUBDIRS_y+=tz
SUBDIRS_y+=zlib
SUBDIRS_$(CONFIG_RG_BUSYBOX)+=busybox
SUBDIRS_$(CONFIG_CRAMFS_FS)+=$(RGSRC)/os/linux/scripts/cramfs
SUBDIRS_$(CONFIG_ROMFS_FS)+=genromfs
SUBDIRS_$(CONFIG_RG_NETTOOLS_ARP)+=net-tools
SUBDIRS_$(CONFIG_GMP)+=gmp
SUBDIRS_$(CONFIG_FREESWAN)+=freeswan
ifneq ($(CONFIG_FREESWAN),y)
SUBDIRS_$(CONFIG_LIBDES)+=freeswan
endif
SUBDIRS_$(CONFIG_IPTABLES)+=iptables
SUBDIRS_$(CONFIG_ATM)+=atm kernel/linux/atm
SUBDIRS_$(CONFIG_RG_PPTPS)+=poptop
SUBDIRS_$(CONFIG_RG_PPTPC)+=pptp-client
SUBDIRS_$(CONFIG_RG_L2TPC)+=l2tp
SUBDIRS_y+=main

ALL_SUBDIRS:=$(SUBDIRS) $(SUBDIRS_m) $(SUBDIRS_y)

DEP_SUBDIRS:=$(ALL_SUBDIRS)

# Build must be the last subdir in order for make ramdisk to work
RAMDISK_SUBDIRS:=$(filter-out build,$(ALL_SUBDIRS)) build
# include should be the last subdir in order not to delete configuration file
# before the end of the cleaning
DISTCLEAN_SUBDIRS:=$(filter-out include,$(ALL_SUBDIRS)) \
  $(wildcard doc) $(wildcard pktgen)
ARCHCONFIG_SUBDIRS:=$(wildcard busybox include gmp freeswan net-tools build)

CLEAN_SUBDIRS:=$(DISTCLEAN_SUBDIRS)

include $(RGMK)

distclean::
	rm -rf lib

# Run this option if you would like to build GlibC 2.95.2 toolchain
glibc_config:
	mkdir -p build/glibc ; true
	cd build/glibc && unset LD_LIBRARY_PATH && \
	  CC=$(REAL_GCC) \
	  ../../glibc/configure --without-cvs \
	  --prefix=$(TOOLS_PREFIX)/$(TARGET_MACHINE)/ \
	  --build=i686-pc-linux-gnu --host=$(TARGET_MACHINE) \
	  --target=$(RG_CPU) \
	  --enable-add-ons=crypt,linuxthreads -v \
	  --with-headers=$(RGSRC)/os/linux/include/

rg_gcc:
	$(MAKE) -C $(RGSRC)/pkg/build gcc

.PHONY: glibc_config rg_gcc
