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 ]

Diff markup

Differences between /userland/Makefile (Article 7) and /userland/Makefile (Article 6.5)


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

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