| 1 | #
|
|---|
| 2 | # Copyright (c) 2011 Petr Koupy
|
|---|
| 3 | # Copyright (c) 2011 Jiri Zarevucky
|
|---|
| 4 | # All rights reserved.
|
|---|
| 5 | #
|
|---|
| 6 | # Redistribution and use in source and binary forms, with or without
|
|---|
| 7 | # modification, are permitted provided that the following conditions
|
|---|
| 8 | # are met:
|
|---|
| 9 | #
|
|---|
| 10 | # - Redistributions of source code must retain the above copyright
|
|---|
| 11 | # notice, this list of conditions and the following disclaimer.
|
|---|
| 12 | # - Redistributions in binary form must reproduce the above copyright
|
|---|
| 13 | # notice, this list of conditions and the following disclaimer in the
|
|---|
| 14 | # documentation and/or other materials provided with the distribution.
|
|---|
| 15 | # - The name of the author may not be used to endorse or promote products
|
|---|
| 16 | # derived from this software without specific prior written permission.
|
|---|
| 17 | #
|
|---|
| 18 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 19 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 20 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 21 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 22 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 23 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 27 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 28 | #
|
|---|
| 29 |
|
|---|
| 30 | USPACE_PREFIX = ../..
|
|---|
| 31 | LIBRARY = libposix
|
|---|
| 32 |
|
|---|
| 33 | EXTRA_CFLAGS = -Iinclude/
|
|---|
| 34 |
|
|---|
| 35 | INCLUDE_LIBC = ./include/libc
|
|---|
| 36 |
|
|---|
| 37 | SPECS = gcc.specs
|
|---|
| 38 | LIBC_LINKER_SCRIPT = $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld
|
|---|
| 39 | LIBC_STARTUP_FILE = $(shell sed -n -e 's/^.*STARTUP(\(.*\)).*$$/\1/p' $(LIBC_LINKER_SCRIPT))
|
|---|
| 40 | EXPORT_LINKER_SCRIPT = link.ld
|
|---|
| 41 | EXPORT_STARTUP_FILE = crt0.o
|
|---|
| 42 |
|
|---|
| 43 | EXPORT_FILES = \
|
|---|
| 44 | ../math/libmath.a \
|
|---|
| 45 | ../clui/libclui.a \
|
|---|
| 46 | $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a \
|
|---|
| 47 | $(LIBSOFTINT_PREFIX)/libsoftint.a \
|
|---|
| 48 | $(LIBC_PREFIX)/libc.a \
|
|---|
| 49 | $(LIBRARY).a \
|
|---|
| 50 | $(EXPORT_STARTUP_FILE) \
|
|---|
| 51 | $(EXPORT_LINKER_SCRIPT) \
|
|---|
| 52 | $(SPECS)
|
|---|
| 53 |
|
|---|
| 54 | PRE_DEPEND = $(INCLUDE_LIBC)
|
|---|
| 55 | EXTRA_CLEAN = $(INCLUDE_LIBC)
|
|---|
| 56 |
|
|---|
| 57 | EXTRA_OUTPUT = $(SPECS) $(EXPORT_LINKER_SCRIPT) $(EXPORT_STARTUP_FILE)
|
|---|
| 58 |
|
|---|
| 59 | SOURCES = \
|
|---|
| 60 | src/ctype.c \
|
|---|
| 61 | src/dlfcn.c \
|
|---|
| 62 | src/fcntl.c \
|
|---|
| 63 | src/fnmatch.c \
|
|---|
| 64 | src/locale.c \
|
|---|
| 65 | src/pthread/condvar.c \
|
|---|
| 66 | src/pthread/keys.c \
|
|---|
| 67 | src/pthread/mutex.c \
|
|---|
| 68 | src/pthread/threads.c \
|
|---|
| 69 | src/pwd.c \
|
|---|
| 70 | src/signal.c \
|
|---|
| 71 | src/stdio.c \
|
|---|
| 72 | src/stdlib.c \
|
|---|
| 73 | src/stdlib/strtold.c \
|
|---|
| 74 | src/string.c \
|
|---|
| 75 | src/strings.c \
|
|---|
| 76 | src/sys/mman.c \
|
|---|
| 77 | src/sys/stat.c \
|
|---|
| 78 | src/sys/wait.c \
|
|---|
| 79 | src/time.c \
|
|---|
| 80 | src/unistd.c
|
|---|
| 81 |
|
|---|
| 82 | TEST_SOURCES = \
|
|---|
| 83 | test/main.c \
|
|---|
| 84 | test/scanf.c
|
|---|
| 85 |
|
|---|
| 86 | EXPORT_CPPFLAGS = \
|
|---|
| 87 | -specs $$(HELENOS_EXPORT_ROOT)/lib/gcc.specs \
|
|---|
| 88 | -isystem $$(HELENOS_EXPORT_ROOT)/include
|
|---|
| 89 |
|
|---|
| 90 | EXPORT_LDFLAGS = \
|
|---|
| 91 | -L$$(HELENOS_EXPORT_ROOT)/lib \
|
|---|
| 92 | -T link.ld
|
|---|
| 93 |
|
|---|
| 94 | EXPORT_LDLIBS = \
|
|---|
| 95 | -Wl,--start-group -lposix -lmath -lc -lsoftfloat -lsoftint -Wl,--end-group
|
|---|
| 96 |
|
|---|
| 97 | EXPORT_CFLAGS = \
|
|---|
| 98 | -specs $$(HELENOS_EXPORT_ROOT)/lib/gcc.specs
|
|---|
| 99 |
|
|---|
| 100 | include $(USPACE_PREFIX)/Makefile.common
|
|---|
| 101 |
|
|---|
| 102 | $(SPECS): $(CONFIG_MAKEFILE)
|
|---|
| 103 | echo '*self_spec:' > $@.new
|
|---|
| 104 | echo '+ $(COMMON_CFLAGS)' >> $@.new
|
|---|
| 105 | echo >> $@.new
|
|---|
| 106 | echo '*cpp:' >> $@.new
|
|---|
| 107 | echo '+ $(COMMON_CPPFLAGS)' >> $@.new
|
|---|
| 108 | echo >> $@.new
|
|---|
| 109 | echo '*lib:' >> $@.new
|
|---|
| 110 | echo '$(EXPORT_LDLIBS)' >> $@.new
|
|---|
| 111 | mv $@.new $@
|
|---|
| 112 |
|
|---|
| 113 | $(EXPORT_LINKER_SCRIPT): $(LIBC_LINKER_SCRIPT)
|
|---|
| 114 | sed 's/STARTUP(.*)/STARTUP(crt0.o)/' $< > $@
|
|---|
| 115 |
|
|---|
| 116 | $(EXPORT_STARTUP_FILE): $(LIBC_STARTUP_FILE)
|
|---|
| 117 | cp $< $@
|
|---|
| 118 |
|
|---|
| 119 | $(INCLUDE_LIBC): $(shell find ../c/include -name '*.h')
|
|---|
| 120 | cp -r -L --remove-destination -T ../c/include $@
|
|---|
| 121 | find ../c/include -type f -and -not -name '*.h' -delete
|
|---|
| 122 |
|
|---|
| 123 | export: $(EXPORT_DIR)/config.mk $(EXPORT_DIR)/config.rc
|
|---|
| 124 |
|
|---|
| 125 | $(EXPORT_DIR)/config.mk: export-libs export-includes
|
|---|
| 126 | echo '# Generated file, do not modify.' >> $@.new
|
|---|
| 127 | echo '# Do not forget to set HELENOS_EXPORT_ROOT.' >> $@.new
|
|---|
| 128 | echo 'HELENOS_CROSS_PATH="$(shell dirname "$(CC)")"' >> $@.new
|
|---|
| 129 | echo 'HELENOS_ARCH="$(firstword $(subst -, ,$(TARGET)))"' >> $@.new
|
|---|
| 130 | echo 'HELENOS_TARGET="$(TARGET)"' >> $@.new
|
|---|
| 131 | echo 'HELENOS_CPPFLAGS="$(EXPORT_CPPFLAGS)"' >> $@.new
|
|---|
| 132 | echo 'HELENOS_CFLAGS="$(EXPORT_CFLAGS)"' >> $@.new
|
|---|
| 133 | echo 'HELENOS_CXXFLAGS="$(EXPORT_CFLAGS)"' >> $@.new
|
|---|
| 134 | echo 'HELENOS_LDFLAGS="$(EXPORT_LDFLAGS)"' >> $@.new
|
|---|
| 135 | echo 'HELENOS_LDLIBS="$(EXPORT_LDLIBS)"' >> $@.new
|
|---|
| 136 | mv $@.new $@
|
|---|
| 137 |
|
|---|
| 138 | $(EXPORT_DIR)/config.rc: $(EXPORT_DIR)/config.mk
|
|---|
| 139 | sed 's:$$(HELENOS_EXPORT_ROOT):$$HELENOS_EXPORT_ROOT:g' < $< >$@
|
|---|
| 140 |
|
|---|
| 141 | export-libs: $(EXPORT_FILES) export-includes
|
|---|
| 142 | mkdir -p $(EXPORT_DIR)/lib
|
|---|
| 143 | cp -L $(EXPORT_FILES) $(EXPORT_DIR)/lib
|
|---|
| 144 |
|
|---|
| 145 | export-includes: $(INCLUDE_LIBC) $(shell find ./include ../c/arch/$(UARCH)/include $(ROOT_PATH)/abi/include -name '*.h')
|
|---|
| 146 | mkdir -p $(EXPORT_DIR)/include
|
|---|
| 147 | rm -rf $(EXPORT_DIR)/include.new
|
|---|
| 148 | cp -r -L -T ./include/posix $(EXPORT_DIR)/include.new
|
|---|
| 149 | cp -r -L -T ./include/libc $(EXPORT_DIR)/include.new/libc
|
|---|
| 150 | cp -r -L ../c/arch/$(UARCH)/include/* $(EXPORT_DIR)/include.new/libc
|
|---|
| 151 | cp -r -L $(ROOT_PATH)/abi/include/* $(EXPORT_DIR)/include.new
|
|---|
| 152 | mkdir -p $(EXPORT_DIR)/include.new/libclui
|
|---|
| 153 | cp -L ../clui/tinput.h $(EXPORT_DIR)/include.new/libclui
|
|---|
| 154 |
|
|---|
| 155 | find "$(EXPORT_DIR)/include.new/libc" "$(EXPORT_DIR)/include.new/libclui" -name '*.h' -exec sed \
|
|---|
| 156 | -e 's:#include <:#include <libc/:' \
|
|---|
| 157 | -e 's:#include <libc/abi/:#include <abi/:' \
|
|---|
| 158 | -e 's:#include <libc/_bits/:#include <_bits/:' \
|
|---|
| 159 | -e 's:#include <libc/libc/:#include <libc/:' \
|
|---|
| 160 | -i {} \;
|
|---|
| 161 | find "$(EXPORT_DIR)/include.new" -name '*.h' -exec sed \
|
|---|
| 162 | -e 's:#include "posix/:#include ":' \
|
|---|
| 163 | -e 's:#include <posix/:#include <:' \
|
|---|
| 164 | -i {} \;
|
|---|
| 165 |
|
|---|
| 166 | rm -rf $(EXPORT_DIR)/include
|
|---|
| 167 | mv $(EXPORT_DIR)/include.new $(EXPORT_DIR)/include
|
|---|