Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/Makefile.common

    r664af708 r0feaae4  
    4040#   BINARY         (/) binary output name (like appname)
    4141#   LIBRARY        (/) library output name (like libname)
     42#
    4243#   EXTRA_OUTPUT       additional output targets
    4344#   EXTRA_CLEAN        additional cleanup targets
     45#
     46# Optionally, for a binary:
     47#   STATIC_NEEDED      set to 'y' for init binaries, will build statically
     48#                      linked version
     49#   STATIC_ONLY        set to 'y' if binary cannot be linked dynamically
     50#                      (e.g. uses thread-local variables)
     51#
     52# Optionally, for a libary:
     53#   SLIBRARY           Name with full version, e.g. libfoo.so.0.0
     54#   LSONAME            Soname / name with short version, e.g. libfoo.so.0
    4455#
    4556# (x) required variables
     
    7384endif
    7485
     86ifeq ($(CONFIG_BUILD_SHARED_LIBS), y)
     87        ifneq ($(SLIBRARY),)
     88                LARCHIVE = $(LIBRARY).la
     89                LOUTPUT = $(SLIBRARY)
     90                EXTRA_OUTPUT += $(LOUTPUT).disasm $(LIBRARY).so $(LSONAME)
     91                EXTRA_CLEAN += $(LOUTPUT).map $(LOUTPUT).ldisasm \
     92                    $(LIBC_PREFIX)/shared/arch/$(UARCH)/_lib.ld \
     93                    $(LIBRARY).so $(LSONAME)
     94        endif
     95endif
     96
    7597DEPEND = Makefile.depend
    7698DEPEND_PREV = $(DEPEND).prev
     
    86108LIBCLUI_PREFIX = $(LIB_PREFIX)/clui
    87109
     110LIBEXT2_PREFIX = $(LIB_PREFIX)/ext2
     111
     112LIBUSB_PREFIX = $(LIB_PREFIX)/usb
     113LIBUSBHOST_PREFIX = $(LIB_PREFIX)/usbhost
     114LIBUSBDEV_PREFIX = $(LIB_PREFIX)/usbdev
     115LIBUSBHID_PREFIX = $(LIB_PREFIX)/usbhid
     116LIBUSBVIRT_PREFIX = $(LIB_PREFIX)/usbvirt
     117
    88118LIBDRV_PREFIX = $(LIB_PREFIX)/drv
    89119LIBPACKET_PREFIX = $(LIB_PREFIX)/packet
    90120LIBNET_PREFIX = $(LIB_PREFIX)/net
    91121
     122LIBSCSI_PREFIX = $(LIB_PREFIX)/scsi
     123
     124ifeq ($(STATIC_NEEDED),y)
     125        STATIC_BUILD = y
     126else
     127        ifeq ($(STATIC_ONLY),y)
     128                STATIC_BUILD = y
     129        else
     130                ifeq ($(CONFIG_USE_SHARED_LIBS), y)
     131                        STATIC_BUILD = n
     132                else
     133                        STATIC_BUILD = y
     134                endif
     135        endif
     136endif
     137
     138# Build static whenever we use libusb because that library uses
     139# thread local variables
     140ifneq ($(findstring usb, $(LIBS)),)
     141        STATIC_BUILD = y
     142endif
     143
     144ifeq ($(STATIC_BUILD), y)
    92145BASE_LIBS = $(LIBC_PREFIX)/libc.a $(LIBSOFTINT_PREFIX)/libsoftint.a
    93 
    94146LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld
     147else
     148BASE_LIBS = $(LIBC_PREFIX)/libc.so0 $(LIBSOFTINT_PREFIX)/libsofti.so0
     149LFLAGS = -Bdynamic
     150LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link-dlexe.ld
     151endif
    95152
    96153ifeq ($(CONFIG_OPTIMIZE_FOR_SIZE),y)
     
    102159.PHONY: all clean
    103160
    104 all: $(VERSION_DEF) $(COMMON_MAKEFILE) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(LIBS) $(OUTPUT) $(EXTRA_OUTPUT)
     161all: $(VERSION_DEF) $(COMMON_MAKEFILE) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(LIBS) $(OUTPUT) $(LOUTPUT) $(EXTRA_OUTPUT)
    105162        -[ -f $(DEPEND) ] && cp -a $(DEPEND) $(DEPEND_PREV)
    106163
    107164clean:
    108         rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(EXTRA_OUTPUT) $(EXTRA_CLEAN)
     165        rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(LARCHIVE) $(LOUTPUT) $(EXTRA_OUTPUT) $(EXTRA_CLEAN)
    109166        find . -name '*.o' -follow -exec rm \{\} \;
     167        find . -name '*.lo' -follow -exec rm \{\} \;
    110168
    111169GCC_CFLAGS = -I$(LIBC_PREFIX)/include -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
     
    113171        -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
    114172        -Wall -Wextra -Wno-clobbered -Wno-unused-parameter -Wmissing-prototypes \
    115         -Werror-implicit-function-declaration -Wwrite-strings \
     173        -std=gnu99 -Werror-implicit-function-declaration -Wwrite-strings \
    116174        -pipe -g -D__$(ENDIANESS)__
    117175
     
    130188        -pipe -g -arch $(CLANG_ARCH) -D__$(ENDIANESS)__
    131189
     190LIB_CFLAGS = $(CFLAGS) -fPIC -D__IN_SHARED_LIBC__
     191LIB_LFLAGS = $(LFLAGS) -shared -soname $(LSONAME) --whole-archive
     192
    132193ifeq ($(CONFIG_DEBUG),y)
    133194        GCC_CFLAGS += -Werror
     
    175236
    176237OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
     238LOBJECTS := $(addsuffix .lo,$(basename $(SOURCES)))
    177239
    178240ifneq ($(BINARY),)
     
    185247
    186248$(BINARY): $(LINKER_SCRIPT) $(OBJECTS) $(LIBS) $(BASE_LIBS)
    187         $(LD) -N $(LFLAGS) -T $(LINKER_SCRIPT) -M -Map $(BINARY).map -o $(BINARY) $(OBJECTS) $(LIBS) $(BASE_LIBS)
     249        $(LD) -n $(LFLAGS) -T $(LINKER_SCRIPT) -M -Map $(BINARY).map -o $(BINARY) $(OBJECTS) $(LIBS) $(BASE_LIBS)
    188250ifeq ($(CONFIG_STRIP_BINARIES),y)
    189251        $(STRIP) $(BINARY)
    190252endif
     253endif
     254
     255ifneq ($(SLIBRARY),)
     256%.disasm: $(LOUTPUT)
     257ifeq ($(CONFIG_LINE_DEBUG),y)
     258        $(OBJDUMP) -d -S $< > $@
     259else
     260        $(OBJDUMP) -d $< > $@
     261endif
     262
     263$(LOUTPUT): $(LARCHIVE) $(LIBC_PREFIX)/arch/$(UARCH)/_link-shlib.ld
     264        $(LD) -T $(LIBC_PREFIX)/arch/$(UARCH)/_link-shlib.ld $(LIB_LFLAGS) $(LARCHIVE) -o $@ -Map $(LOUTPUT).map
     265
     266$(LIBRARY).so:
     267        ln -s $(SLIBRARY) $@
     268
     269$(LSONAME):
     270        ln -s $(SLIBRARY) $@
    191271endif
    192272
     
    196276endif
    197277
     278ifneq ($(SLIBRARY),)
     279%.la: $(LOBJECTS)
     280        $(AR) rc $@ $(LOBJECTS)
     281endif
     282
    198283%.o: %.S $(DEPEND)
    199284        $(CC) $(DEFS) $(CFLAGS) -D__ASM__ -c $< -o $@
     
    210295%.o: %.c $(DEPEND)
    211296        $(CC) $(DEFS) $(CFLAGS) -c $< -o $@
     297ifeq ($(PRECHECK),y)
     298        $(JOBFILE) $(JOB) $< $@ cc core $(DEFS) $(CFLAGS)
     299endif
     300
     301%.lo: %.S $(DEPEND)
     302        $(CC) $(DEFS) $(LIB_CFLAGS) -D__ASM__ -c $< -o $@
     303ifeq ($(PRECHECK),y)
     304        $(JOBFILE) $(JOB) $< $@ as asm/preproc $(DEFS) $(CFLAGS) -D__ASM__
     305endif
     306
     307%.lo: %.s $(DEPEND)
     308        $(AS) $(AFLAGS) -o $@ $<
     309ifeq ($(PRECHECK),y)
     310        $(JOBFILE) $(JOB) $< $@ as asm
     311endif
     312
     313%.lo: %.c $(DEPEND)
     314        $(CC) $(DEFS) $(LIB_CFLAGS) -c $< -o $@
    212315ifeq ($(PRECHECK),y)
    213316        $(JOBFILE) $(JOB) $< $@ cc core $(DEFS) $(CFLAGS)
     
    223326$(OUTPUT): $(OBJECTS)
    224327
     328$(LARCHIVE): $(LOBJECTS)
Note: See TracChangeset for help on using the changeset viewer.