# $Id$ ## @file # # kBuild Makefile for kLIBC (formerly known as InnoTek LIBC). # # Copyright (c) 2006 knut st. osmundsen # # # This file is part of kLIBC. # # kLIBC is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # kLIBC is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with kLIBC; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # DEPTH = .. SUB_DEPTH = . include $(PATH_KBUILD)/subheader.kmk BLDPROGS := LIBRARIES := DLLS := PROGRAMS := INSTALLS = \ headers \ startupobjs \ libc_alias # Include sub-makefiles. include $(wildcard $(PATH_LIBC_SRC)/Makefile.kmk) # # Some external tools we depend on. # LIBC_GAWK ?= gawk$(HOSTSUFF_EXE) LIBC_DIFF ?= diff$(HOSTSUFF_EXE) # # The name of the alias library. # ifdef CFG_LIBC_USE_WATCOM KLIBC_LIB_ALIAS = $(PATH_TARGET)/libc_alias/libc_alias.lib else KLIBC_LIB_ALIAS = $(PATH_TARGET)/libc_alias/libc_alias.a endif # # libc_frontend.a # LIBRARIES += libc_frontend libc_frontend_TEMPLATE = libc libc_frontend_SOURCES = \ $(libc_libc_1_TARGET) \ $(libc_fbsdlibc_1_TARGET) \ $(libc_glibc_1_TARGET) \ $(libc_msun_1_TARGET) #libc_SOURCES.os2 = \ # $(libc_libsocket_1_TARGET) \ # $(libc_libsyslog_1_TARGET) libc_SOURCES.nt = $(kNIX.nt_1_TARGET) ifdef CFG_LIBC_LOGSTRICT_LIBS LIBRARIES += libc_frontend_l libc_frontend_l_TEMPLATE = libc.logstrict libc_frontend_l_SOURCES = \ $(libc_libc_l_1_TARGET) \ $(libc_fbsdlibc_l_1_TARGET) \ $(libc_glibc_l_1_TARGET) \ $(libc_msun_l_1_TARGET) #libc_frontend_l_SOURCES.os2 = \ # $(libc_libsocket_l_1_TARGET) \ # $(libc_libsyslog_l_1_TARGET) endif ifdef CFG_LIBC_PROFILED_LIBS LIBRARIES += libc_frontend_p libc_frontend_p_TEMPLATE = libc.profiled libc_frontend_p_SOURCES = \ $(libc_libc_p_1_TARGET) \ $(libc_fbsdlibc_p_1_TARGET) \ $(libc_glibc_p_1_TARGET) \ $(libc_msun_p_1_TARGET) #libc_frontend_p_SOURCES.os2 = \ # $(libc_libsocket_p_1_TARGET) \ # $(libc_libsyslog_p_1_TARGET) endif # # libc_asm.a # LIBRARIES += libc_frontend_asm libc_frontend_asm_TEMPLATE = libcasm libc_frontend_asm_SOURCES = \ $(libc_libc_asm_1_TARGET) \ $(libc_fbsdlibc_asm_1_TARGET) \ $(libc_glibc_asm_1_TARGET) \ $(libc_msun_asm_1_TARGET) ifdef CFG_LIBC_LOGSTRICT_LIBS LIBRARIES += libc_frontend_asm_l libc_frontend_asm_l_TEMPLATE = libcasm.logstrict libc_frontend_asm_l_SOURCES = \ $(libc_libc_asm_l_1_TARGET) \ $(libc_fbsdlibc_asm_l_1_TARGET) \ $(libc_glibc_asm_l_1_TARGET) \ $(libc_msun_asm_l_1_TARGET) endif ifdef CFG_LIBC_PROFILED_LIBS LIBRARIES += libc_frontend_asm_p libc_frontend_asm_p_TEMPLATE = libcasm.profiled libc_frontend_asm_p_SOURCES = \ $(libc_libc_asm_p_1_TARGET) \ $(libc_fbsdlibc_asm_p_1_TARGET) \ $(libc_glibc_asm_p_1_TARGET) \ $(libc_msun_asm_p_1_TARGET) endif # # libc.a # LIBRARIES += libc_s libc_s_TEMPLATE = libc libc_s_SOURCES = \ $(libc_frontend_1_TARGET) \ $(libc_kNIX_1_TARGET) libc_s_SOURCES.nt = $(kNIX.nt_1_TARGET) ifdef CFG_LIBC_LOGSTRICT_LIBS LIBRARIES += libc_s_l libc_s_l_TEMPLATE = libc.profiled libc_s_l_SOURCES = \ $(libc_frontend_l_1_TARGET) \ $(libc_kNIX_l_1_TARGET) libc_s_l_SOURCES.nt = $(kNIX_l.nt_1_TARGET) endif ifdef CFG_LIBC_PROFILED_LIBS LIBRARIES += libc_s_p libc_s_p_TEMPLATE = libc.profiled libc_s_p_SOURCES = \ $(libc_frontend_p_1_TARGET) \ $(libc_kNIX_p_1_TARGET) libc_s_p_SOURCES.nt = $(kNIX_p.nt_1_TARGET) endif # # libc_asm.a # LIBRARIES += libc_asm libc_asm_TEMPLATE = libcasm libc_asm_SOURCES = \ $(libc_frontend_asm_1_TARGET) \ $(libc_kNIX_asm_1_TARGET) ifdef CFG_LIBC_LOGSTRICT_LIBS LIBRARIES += libc_asm_l libc_asm_l_TEMPLATE = libcasm.logstrict libc_asm_l_SOURCES = \ $(libc_frontend_asm_l_1_TARGET) \ $(libc_kNIX_asm_l_1_TARGET) endif ifdef CFG_LIBC_PROFILED_LIBS LIBRARIES += libc_asm_p libc_asm_p_TEMPLATE = libcasm.profiled libc_asm_p_SOURCES = \ $(libc_frontend_asm_p_1_TARGET) \ $(libc_kNIX_asm_p_1_TARGET) endif # # The shared library / so. # DLLS.os2 += libc07 libc07_TEMPLATE = libc libc07_TOOL = GCC3 libc07_TOOL.os2 = GCC3OMF libc07_SOURCES = \ $(PATH_TARGET)/dll0hi.obj \ $(PATH_TARGET)/libc.def libc07_LDFLAGS = -g -Zomf -nostdlib libc07_LIBS = \ $(libc_s_1_TARGET) \ $(libc_asm_1_TARGET) \ $(libos2_unicode_lazy_1_TARGET) \ $(libos2_1_TARGET) \ $(KLIBC_LIB_ALIAS) \ gcc \ gcc_eh \ lazyimp \ end ifdef CFG_LIBC_LOGSTRICT_LIBS DLLS.os2 += libc07.logstrict libc07.logstrict_TEMPLATE = libc.logstrict libc07.logstrict_TOOL = GCC3 libc07.logstrict_TOOL.os2 = GCC3OMF libc07.logstrict_SOURCES = \ $(PATH_TARGET)/dll0hi.obj \ $(PATH_TARGET)/libc.def libc07.logstrict_LDFLAGS = -g -Zomf -nostdlib libc07.logstrict_LIBS = \ $(libc_s_l_1_TARGET) \ $(libc_asm_l_1_TARGET) \ $(libos2_unicode_lazy_1_TARGET) \ $(libos2_l_1_TARGET) \ $(KLIBC_LIB_ALIAS) \ gcc \ gcc_eh \ lazyimp \ end endif ifdef CFG_LIBC_PROFILED_LIBS #DLLS.os2 += libc07.profiled libc07.profiled_TEMPLATE = libc.profiled libc07.profiled_TOOL = GCC3 libc07.profiled_TOOL.os2 = GCC3OMF libc07.profiled_SOURCES = \ $(PATH_TARGET)/dll0hi.obj \ $(PATH_TARGET)/libc.profiled.def libc07.profiled_LDFLAGS = -g -Zomf -nostdlib libc07.profiled_LIBS = \ $(libc_s_p_1_TARGET) \ $(libc_asm_p_1_TARGET) \ $(libos2_unicode_lazy_1_TARGET) \ $(libos2_p_1_TARGET) \ $(KLIBC_LIB_ALIAS) \ gcc \ gcc_eh \ lazyimp \ end ## @todo fix the .def file. ## @todo Use kProfile2. endif ## @todo electric fence heap # # The shared library / so. # IMPORT_LIBS.os2 += libc_dll libc_dll_TEMPLATE = libc libc_dll_SOURCES = \ $(PATH_TARGET)/libc.def libc_dll_SOURCES.os2 = \ src/libc/startup/os2/dllinit-os2.c # todo add socket ++. # # The export definition file. # $(PATH_TARGET)/libc.def: \ $$(libc_s_1_TARGET) \ $$(PATH_LIBC_SRC)/libc/libc.def $(RM) -f $@ $@.tmp.def $(APPEND) $@.tmp.def "LIBRARY libc07 INITINSTANCE TERMINSTANCE" $(APPEND) $@.tmp.def "DESCRIPTION 'kLIBC - C runtime library version 0.7'" $(APPEND) $@.tmp.def "DATA MULTIPLE" $(APPEND) $@.tmp.def "CODE SHARED" $(APPEND) $@.tmp.def "EXPORTS" emxexp $(libc_s_1_TARGET) \ | $(SED) -e "/\"___pfn/d" -e "/\"__sys_/d" -e "/\"___sys_/d" -e "/\"___libc_[a-z]/d" -e "/\"__nsyy/d" \ >> $@.tmp.def cmd /c " $(PATH_LIBC_SRC)/libc/dlllegacy.cmd -e "_DLL_InitTerm" $@.tmp.def $(PATH_LIBC_SRC)/libc/libc.def " $(MV) -f $@.tmp.def $@ ifdef CFG_LIBC_PROFILED_LIBS $(PATH_TARGET)/libc.profiled.def: $(PATH_TARGET)/libc.def $(RM) -f $@ $@.tmp $(CP) $< $@.tmp $(APPEND) $@.tmp "" $(APPEND) $@.tmp "IMPORTS" $(APPEND) $@.tmp " __mcount = KPROFILE.3" $(APPEND) $@.tmp "" $(MV) -f $@.tmp $@ endif # # Headers # headers_TEMPLATE = usr.include headers_SOURCES = \ $(foreach hdr, $(filter-out libc-alias.h,$(wildcard include/*.h))\ ,$(hdr)=>$(subst include/,,$(hdr))) \ $(foreach hdr, $(wildcard include/386/*.h), $(hdr)=>$(subst include/,,$(hdr))) \ $(foreach hdr, $(wildcard include/arpa/*.h), $(hdr)=>$(subst include/,,$(hdr))) \ $(foreach hdr, $(wildcard include/emx/*.h), $(hdr)=>$(subst include/,,$(hdr))) \ $(foreach hdr, $(wildcard include/InnoTekLIBC/*.h), $(hdr)=>$(subst include/,,$(hdr))) \ $(foreach hdr, $(wildcard include/klibc/*.h), $(hdr)=>$(subst include/,,$(hdr))) \ $(foreach hdr, $(wildcard include/klibc/*/*.h), $(hdr)=>$(subst include/,,$(hdr))) \ $(foreach hdr, $(wildcard include/machine/*.h), $(hdr)=>$(subst include/,,$(hdr))) \ $(foreach hdr, $(wildcard include/net/*.h), $(hdr)=>$(subst include/,,$(hdr))) \ $(foreach hdr, $(wildcard include/netinet/*.h), $(hdr)=>$(subst include/,,$(hdr))) \ $(foreach hdr, $(wildcard include/protocol/*.h), $(hdr)=>$(subst include/,,$(hdr))) \ $(foreach hdr, $(wildcard include/protocols/*.h), $(hdr)=>$(subst include/,,$(hdr))) \ $(foreach hdr, $(wildcard include/sys/*.h), $(hdr)=>$(subst include/,,$(hdr))) \ # # libc_alias - The alias lib is special, see alias.kmk. # libc_alias_TEMPLATE = usr.lib libc_alias_SOURCES = \ $(KLIBC_LIB_ALIAS) # # The startup files. # # kBuild doesn't have a concept for object targets yet. This doens't # bother us too much since we need to generate a lot of different objects # from the same source files anyway. # # Note that dependencies are not complete for the crt/dll*.o[bj] files. # startupobjs_TEMPLATE = usr.lib startupobjs_SOURCES := ifeq ($(BUILD_TARGET),os2) ifdef CFG_LIBC_USE_WATCOM define def_startup $(PATH_TARGET)/crt0$(i).obj: src/libc/startup/os2/x86/crt0.asm | $(call DIRDEP,$(PATH_TARGET)) $(RM) -f $$@ $$(TOOL_$$(TEMPLATE_libcasm_ASTOOL)_AS) $(TEMPLATE_libcasm_ASFLAGS) -Iinclude/ \ $(addprefix -D,$(DEFS) $(ASDEFS) $(DEFS.$(KBUILD_TARGET)) $(ASDEFS.$(KBUILD_TARGET)) ) \ $(subst wild, -DARGS_WILD, \ $(subst resp, -DARGS_RESP, \ $(subst noux, -DNOUNIX, \ $(subst nofork, -DNOFORK, \ $(subst hi, -DHIGHMEM, $i) )))) \ -o $$@ \ $$< $$(eval startupobjs_SOURCES += $(PATH_TARGET)/crt0$(i).obj) ifeq ($(subst resp,,$(subst wild,,$(i))),$(i)) $(PATH_TARGET)/dll0$(i).obj: src/libc/startup/os2/x86/dll0.asm | $(call DIRDEP,$(PATH_TARGET)) $(RM) -f $$@ $$(TOOL_$$(TEMPLATE_libcasm_ASTOOL)_AS) $(TEMPLATE_libcasm_ASFLAGS) -Iinclude/ \ $(addprefix -D,$(DEFS) $(ASDEFS) $(DEFS.$(KBUILD_TARGET)) $(ASDEFS.$(KBUILD_TARGET)) ) \ $(subst wild, -DARGS_WILD, \ $(subst resp, -DARGS_RESP, \ $(subst noux, -DNOUNIX, \ $(subst nofork, -DNOFORK, \ $(subst hi, -DHIGHMEM, $i) )))) \ -o $$@ \ $$< $$(eval startupobjs_SOURCES += $(PATH_TARGET)/dll0$(i).obj) endif endef # def_startup else # !CFG_LIBC_USE_WATCOM define def_startup $(PATH_TARGET)/crt0$(i).o: src/libc/startup/os2/x86/crt0.s | $(call DIRDEP,$(PATH_TARGET)) $(RM) -f $$@ $$@bj gcc -c -Iinclude -x assembler-with-cpp \ $(subst wild, -DARGS_WILD, \ $(subst resp, -DARGS_RESP, \ $(subst noux, -DNOUNIX, \ $(subst nofork, -DNOFORK, \ $(subst hi, -DHIGHMEM, $i) )))) \ -o $$@ \ $$< $$(eval startupobjs_SOURCES += $(PATH_TARGET)/crt0$(i).o) ifeq ($(BUILD_TARGET),os2) $(PATH_TARGET)/crt0$(i).obj: $(PATH_TARGET)/crt0$(i).o emxomf -m__text -o $$@ $$< $$(eval startupobjs_SOURCES += $(PATH_TARGET)/crt0$(i).obj) endif ifeq ($(subst resp,,$(subst wild,,$(i))),$(i)) $(PATH_TARGET)/dll0$(i).o: src/libc/startup/os2/x86/dll0.s | $(call DIRDEP,$(PATH_TARGET)) $(RM) -f $$@ $$@bj gcc -c -Iinclude -x assembler-with-cpp \ $(subst wild, -DARGS_WILD, \ $(subst resp, -DARGS_RESP, \ $(subst noux, -DNOUNIX, \ $(subst nofork, -DNOFORK, \ $(subst hi, -DHIGHMEM, $i) )))) \ -o $$@ \ $$< $$(eval startupobjs_SOURCES += $(PATH_TARGET)/dll0$(i).o) ifeq ($(BUILD_TARGET),os2) $(PATH_TARGET)/dll0$(i).obj: $(PATH_TARGET)/dll0$(i).o emxomf -l__text -o $$@ $$< $$(eval startupobjs_SOURCES += $(PATH_TARGET)/dll0$(i).obj) endif endif endef # def_startup endif # !CFG_LIBC_USE_WATCOM # generate i:= $(eval $(def_startup)) $(foreach i,\ hi \ hinofork \ hinoforknoux \ hinoforknouxwild \ hinoforknouxwildresp \ hinoforknouxresp \ hinoforkwild \ hinoforkwildresp \ hinoforkresp \ hinoux \ hinouxwild \ hinouxwildresp \ hinouxresp \ hiwild \ hiwildresp \ hiresp \ \ nofork \ noforknoux \ noforknouxwild \ noforknouxwildresp \ noforknouxresp \ noforkwild \ noforkwildresp \ noforkresp \ \ noux \ nouxwild \ nouxwildresp \ nouxresp \ \ wild \ wildresp \ \ resp \ ,$(eval $(def_startup))) endif # os2 ifeq ($(BUILD_TARGET),nt) startupobjs_SOURCES += $(PATH_TARGET)/crt0.o $(PATH_TARGET)/crt0.o: src/libc/startup/nt/x86/crt0.s $(RM) -f $@ gcc -c -Iinclude -x assembler-with-cpp \ -o $@ \ $< endif # binmode ifdef CFG_LIBC_USE_WATCOM $(PATH_TARGET)/binmode.obj: src/libc/io/386/binmode.asm $(RM) -f $@ $(TOOL_$(TEMPLATE_libcasm_ASTOOL)_AS) $(TEMPLATE_libcasm_ASFLAGS) -Iinclude/ \ $(addprefix -D,$(DEFS) $(ASDEFS) $(DEFS.$(KBUILD_TARGET)) $(ASDEFS.$(KBUILD_TARGET)) ) \ -o $@ $< startupobjs_SOURCES += $(PATH_TARGET)/binmode.obj else $(PATH_TARGET)/binmode.o: src/libc/io/386/binmode.s gcc -c -o $@ $< startupobjs_SOURCES += $(PATH_TARGET)/binmode.o ifdef ($(BUILD_TARGET),os2) $(PATH_TARGET)/binmode.obj: $(PATH_TARGET)/binmode.o emxomf -o $@ $< startupobjs_SOURCES += $(PATH_TARGET)/binmode.obj endif endif # an alias startup: $(startupobjs_SOURCES) # Let kBuild generate the rules. include $(PATH_KBUILD)/subfooter.kmk # # Generate the STD wrappers. # _STD_SOURCE_EXTRAS := \ $(PATH_LIBC_SRC)/msun/std-complex.c \ $(PATH_LIBC_SRC)/msun/std-math.c \ \ $(PATH_LIBC_SRC)/glibc/posix/regcomp.c \ $(PATH_LIBC_SRC)/glibc/posix/regexec.c \ $(PATH_LIBC_SRC)/glibc/posix/regex_internal.c \ _STD_SOURCE_VARS := \ $(foreach sublib,$(LIBC_LIBRARIES), \ $(sublib)_SOURCES \ $(sublib)_SOURCES.$(BUILD_TARGET) \ $(sublib)_SOURCES.$(BUILD_TARGET_ARCH) \ $(sublib)_SOURCES.$(BUILD_TARGET_CPU)\ ) # # We're creating a timestamp file early on in the build process. # (std-update is a phony target for doing this.) # $(PATH_TARGET)/libc-std.ts std-update: \ $(foreach var, $(_STD_SOURCE_VARS), $(filter %.c %.s %.S,$($(var)))) $(_STD_SOURCE_EXTRAS)\ | $(call DIRDEP,$(PATH_TARGET)) $(RM) -f $(PATH_TARGET)/libc-std.ts $(PATH_TARGET)/libc-std.files $(PATH_TARGET)/libc-std.tmp.h $(foreach src, $^\ ,$(NL)$(TAB)@$(APPEND) $(PATH_TARGET)/libc-std.files "$(src)") ifeq ($(BUILD_PLATFORM),os2) $(LIBC_GAWK) -f ./mkstd.awk @$(PATH_TARGET)/libc-std.files > $(PATH_TARGET)/libc-std.tmp.h else cd src && $(LIBC_GAWK) -f ../mkstd.awk $(subst $(PATH_LIBC_SRC)/,,$^) > $(PATH_TARGET)/libc-std.tmp.h endif if $(LIBC_DIFF) $(PATH_TARGET)/libc-std.tmp.h $(PATH_TARGET)/libc-std.h > /dev/null 2> /dev/null; then \ echo "* libc-std.h unchanged"; \ else \ $(CP_EXT) $(PATH_TARGET)/libc-std.tmp.h $(PATH_TARGET)/libc-std.h; \ echo "* libc-std.h updated"; \ fi $(APPEND) $(PATH_TARGET)/libc-std.ts done # # Create non-existing libc-std.h. # $(PATH_TARGET)/libc-std.h: $(MAKE) std-update # # Generate the aliases. # $(KLIBC_LIB_ALIAS): $(PATH_TARGET)/libc-std.h | $(LIBC_GENALIAS) $(MAKE) -f alias.kmk libraries aliases: $(KLIBC_LIB_ALIAS)