libk  Diff

Differences From Artifact [ed3c61cbaa]:

To Artifact [0343c70b67]:


     3      3   # TODO: calculate these using $(MAKE_HOST)
     4      4   export ARCH = x86
     5      5   export OS = lin
     6      6   export BITS = 64
     7      7   export ROOT = $(PWD)
     8      8   export TMP = $(PWD)/gen
     9      9   
           10  +export BUILD = $(shell global/build-id.sh) $(build-host)
           11  +
    10     12   ifneq ($(BITS),)
    11     13       export TARGET = $(ARCH).$(OS).$(BITS)
    12     14   else
    13     15       export TARGET = $(ARCH).$(OS)
    14     16   endif
    15     17   
    16     18   export m4 = m4
    17     19   
    18         -moddirs = $(wildcard k*)
    19         -binaries = $(wildcard k*/*.exe.c)
    20         -functions = $(wildcard k*/*.fn.c) 
    21         -assemblies = $(wildcard k*/*.fn.$(TARGET).s)
    22         -binmods = $(sort $(dir $(binaries)))
           20  +include makerule
           21  +
           22  +moddirs := $(wildcard k*)
           23  +binaries := $(wildcard k*/*.exe.c)
           24  +functions := $(wildcard k*/*.fn.c) 
           25  +assemblies := $(wildcard k*/*.fn.$(TARGET).s)
           26  +binmods := $(sort $(dir $(binaries)))
    23     27   
    24     28   # i'm sorry
    25     29   collect = $(strip $(foreach dir,$(moddirs),$(wildcard $(dir)/*.$1)))
    26     30   transform = $(strip $(foreach dir,$(moddirs),$(patsubst $(dir)/%.$1,$(subst @,$(dir),$2),$(wildcard $(dir)/*.$1))))
    27     31   
    28         -m-hdr-macs = $(call collect,h.m)
    29         -m-c-src-macs = $(call collect,c.m)
    30         -m-s-src-macs = $(call collect,$(TARGET).s.m)
    31         -
    32         -m-c-sources = $(call transform,c.m,$(TMP)/@.%.c)
    33         -m-s-sources = $(call transform,$(TARGET).s.m,$(TMP)/@.%.$(TARGET).s)
    34         -
    35         -m-headers = $(call transform,h.m,$(OUT)/k/%.h)
    36         -m-c-objects = $(call transform,c.m,$(OUT)/@.%.o)
    37         -m-s-objects = $(call transform,$(TARGET).s.m,$(OUT)/@.%.$(TARGET).o)
    38         -
    39         -fnobjects = $(call transform,fn.c,$(OUT)/@.%.fn.o) \
    40         -            $(call transform,fn.c.m,$(OUT)/@.%.fn.o) \
    41         -            $(call transform,fn.$(TARGET).s,$(OUT)/@.%.fn.$(TARGET).o) \
    42         -            $(call transform,fn.$(TARGET).s.m,$(OUT)/@.%.fn.$(TARGET).o)
    43         -
    44         -rtobjects = $(call transform,rt.c,$(OUT)/@.%.rt.o) \
    45         -            $(call transform,rt.c.m,$(OUT)/@.%.rt.o) \
    46         -            $(call transform,rt.$(TARGET).s,$(OUT)/@.%.rt.$(TARGET).o) \
    47         -            $(call transform,rt.$(TARGET).s.m,$(OUT)/@.%.rt.$(TARGET).o)
    48         -
    49         -objects = $(fnobjects) $(rtobjects)
    50         -
    51         -header-dir = /usr/include
    52         -lib-dir = /usr/lib
           32  +m-hdr-macs := $(call collect,h.m)
           33  +m-c-src-macs := $(call collect,c.m)
           34  +m-s-src-macs := $(call collect,$(TARGET).s.m)
           35  +
           36  +m-c-sources := $(call transform,c.m,$(TMP)/@.%.c)
           37  +m-s-sources := $(call transform,$(TARGET).s.m,$(TMP)/@.%.$(TARGET).s)
           38  +
           39  +m-headers := $(call transform,h.m,$(OUT)/k/%.h)
           40  +m-c-objects := $(call transform,c.m,$(OUT)/@.%.o)
           41  +m-s-objects := $(call transform,$(TARGET).s.m,$(OUT)/@.%.$(TARGET).o)
           42  +
           43  +fnobjects := $(call transform,fn.c,$(OUT)/@.%.fn.o) \
           44  +             $(call transform,fn.c.m,$(OUT)/@.%.fn.o) \
           45  +             $(call transform,fn.$(TARGET).s,$(OUT)/@.%.fn.$(TARGET).o) \
           46  +             $(call transform,fn.$(TARGET).s.m,$(OUT)/@.%.fn.$(TARGET).o)
           47  +
           48  +rtobjects := $(call transform,rt.c,$(OUT)/@.%.rt.o) \
           49  +             $(call transform,rt.c.m,$(OUT)/@.%.rt.o) \
           50  +             $(call transform,rt.$(TARGET).s,$(OUT)/@.%.rt.$(TARGET).o) \
           51  +             $(call transform,rt.$(TARGET).s.m,$(OUT)/@.%.rt.$(TARGET).o)
           52  +
           53  +docs := $(wildcard k*/*.md)
           54  +docs-out := $(patsubst %.md,$(OUT)/doc/man/%.4.gz,$(notdir $(docs)))
           55  +objects := $(fnobjects) $(rtobjects)
           56  +
           57  +prefix ?= /usr
           58  +d-header = $(prefix)/include
           59  +d-lib = $(prefix)/lib
           60  +d-share = $(prefix)/share
    53     61   
    54     62   unix-oses = lin fbsd dar and
    55         -posix-oses = lin fbsd dar and hai mgw
           63  +posix-oses = lin fbsd dar and hai mgw cyg
    56     64   
    57     65   ifeq ($(findstring $(OS),$(unix-oses)),$(OS))
    58     66       export UNIX = yes
    59     67       export POSIX = yes
    60     68   else
    61     69       export UNIX = no
    62     70       ifeq ($(findstring $(OS),$(posix-oses)),$(OS))
................................................................................
    64     72   	else
    65     73           export POSIX = no
    66     74   	endif
    67     75   endif
    68     76   
    69     77   # include libgcc.a in gcc builds, just in case
    70     78   ifeq ($(CC),gcc)
    71         -export COMPLIB = -lgcc
           79  +    export COMPLIB = -lgcc
    72     80   endif
    73     81   
    74     82   all: $(OUT) defs obj tool lib.static $(OUT)/boot.o lib.shared
    75     83   lib.static: defs obj $(OUT)/libk.a
    76     84   lib.shared: defs obj $(OUT)/libk.so
    77     85   obj: $(moddirs:%=%.obj) 
    78     86   defs: $(moddirs:%=%.def) 
    79     87   tool: $(OUT)/boot.o $(OUT)/libk.a $(binmods:%=%.tool) 
           88  +doc: $(docs-out)
    80     89   clean:
    81     90   	rm -rf $(TMP) $(OUT)
    82     91   
    83     92   install: all
    84         -	install -d $(header-dir)/k -o root -g wheel
           93  +	install -d $(header-dir)/k $(share-dir)/k -o root -g wheel -m 0755
    85     94   	install $(OUT)/k/* $(header-dir)/k/ -o root -g wheel -m 0644
    86         -	install -d $(lib-dir)/k -o root -g wheel
    87         -	install $(OUT)/libk.a $(OUT)/libk.so $(OUT)/boot.o \
    88         -		$(lib-dir)/k/ -o root -g wheel -m 0644
           95  +	install $(OUT)/libk.a $(OUT)/libk.so \
           96  +		$(lib-dir) -o root -g wheel -m 0644
           97  +	install $(OUT)/boot.o $(share-dir)/k/boot.o -o root -g wheel -m 0644
    89     98   
    90     99   uninstall: $(header-dir)/k $(lib-dir)/k
    91    100   	rm -rf $^
    92    101   
    93         -lists = moddirs functions assemblies fnobjects rtobjects binaries binmods POSIX
          102  +lists = BUILD moddirs functions assemblies fnobjects rtobjects binaries binmods POSIX docs docs-out
    94    103   dbg:
    95    104   	@echo -e lists: $(foreach var, $(lists), "\\n - \\e[1m$(var)\\e[m = $($(var))")
    96    105   
    97         -%.obj: %/makefile  $(OUT)
          106  +%.obj: %/makefile $(OUT)/internal.ident.o $(OUT)
    98    107   	cd $* && $(MAKE) obj
    99    108   
   100    109   %.tool: %/makefile $(OUT)
   101    110   	cd $* && $(MAKE) tool
   102    111   
   103    112   %.dbg: %/makefile $(OUT)
   104    113   	cd $* && $(MAKE) dbg
   105    114   
   106    115   %.def: %/makefile $(TMP)/typesize.def \
          116  +                  $(OUT)/k/internal.egroup.h \
   107    117                     $(TMP)/system_calls.h \
   108    118   				  $(TMP)/system_calls.s \
   109    119   				  $(TMP)/error_table.h \
   110    120   				  $(OUT) $(OUT)/k
   111    121   	cd $* && $(MAKE) def
   112    122   
   113    123   .PRECIOUS: $(TMP)/system_calls.%
................................................................................
   129    139   
   130    140   $(OUT)/libk.a: $(fnobjects) $(rtobjects)
   131    141   	@# using `ar rc` and ranlib here instead of
   132    142   	@# `ar rcs` in case `ar` isn't the GNU version
   133    143   	ar rc $@ $^
   134    144   	ranlib $@
   135    145   
          146  +$(OUT)/man/doc:
          147  +	mkdir -p $@
          148  +
          149  +$(OUT)/k/internal.egroup.h: global/modules global/genconds.awk $(OUT)/k
          150  +	awk -f global/genconds.awk <$< >$@
          151  +$(TMP)/internal.ident.c: global/modules global/genident.awk $(OUT)/k/internal.egroup.h $(TMP)
          152  +	awk -f global/genident.awk <$< >$@
          153  +$(OUT)/%.o: $(TMP)/%.c $(OUT)
          154  +	$(CC) $(cflags) -c $< -o $@
          155  +
   136    156   $(OUT) $(OUT)/k $(TMP):
   137    157   	mkdir -p $@