Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/Makefile.common

    rafdcc60e r79ae36dd  
    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
     122ifeq ($(STATIC_NEEDED),y)
     123        STATIC_BUILD = y
     124else
     125        ifeq ($(STATIC_ONLY),y)
     126                STATIC_BUILD = y
     127        else
     128                ifeq ($(CONFIG_USE_SHARED_LIBS), y)
     129                        STATIC_BUILD = n
     130                else
     131                        STATIC_BUILD = y
     132                endif
     133        endif
     134endif
     135
     136# Build static whenever we use libusb because that library uses
     137# thread local variables
     138ifneq ($(findstring usb, $(LIBS)),)
     139        STATIC_BUILD = y
     140endif
     141
     142ifeq ($(STATIC_BUILD), y)
    92143BASE_LIBS = $(LIBC_PREFIX)/libc.a $(LIBSOFTINT_PREFIX)/libsoftint.a
    93 
    94144LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld
     145else
     146BASE_LIBS = $(LIBC_PREFIX)/libc.so0 $(LIBSOFTINT_PREFIX)/libsofti.so0
     147LFLAGS = -Bdynamic
     148LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link-dlexe.ld
     149endif
    95150
    96151ifeq ($(CONFIG_OPTIMIZE_FOR_SIZE),y)
     
    102157.PHONY: all clean
    103158
    104 all: $(VERSION_DEF) $(COMMON_MAKEFILE) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(LIBS) $(OUTPUT) $(EXTRA_OUTPUT)
     159all: $(VERSION_DEF) $(COMMON_MAKEFILE) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(LIBS) $(OUTPUT) $(LOUTPUT) $(EXTRA_OUTPUT)
    105160        -[ -f $(DEPEND) ] && cp -a $(DEPEND) $(DEPEND_PREV)
    106161
    107162clean:
    108         rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(EXTRA_OUTPUT) $(EXTRA_CLEAN)
     163        rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(LARCHIVE) $(LOUTPUT) $(EXTRA_OUTPUT) $(EXTRA_CLEAN)
    109164        find . -name '*.o' -follow -exec rm \{\} \;
     165        find . -name '*.lo' -follow -exec rm \{\} \;
    110166
    111167GCC_CFLAGS = -I$(LIBC_PREFIX)/include -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
     
    113169        -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
    114170        -Wall -Wextra -Wno-clobbered -Wno-unused-parameter -Wmissing-prototypes \
    115         -Werror-implicit-function-declaration -Wwrite-strings \
     171        -std=gnu99 -Werror-implicit-function-declaration -Wwrite-strings \
    116172        -pipe -g -D__$(ENDIANESS)__
    117173
     
    130186        -pipe -g -arch $(CLANG_ARCH) -D__$(ENDIANESS)__
    131187
     188LIB_CFLAGS = $(CFLAGS) -fPIC -D__IN_SHARED_LIBC__
     189LIB_LFLAGS = $(LFLAGS) -shared -soname $(LSONAME) --whole-archive
     190
    132191ifeq ($(CONFIG_DEBUG),y)
    133192        GCC_CFLAGS += -Werror
     
    175234
    176235OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
     236LOBJECTS := $(addsuffix .lo,$(basename $(SOURCES)))
    177237
    178238ifneq ($(BINARY),)
     
    191251endif
    192252
     253ifneq ($(SLIBRARY),)
     254%.disasm: $(LOUTPUT)
     255ifeq ($(CONFIG_LINE_DEBUG),y)
     256        $(OBJDUMP) -d -S $< > $@
     257else
     258        $(OBJDUMP) -d $< > $@
     259endif
     260
     261$(LOUTPUT): $(LARCHIVE) $(LIBC_PREFIX)/arch/$(UARCH)/_link-shlib.ld
     262        $(LD) -T $(LIBC_PREFIX)/arch/$(UARCH)/_link-shlib.ld $(LIB_LFLAGS) $(LARCHIVE) -o $@ -Map $(LOUTPUT).map
     263
     264$(LIBRARY).so:
     265        ln -s $(SLIBRARY) $@
     266
     267$(LSONAME):
     268        ln -s $(SLIBRARY) $@
     269endif
     270
    193271ifneq ($(LIBRARY),)
    194272%.a: $(OBJECTS)
     
    196274endif
    197275
     276ifneq ($(SLIBRARY),)
     277%.la: $(LOBJECTS)
     278        $(AR) rc $@ $(LOBJECTS)
     279endif
     280
    198281%.o: %.S $(DEPEND)
    199282        $(CC) $(DEFS) $(CFLAGS) -D__ASM__ -c $< -o $@
     
    210293%.o: %.c $(DEPEND)
    211294        $(CC) $(DEFS) $(CFLAGS) -c $< -o $@
     295ifeq ($(PRECHECK),y)
     296        $(JOBFILE) $(JOB) $< $@ cc core $(DEFS) $(CFLAGS)
     297endif
     298
     299%.lo: %.S $(DEPEND)
     300        $(CC) $(DEFS) $(LIB_CFLAGS) -D__ASM__ -c $< -o $@
     301ifeq ($(PRECHECK),y)
     302        $(JOBFILE) $(JOB) $< $@ as asm/preproc $(DEFS) $(CFLAGS) -D__ASM__
     303endif
     304
     305%.lo: %.s $(DEPEND)
     306        $(AS) $(AFLAGS) -o $@ $<
     307ifeq ($(PRECHECK),y)
     308        $(JOBFILE) $(JOB) $< $@ as asm
     309endif
     310
     311%.lo: %.c $(DEPEND)
     312        $(CC) $(DEFS) $(LIB_CFLAGS) -c $< -o $@
    212313ifeq ($(PRECHECK),y)
    213314        $(JOBFILE) $(JOB) $< $@ cc core $(DEFS) $(CFLAGS)
     
    223324$(OUTPUT): $(OBJECTS)
    224325
     326$(LARCHIVE): $(LOBJECTS)
Note: See TracChangeset for help on using the changeset viewer.