libk  Diff

Differences From Artifact [e72fb78502]:

To Artifact [adae292a57]:


     2      2   # this is the master makefile that controls the building of each
     3      3   # libk module. it is included from each k*/makefile.
     4      4   # vim: ft=make
     5      5   
     6      6   mod = $(notdir $(PWD))
     7      7   src = $(wildcard *.c) $(wildcard *.s)
     8      8   bare = $(mod:k%=%)
            9  +headers = $(wildcard *.h) $(gen-headers)
     9     10   
    10     11   tools    = $(filter     exe.%.c,   $(src))
    11     12   nontools = $(filter-out exe.%.c,   $(src))
    12     13   cobjects = $(filter     %.c,       $(nontools))
    13     14   sobjects = $(filter %.${TARGET}.s, $(nontools))
    14     15   
           16  +cflags = -isystem ${OUT} -nostdlib ${COMPLIB} -L${OUT} -lk
           17  +
    15     18   obj: $(cobjects:%.c=${OUT}/$(mod).%.o) \
    16     19   	 $(sobjects:%.s=${OUT}/$(mod).%.o)
    17         -tool: $(tools:exe.%.c=${OUT}/$(mod).%)
           20  +tool: $(tools:exe.%.c=${OUT}/$(mod).%) \
           21  +	  ${OUT}/libk.a
           22  +
           23  +def: $(headers:%=${OUT}/k/%)
    18     24   
    19     25   dbg:
    20     26   	@echo tools = $(tools)
    21     27   	@echo TARGET = ${TARGET}
    22     28   	@echo cobjects = $(cobjects)
    23     29   	@echo sobjects = $(sobjects)
           30  +	@echo headers = $(headers)
    24     31   	@echo mod = $(mod)
    25     32   
    26     33   ${OUT}/$(mod).%.o: %.c
    27         -	$(CC) -c $< -o $@
           34  +	$(CC) $(cflags) -c $< -o $@
    28     35   
    29         -${OUT}/k/$(bare).h: $(bare).h
           36  +${OUT}/k/%.h: %.h
    30     37   	cp $< $@
    31     38   
    32     39   ${OUT}/$(mod).%: exe.%.c
    33         -	$(CC) $< -o $@
           40  +	$(CC) $(cflags) $< -o $@
           41  +
           42  +${TMP}:
           43  +	mkdir -p ${TMP}
    34     44   
    35     45   #- assembly
    36     46   # compiling  the assembly  code will  be  faster but  a lot  more
    37     47   # complex, given the  nature of assembly and the  large number of
    38     48   # platforms  targeted.  we need  to  add  build rules  for  every
    39     49   # arch.OS[.bits] tuple;  since this  is a fairly  repetetive task
    40     50   # that  requires ugly  make  rules,  we're just  going  to use  a
................................................................................
    43     53   # ${OUT} = ultimate build directory
    44     54   # $(mod) = module name
    45     55   #      % = function name
    46     56   #   $(1) = arch tuple
    47     57   arch = ${OUT}/$(mod).%.$(1).o: %.$(1).s
    48     58   # invoke with $(call arch,tuple). do not
    49     59   # put spaces between either term though!
           60  +
           61  +ifeq ($(debug),yes)
           62  +yasm-flags = -gdwarf2
           63  +endif
    50     64   
    51     65   #-- linux
    52     66   # linux uses the ELF{32,64} binary format,  and generating these
    53     67   # from yasm is trivial.  linux only supports one ABI per format,
    54     68   # at least with ELF, so that's all we need to do.
    55     69   
    56     70   #${OUT}/$(mod).%.x86.lin.32.o: %.x86.lin.32.s
    57     71   $(call arch,x86.lin.32)
    58         -	yasm -gdwarf2 -felf32 $< -o $@
           72  +	yasm $(yasm-flags) -felf32 -i${TMP} $< -o $@
    59     73   
    60     74   #${OUT}/$(mod).%.x86.lin.64.o: %.x86.lin.64.s
    61     75   $(call arch,x86.lin.64)
    62         -	yasm -gdwarf2 -felf64 $< -o $@
           76  +	yasm $(yasm-flags) -felf64 -i${TMP} $< -o $@
    63     77   
    64     78   #-- freebsd
    65     79   # the freebsd ABI is different, so it will require different code
    66     80   # (though there might be ways to minimize that). freebsd uses the
    67     81   # same binary format as Linux  (though it also supports a.out and
    68     82   # COFF) but because freebsd can interpret multiple different ABIs
    69     83   # the  object files  need to  be "branded"  with the  correct one