SimpleOS

LXR

Navigation



Site hébergé par : enix

The LXR Cross Referencer for SOS

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Article:1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 6.5 ] [ 7 ] [ 7.5 ] [ 8 ] [ 9 ] [ 9.5 ]

001 ## Copyright (C) 2005  David Decotigny
002 ##
003 ## This program is free software; you can redistribute it and/or
004 ## modify it under the terms of the GNU General Public License
005 ## as published by the Free Software Foundation; either version 2
006 ## of the License, or (at your option) any later version.
007 ## 
008 ## This program is distributed in the hope that it will be useful,
009 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
010 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
011 ## GNU General Public License for more details.
012 ## 
013 ## You should have received a copy of the GNU General Public License
014 ## along with this program; if not, write to the Free Software
015 ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
016 ## USA. 
017 
018 CC=gcc
019 AR=ar
020 CFLAGS  = -Wall -nostdinc -ffreestanding -I. -I..
021 LDFLAGS = -Wl,--warn-common -nostdlib -Wl,-Tldscript.lds
022 
023 # Main target
024 all: userprogs.kimg
025 
026 -include .mkvars
027 
028 
029 PWD := $(shell pwd)
030 
031 # Programs generation
032 $(PROGS):
033         $(CC) -static $(LDFLAGS) -o $@ $^
034 
035 # Generation of the libC
036 libc.a: libc.o
037 
038 # Create a program image to be integrated into the Kernel
039 userprogs.kimg: $(PROGS)
040         @echo "# Generating ELF images for inclusion into the kernel image: $@"
041         @echo "SECTIONS { .rodata . : { " > .userprogs.lds
042         @i=0 ;                                                              \
043          for f in $^ ; do                                                   \
044            i=`expr $$i + 1` ;                                               \
045            echo "extern char _begin_userprog$$i, _end_userprog$$i;"         \
046                 > .userprog$$i.c ;                                          \
047            echo "char *_userprog"$$i"_entry[]" >> .userprog$$i.c ;          \
048            echo "  __attribute__((section(\".userprogs_table\")))"          \
049                 >> .userprog$$i.c ;                                         \
050            echo "  = { \"$$f\", &_begin_userprog$$i, &_end_userprog$$i };"  \
051                 >> .userprog$$i.c ;                                         \
052            $(CC) $(CFLAGS) -c .userprog$$i.c -o .userprog$$i.o ;            \
053            objcopy --add-section .userprog$$i=$$f .userprog$$i.o            \
054                 .userprog$$i.kimg ;                                         \
055            echo "  _begin_userprog$$i = .;" >> .userprogs.lds ;             \
056            echo "  .userprog$$i.kimg(.userprog$$i);" >> .userprogs.lds ;    \
057            echo "  _end_userprog$$i = .;" >> .userprogs.lds ;               \
058            echo "  .userprog$$i.kimg(.rodata); .userprog$$i.kimg(.data);"   \
059                 >> .userprogs.lds ;                                         \
060          done
061         @echo "  _userprogs_table = .; *(.userprogs_table) ; LONG(0);"      \
062                 >> .userprogs.lds
063         @echo "} /DISCARD/ : { *(.text) *(.data) *(.bss) } }"               \
064                 >> .userprogs.lds
065         @ld -r -o $@ -T.userprogs.lds
066 
067 # Create libraries from object files
068 %.a:
069         $(AR) rcv $@ $^
070 
071 # Create objects from C source code
072 %.o: %.c
073         $(CC) -I$(PWD) -c $< $(CFLAGS) -o $@
074 
075 # Create objects from assembler (.S) source code
076 %.o: %.S
077         $(CC) -I$(PWD) -c $< $(CFLAGS) -DASM_SOURCE=1 -o $@
078 
079 # Clean directory
080 clean:
081         $(RM) *.o *.a *~ $(PROGS) *.kimg
082         $(RM) .userprog*

source navigation ] diff markup ] identifier search ] general search ]