| 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 | EXPORT_LINKER_SCRIPT = link.ld
 | 
|---|
| 40 | 
 | 
|---|
| 41 | EXPORT_FILES = \
 | 
|---|
| 42 |         ../math/libmath.a \
 | 
|---|
| 43 |         ../clui/libclui.a \
 | 
|---|
| 44 |         $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a \
 | 
|---|
| 45 |         $(LIBSOFTINT_PREFIX)/libsoftint.a \
 | 
|---|
| 46 |         $(LIBC_PREFIX)/libc.a \
 | 
|---|
| 47 |         $(LIBC_PREFIX)/crt0.o \
 | 
|---|
| 48 |         $(LIBC_PREFIX)/crt1.o \
 | 
|---|
| 49 |         $(LIBRARY).a \
 | 
|---|
| 50 |         $(EXPORT_LINKER_SCRIPT) \
 | 
|---|
| 51 |         $(SPECS)
 | 
|---|
| 52 | 
 | 
|---|
| 53 | PRE_DEPEND = $(INCLUDE_LIBC)
 | 
|---|
| 54 | EXTRA_CLEAN = $(INCLUDE_LIBC)
 | 
|---|
| 55 | 
 | 
|---|
| 56 | EXTRA_OUTPUT = $(SPECS) $(EXPORT_LINKER_SCRIPT) $(EXPORT_STARTUP_FILE)
 | 
|---|
| 57 | 
 | 
|---|
| 58 | SOURCES = \
 | 
|---|
| 59 |         src/ctype.c \
 | 
|---|
| 60 |         src/dlfcn.c \
 | 
|---|
| 61 |         src/fcntl.c \
 | 
|---|
| 62 |         src/fnmatch.c \
 | 
|---|
| 63 |         src/locale.c \
 | 
|---|
| 64 |         src/pthread/condvar.c \
 | 
|---|
| 65 |         src/pthread/keys.c \
 | 
|---|
| 66 |         src/pthread/mutex.c \
 | 
|---|
| 67 |         src/pthread/threads.c \
 | 
|---|
| 68 |         src/pwd.c \
 | 
|---|
| 69 |         src/signal.c \
 | 
|---|
| 70 |         src/stdio.c \
 | 
|---|
| 71 |         src/stdlib.c \
 | 
|---|
| 72 |         src/string.c \
 | 
|---|
| 73 |         src/strings.c \
 | 
|---|
| 74 |         src/sys/mman.c \
 | 
|---|
| 75 |         src/sys/stat.c \
 | 
|---|
| 76 |         src/sys/wait.c \
 | 
|---|
| 77 |         src/time.c \
 | 
|---|
| 78 |         src/unistd.c
 | 
|---|
| 79 | 
 | 
|---|
| 80 | TEST_SOURCES = \
 | 
|---|
| 81 |         test/main.c \
 | 
|---|
| 82 |         test/stdio.c \
 | 
|---|
| 83 |         test/stdlib.c \
 | 
|---|
| 84 |         test/unistd.c
 | 
|---|
| 85 | 
 | 
|---|
| 86 | EXTRA_TEST_CFLAGS = -Wno-deprecated-declarations
 | 
|---|
| 87 | 
 | 
|---|
| 88 | EXPORT_CPPFLAGS = \
 | 
|---|
| 89 |         -specs $$(HELENOS_EXPORT_ROOT)/lib/gcc.specs \
 | 
|---|
| 90 |         -isystem $$(HELENOS_EXPORT_ROOT)/include
 | 
|---|
| 91 | 
 | 
|---|
| 92 | EXPORT_LDFLAGS = \
 | 
|---|
| 93 |         -L$$(HELENOS_EXPORT_ROOT)/lib \
 | 
|---|
| 94 |         -T link.ld \
 | 
|---|
| 95 |         $$(HELENOS_EXPORT_ROOT)/lib/crt0.o \
 | 
|---|
| 96 |         $$(HELENOS_EXPORT_ROOT)/lib/crt1.o
 | 
|---|
| 97 | 
 | 
|---|
| 98 | EXPORT_LDLIBS = \
 | 
|---|
| 99 |         -Wl,--start-group -lposix -lmath -lc -lsoftfloat -lsoftint -Wl,--end-group
 | 
|---|
| 100 | 
 | 
|---|
| 101 | EXPORT_CFLAGS = \
 | 
|---|
| 102 |         -specs $$(HELENOS_EXPORT_ROOT)/lib/gcc.specs
 | 
|---|
| 103 | 
 | 
|---|
| 104 | include $(USPACE_PREFIX)/Makefile.common
 | 
|---|
| 105 | 
 | 
|---|
| 106 | $(SPECS): $(CONFIG_MAKEFILE)
 | 
|---|
| 107 |         echo '*self_spec:' > $@.new
 | 
|---|
| 108 |         echo '+ $(COMMON_CFLAGS)' >> $@.new
 | 
|---|
| 109 |         echo >> $@.new
 | 
|---|
| 110 |         echo '*cpp:' >> $@.new
 | 
|---|
| 111 |         echo '+ $(COMMON_CPPFLAGS)' >> $@.new
 | 
|---|
| 112 |         echo >> $@.new
 | 
|---|
| 113 |         echo '*lib:' >> $@.new
 | 
|---|
| 114 |         echo '$(EXPORT_LDLIBS)' >> $@.new
 | 
|---|
| 115 |         mv $@.new $@
 | 
|---|
| 116 | 
 | 
|---|
| 117 | $(EXPORT_LINKER_SCRIPT): $(LIBC_LINKER_SCRIPT)
 | 
|---|
| 118 |         cp $< $@
 | 
|---|
| 119 | 
 | 
|---|
| 120 | $(EXPORT_STARTUP_FILE): $(LIBC_STARTUP_FILE)
 | 
|---|
| 121 |         cp $< $@
 | 
|---|
| 122 | 
 | 
|---|
| 123 | $(INCLUDE_LIBC): $(shell find ../c/include -name '*.h')
 | 
|---|
| 124 |         cp -r -L --remove-destination -T ../c/include $@
 | 
|---|
| 125 |         find ../c/include -type f -and -not -name '*.h' -delete
 | 
|---|
| 126 | 
 | 
|---|
| 127 | export: $(EXPORT_DIR)/config.mk $(EXPORT_DIR)/config.rc
 | 
|---|
| 128 | 
 | 
|---|
| 129 | $(EXPORT_DIR)/config.mk: export-libs export-includes
 | 
|---|
| 130 |         echo '# Generated file, do not modify.' >> $@.new
 | 
|---|
| 131 |         echo '# Do not forget to set HELENOS_EXPORT_ROOT.' >> $@.new
 | 
|---|
| 132 |         echo 'HELENOS_CROSS_PATH="$(shell dirname "$(CC)")"' >> $@.new
 | 
|---|
| 133 |         echo 'HELENOS_ARCH="$(firstword $(subst -, ,$(TARGET)))"' >> $@.new
 | 
|---|
| 134 |         echo 'HELENOS_TARGET="$(TARGET)"' >> $@.new
 | 
|---|
| 135 |         echo 'HELENOS_CPPFLAGS="$(EXPORT_CPPFLAGS)"' >> $@.new
 | 
|---|
| 136 |         echo 'HELENOS_CFLAGS="$(EXPORT_CFLAGS)"' >> $@.new
 | 
|---|
| 137 |         echo 'HELENOS_CXXFLAGS="$(EXPORT_CFLAGS)"' >> $@.new
 | 
|---|
| 138 |         echo 'HELENOS_LDFLAGS="$(EXPORT_LDFLAGS)"' >> $@.new
 | 
|---|
| 139 |         echo 'HELENOS_LDLIBS="$(EXPORT_LDLIBS)"' >> $@.new
 | 
|---|
| 140 |         mv $@.new $@
 | 
|---|
| 141 | 
 | 
|---|
| 142 | $(EXPORT_DIR)/config.rc: $(EXPORT_DIR)/config.mk
 | 
|---|
| 143 |         sed 's:$$(HELENOS_EXPORT_ROOT):$$HELENOS_EXPORT_ROOT:g' < $< >$@
 | 
|---|
| 144 | 
 | 
|---|
| 145 | export-libs: $(EXPORT_FILES) export-includes
 | 
|---|
| 146 |         mkdir -p $(EXPORT_DIR)/lib
 | 
|---|
| 147 |         cp -L $(EXPORT_FILES) $(EXPORT_DIR)/lib
 | 
|---|
| 148 | 
 | 
|---|
| 149 | export-includes: $(INCLUDE_LIBC) $(shell find ./include ../c/arch/$(UARCH)/include $(ROOT_PATH)/abi/include -name '*.h')
 | 
|---|
| 150 |         mkdir -p $(EXPORT_DIR)/include
 | 
|---|
| 151 |         rm -rf $(EXPORT_DIR)/include.new
 | 
|---|
| 152 |         cp -r -L -T ./include/posix $(EXPORT_DIR)/include.new
 | 
|---|
| 153 |         cp -r -L -T ./include/libc $(EXPORT_DIR)/include.new/libc
 | 
|---|
| 154 |         cp -r -L ../c/arch/$(UARCH)/include/* $(EXPORT_DIR)/include.new/libc
 | 
|---|
| 155 |         cp -r -L $(ROOT_PATH)/abi/include/* $(EXPORT_DIR)/include.new
 | 
|---|
| 156 |         mkdir -p $(EXPORT_DIR)/include.new/libclui
 | 
|---|
| 157 |         cp -L ../clui/tinput.h $(EXPORT_DIR)/include.new/libclui
 | 
|---|
| 158 | 
 | 
|---|
| 159 |         find "$(EXPORT_DIR)/include.new/libc" "$(EXPORT_DIR)/include.new/libclui" -name '*.h' -exec sed \
 | 
|---|
| 160 |                 -e 's:#include <:#include <libc/:' \
 | 
|---|
| 161 |                 -e 's:#include <libc/abi/:#include <abi/:' \
 | 
|---|
| 162 |                 -e 's:#include <libc/_bits/:#include <_bits/:' \
 | 
|---|
| 163 |                 -e 's:#include <libc/libc/:#include <libc/:' \
 | 
|---|
| 164 |                 -i {} \;
 | 
|---|
| 165 |         find "$(EXPORT_DIR)/include.new" -name '*.h' -exec sed \
 | 
|---|
| 166 |                 -e 's:#include "posix/:#include ":' \
 | 
|---|
| 167 |                 -e 's:#include <posix/:#include <:' \
 | 
|---|
| 168 |                 -i {} \;
 | 
|---|
| 169 | 
 | 
|---|
| 170 |         rm -rf $(EXPORT_DIR)/include
 | 
|---|
| 171 |         mv $(EXPORT_DIR)/include.new $(EXPORT_DIR)/include
 | 
|---|