github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/containers/compilers/includeos/cpp/patches/src/Makefile (about)

     1  #################################################
     2  #              IncludeOS makefile               #
     3  #################################################
     4  
     5  ifndef INCLUDEOS_INSTALL
     6  	INCLUDEOS_INSTALL=$(HOME)/IncludeOS_install
     7  	#$(error IncludeOS installation folder not set!)
     8  endif
     9  # shorter name
    10  INSTALL = $(INCLUDEOS_INSTALL)
    11  
    12  STACK_PROTECTOR_VALUE=$(shell date +%s)
    13  # stackrealign is needed to guarantee 16-byte stack alignment for SSE
    14  # the compiler seems to be really dumb in this regard, creating a misaligned stack left and right
    15  CAPABS_COMMON = -mstackrealign -msse3 -fstack-protector-strong -D_STACK_GUARD_VALUE_=$(STACK_PROTECTOR_VALUE)
    16  
    17  # Various global defines
    18  # * NO_DEBUG Disables  output from the debug macro
    19  # * OS_TERMINATE_ON_CONTRACT_VIOLATION provides classic assert-like output from Expects / Ensures
    20  # * _GNU_SOURCE enables POSIX-extensions in newlib, such as strnlen. ("everything newlib has", ref. cdefs.h)
    21  CAPABS = $(CAPABS_COMMON) -DNO_DEBUG=1 -DOS_TERMINATE_ON_CONTRACT_VIOLATION -D_GNU_SOURCE
    22  WARNS   = -Wall -Wextra #-pedantic
    23  DEBUG_OPTS = -ggdb3
    24  
    25  
    26  # External Libraries
    27  ###################################################
    28  LIBC_OBJ = $(INSTALL)/newlib/libc.a
    29  LIBG_OBJ = $(INSTALL)/newlib/libg.a
    30  LIBM_OBJ = $(INSTALL)/newlib/libm.a
    31  
    32  LIBGCC = $(INSTALL)/libgcc/libgcc.a
    33  LIBCXX = $(INSTALL)/libcxx/libc++.a libc++abi.a
    34  
    35  INC_NEWLIB=$(INSTALL)/newlib/include
    36  
    37  # Compiler/Linker
    38  ###################################################
    39  
    40  CC  = $(shell command -v clang-3.8 || command -v clang-3.6)
    41  CPP = $(shell command -v clang++-3.8 || command -v clang++-3.6 || command -v clang++)
    42  # Set defaults if not defined
    43  ifndef AR_INC
    44  	AR_INC = ar
    45  endif
    46  ifndef OBJCOPY_INC
    47  	OBJCOPY_INC=objcopy
    48  endif
    49  
    50  # Compiler options
    51  CCOPTS  = -target i686-elf
    52  CPPOPTS = -target i686-elf
    53  
    54  INCLUDES  = -I../api/sys -I$(INSTALL)/libcxx/include -I$(INC_NEWLIB) -Iinclude -I../api -I../api/posix -I../mod/GSL -I../mod/fiber/include -Ilib -Ilib/mana/include -Ilib/json/rapidjson/include
    55  CINCLUDES = -I../api/sys -I$(INC_NEWLIB) -Iinclude -I../api
    56  
    57  CCOPTS  += $(CAPABS) $(WARNS) -c -m32 -march=i686 $(CINCLUDES)
    58  CPPOPTS += $(CAPABS) $(WARNS) -c -m32 -std=c++14 $(INCLUDES) -D_LIBCPP_HAS_NO_THREADS=1 -DOS_VERSION="\"$(shell git describe --dirty)\""
    59  
    60  # Objects
    61  ###################################################
    62  CXXABI     = $(shell find ./crt/cxxabi -type f -name "*.cpp")
    63  CXXABI_OBJ = $(CXXABI:.cpp=.o)
    64  
    65  OS_OBJECTS = kernel/start.o kernel/kernel_start.o kernel/syscalls.o \
    66  		kernel/interrupts.o kernel/os.o kernel/os_stdout.o kernel/cpuid.o \
    67  		kernel/memmap.o kernel/irq_manager.o kernel/pci_manager.o \
    68  		kernel/service_stub.o kernel/main_call.o\
    69  		kernel/elf.o kernel/terminal.o kernel/terminal_disk.o \
    70  		kernel/vga.o kernel/context.o kernel/context_asm.o kernel/block.o\
    71  		kernel/profile.o kernel/profile_intr.o \
    72  		kernel/timers.o kernel/rtc.o \
    73  		util/memstream.o util/async.o util/statman.o util/logger.o \
    74  		crt/c_abi.o crt/string.o crt/quick_exit.o crt/cxx_abi.o \
    75  		hw/ide.o hw/pit.o hw/pic.o hw/pci_device.o hw/cpu_freq_sampling.o \
    76  		hw/ps2.o hw/serial.o hw/serial1.o hw/cmos.o hw/drive.o \
    77  		hw/acpi.o hw/apic.o hw/apic_timer.o hw/ioapic.o hw/apic_asm.o \
    78  		hw/apic_revenant.o hw/msi.o hw/pci_msi.o \
    79  		virtio/virtio.o virtio/virtio_queue.o \
    80  		net/ethernet/ethernet.o net/inet_common.o net/ip4/arp.o net/ip4/ip4.o \
    81  		net/tcp/tcp.o net/tcp/connection.o net/tcp/connection_states.o \
    82  		net/tcp/rttm.o net/tcp/listener.o \
    83  		net/ip4/icmpv4.o net/ip4/udp.o net/ip4/udp_socket.o \
    84  		net/dns/dns.o net/dns/client.o net/dhcp/dh4client.o \
    85  		net/buffer_store.o net/inet4.o \
    86  		fs/disk.o fs/filesystem.o fs/mbr.o fs/path.o \
    87  		fs/ext4.o fs/fat.o fs/fat_async.o fs/fat_sync.o fs/memdisk.o \
    88  		posix/tcp_fd.o posix/udp_fd.o posix/unistd.o posix/fcntl.o \
    89  		posix/sys/socket.o posix/sys/mman.o posix/arpa/inet.o
    90  		#../mod/fiber/src/barrier.o ../mod/fiber/src/context.o ../mod/fiber/src/condition_variable.o \
    91  		#../mod/fiber/src/fiber.o ../mod/fiber/src/future.o ../mod/fiber/src/properties.o ../mod/fiber/src/mutex.o \
    92  		# ../mod/fiber/src/recursive_mutex.o ../mod/fiber/src/recursive_timed_mutex.o \
    93  		#../mod/fiber/src/recursive_mutex.o ../mod/fiber/src/scheduler.o ../mod/fiber/src/timed_mutex.o
    94  
    95  DRIVERS = drivers/virtioblk.o drivers/virtionet.o drivers/heap_debugging.o
    96  DRIVERS_DEPS = $(DRIVERS:.o=.d)
    97  
    98  PLATFORMS = platforms/unik.o
    99  PLATFORMS_DEPS = $(PLATFORMS:.o=.d)
   100  
   101  CRTI_OBJ = crt/crti.o
   102  CRTN_OBJ = crt/crtn.o
   103  
   104  # Header dependencies (rebuild if header changed)
   105  ###################################################
   106  OS_DEPS = $(OS_OBJECTS:.o=.d)
   107  
   108  .PHONY: all stripped minimal debug silent clean
   109  
   110  # Complete OS build
   111  ###################################################
   112  # A complete build includes:
   113  # - a bootloader
   114  # - an OS library for the service to link against
   115  
   116  all: CAPABS += -O2
   117  all: includeos
   118  	@echo "\n>>> Built OS-library. Install to '"$(INSTALL)"' using 'make install'"
   119  
   120  stripped: CAPABS += -O2
   121  stripped: includeos
   122  
   123  minimal: CAPABS += -Os
   124  minimal: includeos
   125  
   126  # Build like "all" but with debugging output (i.e. the 'debug'-macro) enabled
   127  debug-info: CAPABS += -UNO_DEBUG
   128  debug-info: CAPABS += -DGSL_THROW_ON_CONTRACT_VIOLATION
   129  debug-info: includeos test
   130  
   131  # Build with debugging symbols (OBS: Dramatically increases binary size)
   132  debug: CAPABS += -O0
   133  debug: CCOPTS  += $(DEBUG_OPTS)
   134  debug: CPPOPTS += $(DEBUG_OPTS)
   135  debug: OBJ_LIST += $(LIBG_OBJ)
   136  debug: includeos test
   137  
   138  # Build with debugging symbols + debugging ouput, i.e. "debug" + "debug-info"
   139  debug-all: CAPABS += -O0 -UNO_DEBUG
   140  debug-all: CCOPTS  += $(DEBUG_OPTS)
   141  debug-all: CPPOPTS += $(DEBUG_OPTS)
   142  debug-all: OBJ_LIST += $(LIBG_OBJ)
   143  debug-all: includeos test
   144  
   145  silent: CPPOPTS += -DNO_INFO=1
   146  silent: includeos
   147  
   148  includeos: bootloader multiboot libc++abi.a os.a drivers platforms
   149  
   150  # OS libraries
   151  ###################################################
   152  # OS
   153  libc++abi.a: $(CXXABI_OBJ)
   154  	$(AR_INC) rcs $@ $(CXXABI_OBJ)
   155  
   156  os.a: $(OS_OBJECTS) apic_boot.o
   157  	@echo "\n>> Building the OS library"
   158  	$(AR_INC) rcs $@ $(OS_OBJECTS) apic_boot.o
   159  
   160  drivers: $(DRIVERS)
   161  
   162  platforms: $(PLATFORMS)
   163  
   164  install: drivers platforms bootloader multiboot $(CRTI_OBJ) $(CRTN_OBJ)
   165  	@echo "\n>> Installing IncludeOS"
   166  # API
   167  	cp -r ../api $(INSTALL)/
   168  # Drivers
   169  	mkdir -p $(INSTALL)/drivers
   170  	cp -r drivers/*.o $(INSTALL)/drivers
   171  # Platforms
   172  	mkdir -p $(INSTALL)/platforms
   173  	cp -r platforms/*.o $(INSTALL)/platforms
   174  # Boot related
   175  	cp bootloader $(INSTALL)
   176  	cp boot/multiboot.o $(INSTALL)
   177  # Core libraries
   178  	cp os.a $(INSTALL)
   179  	cp libc++abi.a $(INSTALL)/libcxx
   180  	cp crt/crti.o $(INSTALL)/crt
   181  	cp crt/crtn.o $(INSTALL)/crt
   182  # Linker script
   183  	cp linker.ld $(INSTALL)/
   184  # Memdisk related
   185  	mkdir -p $(INSTALL)/memdisk
   186  	cp memdisk/* $(INSTALL)/memdisk/
   187  # Seed related
   188  	cp seed/service_name.cpp $(INSTALL)
   189  	cp seed/Makefile $(INSTALL)/Makeseed
   190  	cp seed/Makelib $(INSTALL)/Makelib
   191  	cp -r ../seed $(INSTALL)
   192  # External dependencies related
   193  	mkdir -p $(INSTALL)/mod/
   194  	cp -r ../mod/GSL $(INSTALL)/mod
   195  	@echo "\nDone!"
   196  
   197  # Makefile recipes
   198  ###################################################
   199  %.o: %.c
   200  	$(CC) -MMD $(CCOPTS) -o $@ $<
   201  
   202  %.o: %.cpp
   203  	@echo "\n"
   204  	$(CPP) -MMD $(CPPOPTS) -o $@ $<
   205  
   206  %.o: %.s
   207  	@echo "\n"
   208  	$(CPP) $(CPPOPTS) -x assembler-with-cpp $< -o $@
   209  
   210  %.o: %.asm
   211  	nasm -f elf $< -o $@
   212  
   213  # Bootloaders
   214  ###################################################
   215  bootloader: boot/bootloader.asm boot/disk_read_lba.asm
   216  	@echo "\n>> Assembling bootloader"
   217  	nasm -f bin -o bootloader $<
   218  
   219  apic_boot.o: hw/apic_boot.asm
   220  	nasm -f bin -o apic_boot.bin $<
   221  	$(OBJCOPY_INC) -I binary -O elf32-i386 -B i386 apic_boot.bin $@
   222  
   223  multiboot: boot/multiboot.o
   224  
   225  # Etags
   226  ###################################################
   227  etags:
   228  	@echo "\n>> Updating emacs tags "
   229  	- find ../ -name "*.[hc]pp" | grep -v ".*\#.*" | etags -
   230  
   231  
   232  # Cleanup
   233  ###################################################
   234  clean:
   235  	$(RM) $(OS_OBJECTS) $(CXXABI_OBJ) $(OS_DEPS) $(DRIVERS) $(DRIVERS_DEPS) $(PLATFORMS) $(PLATFORMS_DEPS)
   236  	$(RM) os.a libc++abi.a
   237  	$(RM) bootloader apic_boot apic_boot.o boot/multiboot.o
   238  
   239  -include $(OS_DEPS)