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/stdio/scanf.c \
|
---|
73 | src/stdlib.c \
|
---|
74 | src/stdlib/strtold.c \
|
---|
75 | src/string.c \
|
---|
76 | src/strings.c \
|
---|
77 | src/sys/mman.c \
|
---|
78 | src/sys/stat.c \
|
---|
79 | src/sys/wait.c \
|
---|
80 | src/time.c \
|
---|
81 | src/unistd.c
|
---|
82 |
|
---|
83 | TEST_SOURCES = \
|
---|
84 | test/main.c \
|
---|
85 | test/scanf.c
|
---|
86 |
|
---|
87 | EXPORT_CPPFLAGS = \
|
---|
88 | -specs $$(HELENOS_EXPORT_ROOT)/lib/gcc.specs \
|
---|
89 | -isystem $$(HELENOS_EXPORT_ROOT)/include
|
---|
90 |
|
---|
91 | EXPORT_LDFLAGS = \
|
---|
92 | -L$$(HELENOS_EXPORT_ROOT)/lib \
|
---|
93 | -T link.ld
|
---|
94 |
|
---|
95 | EXPORT_LDLIBS = \
|
---|
96 | -Wl,--start-group -lposix -lmath -lc -lsoftfloat -lsoftint -Wl,--end-group
|
---|
97 |
|
---|
98 | EXPORT_CFLAGS = \
|
---|
99 | -specs $$(HELENOS_EXPORT_ROOT)/lib/gcc.specs
|
---|
100 |
|
---|
101 | include $(USPACE_PREFIX)/Makefile.common
|
---|
102 |
|
---|
103 | $(SPECS): $(CONFIG_MAKEFILE)
|
---|
104 | echo '*self_spec:' > $@.new
|
---|
105 | echo '+ $(COMMON_CFLAGS)' >> $@.new
|
---|
106 | echo >> $@.new
|
---|
107 | echo '*cpp:' >> $@.new
|
---|
108 | echo '+ $(COMMON_CPPFLAGS)' >> $@.new
|
---|
109 | echo >> $@.new
|
---|
110 | echo '*lib:' >> $@.new
|
---|
111 | echo '$(EXPORT_LDLIBS)' >> $@.new
|
---|
112 | mv $@.new $@
|
---|
113 |
|
---|
114 | $(EXPORT_LINKER_SCRIPT): $(LIBC_LINKER_SCRIPT)
|
---|
115 | sed 's/STARTUP(.*)/STARTUP(crt0.o)/' $< > $@
|
---|
116 |
|
---|
117 | $(EXPORT_STARTUP_FILE): $(LIBC_STARTUP_FILE)
|
---|
118 | cp $< $@
|
---|
119 |
|
---|
120 | $(INCLUDE_LIBC): $(shell find ../c/include -name '*.h')
|
---|
121 | cp -r -L --remove-destination -T ../c/include $@
|
---|
122 | find ../c/include -type f -and -not -name '*.h' -delete
|
---|
123 |
|
---|
124 | export: $(EXPORT_DIR)/config.mk $(EXPORT_DIR)/config.rc
|
---|
125 |
|
---|
126 | $(EXPORT_DIR)/config.mk: export-libs export-includes
|
---|
127 | echo '# Generated file, do not modify.' >> $@.new
|
---|
128 | echo '# Do not forget to set HELENOS_EXPORT_ROOT.' >> $@.new
|
---|
129 | echo 'HELENOS_CROSS_PATH="$(shell dirname "$(CC)")"' >> $@.new
|
---|
130 | echo 'HELENOS_ARCH="$(firstword $(subst -, ,$(TARGET)))"' >> $@.new
|
---|
131 | echo 'HELENOS_TARGET="$(TARGET)"' >> $@.new
|
---|
132 | echo 'HELENOS_CPPFLAGS="$(EXPORT_CPPFLAGS)"' >> $@.new
|
---|
133 | echo 'HELENOS_CFLAGS="$(EXPORT_CFLAGS)"' >> $@.new
|
---|
134 | echo 'HELENOS_CXXFLAGS="$(EXPORT_CFLAGS)"' >> $@.new
|
---|
135 | echo 'HELENOS_LDFLAGS="$(EXPORT_LDFLAGS)"' >> $@.new
|
---|
136 | echo 'HELENOS_LDLIBS="$(EXPORT_LDLIBS)"' >> $@.new
|
---|
137 | mv $@.new $@
|
---|
138 |
|
---|
139 | $(EXPORT_DIR)/config.rc: $(EXPORT_DIR)/config.mk
|
---|
140 | sed 's:$$(HELENOS_EXPORT_ROOT):$$HELENOS_EXPORT_ROOT:g' < $< >$@
|
---|
141 |
|
---|
142 | export-libs: $(EXPORT_FILES) export-includes
|
---|
143 | mkdir -p $(EXPORT_DIR)/lib
|
---|
144 | cp -L $(EXPORT_FILES) $(EXPORT_DIR)/lib
|
---|
145 |
|
---|
146 | export-includes: $(INCLUDE_LIBC) $(shell find ./include ../c/arch/$(UARCH)/include $(ROOT_PATH)/abi/include -name '*.h')
|
---|
147 | mkdir -p $(EXPORT_DIR)/include
|
---|
148 | rm -rf $(EXPORT_DIR)/include.new
|
---|
149 | cp -r -L -T ./include/posix $(EXPORT_DIR)/include.new
|
---|
150 | cp -r -L -T ./include/libc $(EXPORT_DIR)/include.new/libc
|
---|
151 | cp -r -L ../c/arch/$(UARCH)/include/* $(EXPORT_DIR)/include.new/libc
|
---|
152 | cp -r -L $(ROOT_PATH)/abi/include/* $(EXPORT_DIR)/include.new
|
---|
153 | mkdir -p $(EXPORT_DIR)/include.new/libclui
|
---|
154 | cp -L ../clui/tinput.h $(EXPORT_DIR)/include.new/libclui
|
---|
155 |
|
---|
156 | find "$(EXPORT_DIR)/include.new/libc" "$(EXPORT_DIR)/include.new/libclui" -name '*.h' -exec sed \
|
---|
157 | -e 's:#include <:#include <libc/:' \
|
---|
158 | -e 's:#include <libc/abi/:#include <abi/:' \
|
---|
159 | -e 's:#include <libc/_bits/:#include <_bits/:' \
|
---|
160 | -e 's:#include <libc/libc/:#include <libc/:' \
|
---|
161 | -i {} \;
|
---|
162 | find "$(EXPORT_DIR)/include.new" -name '*.h' -exec sed \
|
---|
163 | -e 's:#include "posix/:#include ":' \
|
---|
164 | -e 's:#include <posix/:#include <:' \
|
---|
165 | -i {} \;
|
---|
166 |
|
---|
167 | rm -rf $(EXPORT_DIR)/include
|
---|
168 | mv $(EXPORT_DIR)/include.new $(EXPORT_DIR)/include
|
---|