#
# Makefile for the Linux C library
#

TOPDIR=.

include $(TOPDIR)/Makeconfig

CLEAN_DIRS= bsd cvt ctype curses dirent gdbm grp inet io \
	libio locale login malloc math misc mntent posix pwd regex \
	rpc setjmp signal stdlib string sysdeps termcap time ufc \
	compat gcc libbsd malloc-930716 yp $(NLSDIR) sbin jump

ifeq ($(LITE),true)
# for light C library without curses, gdbm
DIRS = bsd cvt ctype dirent grp inet io libio locale login \
	malloc-930716 misc mntent posix pwd regex rpc setjmp signal \
	stdlib string sysdeps termcap time ufc compat gcc # yp
else
ifeq ($(CHECKER),true)
DIRS= bsd cvt ctype dirent grp inet io \
	libio locale login math misc mntent posix pwd regex \
	rpc setjmp signal stdlib string sysdeps termcap time ufc \
	gcc libbsd yp $(NLSDIR) gdbm curses
else
ifeq ($(PIC),true)
DIRS= bsd cvt ctype dirent grp inet io \
	libio locale login misc mntent posix pwd regex \
	rpc setjmp signal stdlib string sysdeps time ufc \
	malloc-930716 yp $(NLSDIR)
else
ifeq ($(MATH),true)
DIRS= math sysdeps
else
DIRS= bsd cvt ctype curses dirent gdbm grp inet io \
	libio locale login malloc math misc mntent posix pwd regex \
	rpc setjmp signal stdlib string sysdeps termcap time ufc \
	compat gcc libbsd malloc-930716 yp $(NLSDIR)
endif
endif
endif
endif

ifeq ($(SHARED),true)
DIRS:= $(DIRS) jump
endif

lib depend:
	for i in $(DIRS); do \
		echo making $@ in $$i; \
		(cd $$i; $(MAKE) $@); \
	done

ifeq ($(PIC),true)
libc_pic.so:
	cd $(PIC_DIR) ;\
	$(MKDIR) libalias ; cd libalias ;\
	$(AR) x ../../libalias.a ; cd .. ;\
	$(PIC_LD) -Bshareable -Bsymbolic -assert nosymbolic
		-o $@.1.1 libc/*.o libalias/*.o
endif

clean realclean:
	$(RM) -f core *.o *.s *.sa *.so.* *.a verify.out
	$(RM) -rf $(OBJS_DIRS)
	for i in $(CLEAN_DIRS); do \
	   echo making $@ in $$i; \
	   (cd $$i; $(MAKE) $@); \
	done

install: install.shared install.static install.debug install.profile

install.lite:
	(cd jump; $(MAKE) install LITE=true)

install.shared:
	(cd jump; $(MAKE) install)

install.static:
	-$(AR) -d static/libc.a __.SYMDEF
	(cd static; $(RM) -rf tmpcopy; $(MKDIR) tmpcopy; \
	 cd tmpcopy; \
	 $(AR) -x ../../libalias.a; \
	 $(AR) ucv ../libc.a *.o; \
	 $(RM) *; \
	 $(AR) -x ../../libmalias.a; \
	 $(AR) ucv ../libm.a *.o; \
	 cd ..; $(RM) -rf tmpcopy; \
	 $(REALRANLIB) *.a; cp *.a crt0.o $(TARGET_LIB_DIR))

install.debug:
	-$(AR) -d debug/libg.a __.SYMDEF
	(cd debug; $(RM) -rf tmpcopy; $(MKDIR) tmpcopy; \
	 cd tmpcopy; \
	 $(AR) -x ../../libalias.a; \
	 $(AR) ucv ../libg.a *.o; \
	 cd ..; $(RM) -rf tmpcopy; \
	 $(REALRANLIB) *.a; \
	 cp *.a $(TARGET_LIBEXTRA_DIR); \
	 cp libc/mcheck-init.o $(TARGET_LIBEXTRA_DIR)/libmcheck.a)

install.profile:
	-$(AR) -d profile/libc_p.a __.SYMDEF
	(cd profile; $(RM) -rf tmpcopy; $(MKDIR) tmpcopy; \
	 cd tmpcopy; \
	 $(AR) -x ../../libalias.a; \
	 $(AR) ucv ../libc_p.a *.o; \
	 cd ..; $(RM) -rf tmpcopy; \
	 $(REALRANLIB) *.a; cp *.a gcrt0.o $(TARGET_LIBEXTRA_DIR))

install.checker:
	(cd checker; $(MAKE) install)
