libk  Diff

Differences From Artifact [ac03aab83b]:

To Artifact [d63468c69f]:


     1      1   export OUT = $(PWD)/out
     2      2   
            3  +# TODO: calculate these using $(MAKE_HOST)
     3      4   export ARCH = x86
     4      5   export OS = lin
     5      6   export BITS = 64
     6      7   export TMP = $(PWD)/tmp
     7      8   
     8         -export TARGET = $(ARCH).$(OS).$(BITS)
            9  +ifneq ($(BITS),)
           10  +    export TARGET = $(ARCH).$(OS).$(BITS)
           11  +else
           12  +    export TARGET = $(ARCH).$(OS)
           13  +endif
     9     14   
           15  +export gpp = gpp
    10     16   export lin-headers = /usr/include/asm
    11     17   export fbsd-headers = /usr/include/sys
    12     18   
    13     19   moddirs = $(wildcard k*)
    14     20   binaries = $(wildcard k*/*.exe.c)
    15     21   functions = $(wildcard k*/*.fn.c) 
    16         -assemblies = $(wildcard k*/*.fn.${TARGET}.s)
           22  +assemblies = $(wildcard k*/*.fn.$(TARGET).s)
    17     23   binmods = $(sort $(dir $(binaries)))
    18     24   
    19     25   # i'm sorry
    20         -collect = $(strip $(foreach dir,$(moddirs),$(addprefix $(OUT)/$(dir).,$(notdir $(wildcard $(dir)/$1)))))
           26  +collect = $(strip $(foreach dir,$(moddirs),$(wildcard $(dir)/*.$1)))
           27  +transform = $(strip $(foreach dir,$(moddirs),$(patsubst $(dir)/%.$1,$(subst @,$(dir),$2),$(wildcard $(dir)/*.$1))))
    21     28   
    22         -cfnsources = $(call collect,*.fn.c)
    23         -sfnsources = $(call collect,*.fn.${TARGET}.s)
    24         -crtsources = $(call collect,*.rt.c)
    25         -srtsources = $(call collect,*.rt.${TARGET}.s)
    26         -fnsources = $(cfnsources) $(sfnsources)
    27         -rtsources = $(crtsources) $(srtsources)
    28         -sources = $(fnsources) $(rtsources)
           29  +m-hdr-macs = $(call collect,h.m)
           30  +m-c-src-macs = $(call collect,c.m)
           31  +m-s-src-macs = $(call collect,$(TARGET).s.m)
    29     32   
    30         -cfnobjects = $(cfnsources:%.c=%.o)
    31         -sfnobjects = $(sfnsources:%.s=%.o)
    32         -crtobjects = $(crtsources:%.c=%.o)
    33         -srtobjects = $(srtsources:%.s=%.o)
    34         -fnobjects = $(cfnobjects) $(sfnobjects)
    35         -rtobjects = $(crtobjects) $(srtobjects)
           33  +m-c-sources = $(call transform,c.m,$(TMP)/@.%.c)
           34  +m-s-sources = $(call transform,$(TARGET).s.m,$(TMP)/@.%.$(TARGET).s)
           35  +
           36  +m-headers = $(call transform,h.m,$(OUT)/k/%.h)
           37  +m-c-objects = $(call transform,c.m,$(OUT)/@.%.o)
           38  +m-s-objects = $(call transform,$(TARGET).s.m,$(OUT)/@.%.$(TARGET).o)
           39  +
           40  +fnobjects = $(call transform,fn.c,$(OUT)/@.%.fn.o) \
           41  +            $(call transform,fn.c.m,$(OUT)/@.%.fn.o) \
           42  +            $(call transform,fn.$(TARGET).s,$(OUT)/@.%.fn.$(TARGET).o) \
           43  +            $(call transform,fn.$(TARGET).s.m,$(OUT)/@.%.fn.$(TARGET).o)
           44  +
           45  +rtobjects = $(call transform,rt.c,$(OUT)/@.%.rt.o) \
           46  +            $(call transform,rt.c.m,$(OUT)/@.%.rt.o) \
           47  +            $(call transform,rt.$(TARGET).s,$(OUT)/@.%.rt.$(TARGET).o) \
           48  +            $(call transform,rt.$(TARGET).s.m,$(OUT)/@.%.rt.$(TARGET).o)
           49  +
    36     50   objects = $(fnobjects) $(rtobjects)
    37     51   
    38     52   header-dir = /usr/include
    39     53   lib-dir = /usr/lib
    40     54   
           55  +unix-oses = lin fbsd dar and
    41     56   posix-oses = lin fbsd dar and hai mgw
    42     57   
    43         -ifeq ($(findstring $(OS),$(posix-oses)),$(OS))
    44         -export POSIX = yes
           58  +ifeq ($(findstring $(OS),$(unix-oses)),$(OS))
           59  +    export UNIX = yes
           60  +    export POSIX = yes
    45     61   else
    46         -export POSIX = no
           62  +    export UNIX = no
           63  +    ifeq ($(findstring $(OS),$(posix-oses)),$(OS))
           64  +        export POSIX = yes
           65  +	else
           66  +        export POSIX = no
           67  +	endif
    47     68   endif
    48     69   
    49     70   # include libgcc.a in gcc builds, just in case
    50     71   ifeq ($(CC),gcc)
    51     72   export COMPLIB = -lgcc
    52     73   endif
    53     74   
    54     75   all: $(OUT) defs obj tool lib.static $(OUT)/boot.o lib.shared
    55     76   lib.static: defs obj $(OUT)/libk.a
    56     77   lib.shared: defs obj $(OUT)/libk.so
    57         -obj: $(moddirs:%=%.obj)
    58         -defs: $(moddirs:%=%.def)
    59         -tool: $(OUT)/libk.a $(binmods:%=%.tool) 
           78  +obj: $(moddirs:%=%.obj) 
           79  +defs: $(moddirs:%=%.def) 
           80  +tool: $(OUT)/boot.o $(OUT)/libk.a $(binmods:%=%.tool) 
    60     81   clean:
    61     82   	rm -rf $(TMP) $(OUT)
    62     83   
    63     84   install: all
    64     85   	install -d $(header-dir)/k -o root -g wheel
    65     86   	install $(OUT)/k/* $(header-dir)/k/ -o root -g wheel -m 0644
    66     87   	install -d $(lib-dir)/k -o root -g wheel
    67     88   	install $(OUT)/libk.a $(OUT)/libk.so $(OUT)/boot.o \
    68     89   		$(lib-dir)/k/ -o root -g wheel -m 0644
    69     90   
    70     91   uninstall: $(header-dir)/k $(lib-dir)/k
    71     92   	rm -rf $^
    72     93   
    73         -lists = moddirs functions assemblies cfnobjects sfnobjects crtobjects srtobjects rtobjects binaries binmods POSIX
           94  +lists = moddirs functions assemblies fnobjects rtobjects binaries binmods POSIX
    74     95   dbg:
    75     96   	@echo -e lists: $(foreach var, $(lists), "\\n - \\e[1m$(var)\\e[m = $($(var))")
    76     97   
    77         -%.obj: %/makefile ${TARGET}.calls $(OUT)
           98  +%.obj: %/makefile $(TMP)/precomp.g $(TARGET).calls $(OUT)
    78     99   	cd $* && $(MAKE) obj
    79    100   
    80         -%.tool: %/makefile $(OUT)
          101  +%.tool: %/makefile $(TMP)/precomp.g $(OUT)
    81    102   	cd $* && $(MAKE) tool
    82    103   
    83    104   %.dbg: %/makefile $(OUT)
    84    105   	cd $* && $(MAKE) dbg
    85    106   
    86         -%.def: %/makefile $(OUT) $(OUT)/k
          107  +%.def: %/makefile $(TMP)/precomp.g $(OUT) $(OUT)/k
    87    108   	cd $* && $(MAKE) def
    88    109   
    89    110   %.calls: arch/makefile
    90    111   	cd arch && $(MAKE) $(TMP)/calls.$*.s
          112  +
          113  +$(TMP)/precomp.g: grammar/precomp.g.gpp $(TMP)
          114  +	cd grammar && $(MAKE) $@
    91    115   
    92    116   $(OUT)/libk.so: $(fnobjects) 
    93    117   	ld -shared $(COMPLIB) -o $@ $^
    94    118   	@# $(CC) -shared -fPIC -nostdlib $(COMPLIB) -o $@ $(OUT)/*.o
    95    119   
    96    120   $(OUT)/boot.o: $(rtobjects)
    97    121   	ld -r $^ -o $(OUT)/boot.o
................................................................................
    98    122   
    99    123   $(OUT)/libk.a: $(fnobjects) $(rtobjects)
   100    124   	@# using `ar rc` and ranlib here instead of
   101    125   	@# `ar rcs` in case `ar` isn't the GNU version
   102    126   	ar rc $@ $^
   103    127   	ranlib $@
   104    128   
   105         -$(OUT) $(OUT)/k:
          129  +$(OUT) $(OUT)/k $(TMP):
   106    130   	mkdir -p $@