Changeset 1720


Ignore:
Timestamp:
Dec 9, 2004, 7:39:21 AM (21 years ago)
Author:
bird
Message:

Make building a bit more obvious. (hope it works)

Location:
trunk/src/emx
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/Makefile

    • Property cvs2svn:cvs-rev changed from 1.56 to 1.57
    r1719 r1720  
    1 # Central makefile for building the OS2/GCC C runtime
     1# $Id$
     2## @file
    23#
    3 # InnoTek Systemberatung GmbH
     4# Bootstrap makefile.
    45#
    5 # Copyright (c) 1994-1995 by Eberhard Mattes
    6 # Copyright (c) 2003 InnoTek Systemberatung GmbH
     6# Copyright (c) 2004 knut st. osmundsen <bird@anduin.net>
    77#
    8 # Author: Andrew Zabolotny <zap@cobra.ru>
    9 # $Id$
    108#
    11 # All Rights Reserved
     9# This file is part of InnoTek LIBC.
    1210#
    13 # Requires GNU Make.
    14 # In fact, this build system could be entitled "GNU Make Unleashed"
     11# InnoTek LIBC is free software; you can redistribute it and/or modify
     12# it under the terms of the GNU Lesser General Public License as published
     13# by the Free Software Foundation; either version 2 of the License, or
     14# (at your option) any later version.
    1515#
    16 # For a brief description of how build system works please read build.txt
     16# InnoTek LIBC is distributed in the hope that it will be useful,
     17# but WITHOUT ANY WARRANTY; without even the implied warranty of
     18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     19# GNU Lesser General Public License for more details.
    1720#
    18 # Bootstrapping sequence using EMX gcc compiler:
     21# You should have received a copy of the GNU Lesser General Public License
     22# along with InnoTek LIBC; if not, write to the Free Software
     23# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1924#
    20 # 1. Backup include/ctype.h and rename include/ctype.h-bootstrap to
    21 #    include/ctype.h
    22 # 2. Run 'make os2', put the resulting library os2.a to emx/lib as _os2.a,
    23 #    and convert it to .lib with emxomf: 'emxomf _os2.a'
    24 # 3. Now compile everything you wish this way: 'make LIBS=-l_os2'
    2525#
    2626
    27 # Build type control variables. You can set them right from command line,
    28 # e.g "make MODE=dbg"
     27include version.smak
    2928
    30 # Build mode: opt (optimization), dbg (debug)
    31 MODE = dbg
    32 # Base output directory
    33 OUT = out/
    34 # Base installation directory
    35 INS = out/$(MODE)/install/
    36 # CPU type (pretend we are portable ;-)
    37 CPU = 386
    38 # Name of this makefile
    39 ifndef MAKEFILE
    40 MAKEFILE = Makefile     
    41 endif
     29help:
     30        @echo "Welcome to $(PACKAGE) version $(VERSION) build system!"
     31        @echo "$(COPYRIGHT)"
     32        @echo ""
     33        @echo "There are four makefile you can invoke using the -f option of make:"
     34        @echo "    Makefile      - Bootstrap libc and tools (this makefile)."
     35        @echo "                    Does 1) toolonly.smak and 2) libonly.smak."
     36        @echo "    libonly.gmk   - Build libc using installed tools."
     37        @echo "    toolonly.gmk  - Build all the tools using installed libc & tools."
     38        @echo "    Makefile.gmk  - Build everything, building and using the tools."
     39        @echo "                    This normally never works unless the difference"
     40        @echo "                    between the libc versions you're building and using"
     41        @echo "                    are microscopical."
     42        @echo ""
     43        @echo "This makefile is used to bootstrap libc in is usually what you want to"
     44        @echo "use when building libc. It have the following goals:"
     45        @echo "    all           - Build tools and libc. (in that order)"
     46        @echo "    tools         - make -f toolonly.gmk all"
     47        @echo "    libs          - make -f libonly.gmk all"
     48        @echo "    clean         - Wipes all the output."
     49        @echo "    install       - Wipes all the output."
     50        @echo "    bootstrap     - all + install + clean + all + install. This assumes"
     51        @echo "                    that your install directory is setup to override any"
     52        @echo "                    installed libc and tools when somethings installed."
     53        @echo "    core          - Don't build (some of) the alternative library versions."
     54        @echo "    core-install  - Install the stuff build with the core goal."
     55        @echo "    help          - This message."
     56        @echo ""
     57        @echo "Enjoy :-)"
    4258
    43 # Actual output directory (referenced with $.)
    44 . = $(OUT)$(MODE)/
     59all:
     60        $(MAKE) -f toolonly.gmk $@
     61        $(MAKE) -f libonly.gmk $@
    4562
    46 # overrides from the environment.
    47 ifdef PATH_OBJ
    48 ifndef PATH_OBJD
    49 PATH_OBJD := $(shell echo $(PATH_OBJ)|sed 's/^[a-zA-Z]://')
    50 endif
    51 OUT = $(PATH_OBJD)/emx/
    52 INS = $(PATH_OBJD)/builttools/
    53 .   = $(OUT)
    54 endif
     63libs lib:
     64        $(MAKE) -f libonly.gmk all
    5565
    56 ifdef BUILD_MODE
    57 ifeq ($(BUILD_MODE),RELEASE)
    58 MODE = opt
    59 endif
    60 endif
    61 
    62 # Check if MODE has a valid value
    63 ifneq ($(filter-out /opt/ /dbg/ /prf/,/$(MODE)/),)
    64 $(error MODE should have one of the following values: opt, dbg, prf)
    65 endif
    66 
    67 # The object file format to use for tools (emxomf, ld and friends)
    68 TOOLFMT.dbg = omf
    69 TOOLFMT.opt = omf
    70 TOOLFMT.prf = omf
    71 TOOLFMT = $(TOOLFMT.$(MODE))
    72 
    73 # Use ash.exe which is quite fast (comparable to cmd.exe) but has more features
    74 SHELL := ash.exe
    75 
    76 # Source base directory.
    77 srcdir := $(shell pwd)
    78                                                
    79 # File name extensions
    80 # Executable files -- xxx$E
    81 E = .exe
    82 # DLL files --- xxx$D
    83 D = .dll
    84 # Library files --- xxx$A
    85 A = .$(if $(findstring omf,$(.TKIND)),lib,a)
    86 
    87 # Use the tool we built.
    88 GETTOOL ?= $.$(TOOLFMT)/$1$E
    89 # Use the tool we built if present
    90 GETTOOL2 ?= `test -f '$.$(TOOLFMT)/$1$E' && echo '$.$(TOOLFMT)/'`$1$E
    91 
    92 # The C compiler
    93 CC = gcc -c -Zmt -fmessage-length=0
    94 # The C compiler flags
    95 ifndef NO_LOCAL_HEADERS
    96 CFLAGS.INC  += -Iinclude
    97 endif
    98 CFLAGS.INC  += -Isrc/include
    99 CFLAGS      = -Wall -Wundef -Wmissing-prototypes -mstack-arg-probe $(CFLAGS.INC) $(CFLAGS.$(MODE)) $(CFLAGS.KIND)
    100 # The additional C compiler flags for different build modes
    101 CFLAGS.opt  = -g -O3 -mcpu=pentium -mpreferred-stack-boundary=2 -malign-strings=2 -falign-loops=2 -falign-jumps=2 -falign-functions=3
    102 CFLAGS.dbg  = -g -DDEBUG
    103 CFLAGS.prf  = $(CFLAGS.opt) -pg
    104 CFLAGS.aout = -Zaout
    105 CFLAGS.omf  = -Zomf
    106 CFLAGS.prof = -pg
    107 CFLAGS.log  = -DDEBUG_LOGGING -D__LIBC_STRICT
    108 # The object files are put in subdirectory objectformat-targetkind,
    109 # we decompose object file name back and pick appropiate $CFLAGS
    110 CFLAGS.KIND = $(foreach x,$(subst -, ,$(firstword $(subst /, ,$(subst $.,,$@)))),$(CFLAGS.$x))
    111 # How to compile a .c file
    112 DO.COMPILE.c = $(CC) -std=gnu99 $(strip $(CFLAGS) $1) -o $@ $(srcdir)/$< -I$(dir $<)
    113 # '-std=gnu99' doesn't work with '-x assembler-with-cpp', therefor no $(call DO.COMPILE.c).
    114 DO.COMPILE.s = $(CC) -x assembler-with-cpp $(strip $(CFLAGS) $1) -o $@ $(srcdir)/$< -I$(dir $<)
    115 
    116 # The linker
    117 LD = gcc
    118 # Linker flags
    119 LDFLAGS     = $(LDFLAGS.$(MODE)) $(LDFLAGS.KIND) -Zmap -Zstack 1024 -Zhigh-mem $(LIBS)
    120 LDFLAGS.DLL = $(LDFLAGS) -Zdll -Zfork
    121 # Linker flags for different build modes
    122 LDFLAGS.opt = -g -Zcrtdll=c_dll
    123 LDFLAGS.prf = -g -Zcrtdll=c_dll -lkProfile -LG:/kTaskMgr/Tree/lib/debug
    124 LDFLAGS.dbg = -g
    125 LDFLAGS.aout = -Zaout
    126 LDFLAGS.omf = -Zomf -Zlinker /PM:VIO -Zlinker /LINENUMBERS
    127 LDFLAGS.prof = -pg
    128 # Linker flags for different kinds of target
    129 LDFLAGS.KIND = $(foreach x,$(subst -, ,$(firstword $(subst /, ,$(subst $.,,$@)))),$(LDFLAGS.$x))
    130 # How to link a .exe file
    131 DO.LINK.exe = $(LD) $(strip $(LDFLAGS) $(filter-out -l%,$1)) -o $@ $(^O) $(^DEF) $(^LIB) $(filter -l%,$1)
    132 # How to link a .dll file
    133 DO.LINK.dll = $(LD) $(strip $(LDFLAGS.DLL) $(filter-out -l%,$1)) -o $@ $(^O) $(^DEF) $(^LIB) $(filter -l%,$1)
    134 
    135 # Pack executables and DLLs right after they are linked
    136 # bird: I don't care about space, only performance. So, we will only use
    137 #       lxlite for stripping and sector aligning.
    138 #               <rant> My explanation is that anything which is used frequently
    139 #               enough will be in one of the caches, so unpacking the datasegment
    140 #               for each new process is a waste of time. The code segment is
    141 #               shared, data segment is not shared, but must be reloaded page by page
    142 #               from the executable in new processes.
    143 #       For further optimzations, we align pages on 4kb boundaries since this
    144 #               is the JFS block size and thus should be most the efficient unit to read. </rant>
    145 # URG! we must not do this for ldstub.bin!
    146 ifeq ($(MODE),opt)
    147 LXLITE.FLAGS = /F+ /AP:4096 /MRN /MLN /MF1
    148 DO.LINK.exe += $(if $(findstring .exe,$@), $(NL)cp $@ $(basename $@).dbg $(NL)lxlite /X /AS $(subst /,\\,$@))
    149 DO.LINK.dll += $(NL)cp $@ $(basename $@).dbg $(NL)lxlite $(LXLITE.FLAGS) $(subst /,\\,$@)
    150 endif
    151 
    152 # emxbind tool
    153 EMXBIND = $(call GETTOOL2,emxbind)
    154 # emxbind flags
    155 EMXBINDFLAGS = -bq $(EMXBINDFLAGS.$(MODE))
    156 EMXBINDFLAGS.opt = -s
    157 EMXBINDFLAGS.prf =
    158 EMXBINDFLAGS.dbg =
    159 # Flags for emxbind
    160 DO.EMXBIND = $(EMXBIND) $(EMXBINDFLAGS) -o $@ $1
    161 
    162 # The macro assembler
    163 ifdef PATH_TOP
    164 ASM = $(PATH_TOP)/tools/x86.os2/masm/v6.0/binp/ml.exe -c
    165 else
    166 ASM = ml -c
    167 endif
    168 ASMFLAGS = -Cp -W3 -WX -VM -nologo
    169 # How to compile an .asm file
    170 DO.COMPILE.asm = $(ASM) $(ASMFLAGS) $1 -Fo$@ $<
    171 
    172 # The tool to create an archive
    173 AR = $(if $(findstring .lib,$@), $(call GETTOOL2,emxomfar),ar)
    174 ARFLAGS = crs
    175 DO.LIBRARY = $(call RM,$@); $(AR) $(ARFLAGS)$1 $@ $(^O)
    176 
    177 # The tool to extract exports from object files and archives,
    178 # removing unused stuff (like empty lines and comments)
    179 # and sorting alphabetically (looks nicer).
    180 EMXEXP = $(call GETTOOL2,emxexp)
    181 EMXEXPFLAGS = -u
    182 DO.EMXEXP = $(EMXEXP) $(strip $(EMXEXPFLAGS) $1) | sed -e "/^$$/d" -e "/^ *;/d" | sort -d >>$2
    183 
    184 # The tool to create import libraries
    185 IMPLIB = $(call GETTOOL2,emximp)
    186 IMPLIBFLAGS.prof = -m
    187 IMPLIBFLAGS.lazy = -l
    188 IMPLIBFLAGS.KIND = $(foreach x,$(subst -, ,$(firstword $(subst /, ,$(subst $.,,$@)))),$(IMPLIBFLAGS.$x))
    189 DO.IMPLIB = $(IMPLIB) -o $@ $(strip $1 $(IMPLIBFLAGS.KIND)) $(^IC)\
    190   $(if $(^ID),\
    191   $(NL)$(IMPLIB) -o $@.data$(suffix $@) $(strip $1) $(^ID)\
    192   $(NL)$(call RMDIR,$@.tmpdir)\
    193   $(NL)$(call MKDIR,$@.tmpdir)\
    194   $(NL)cd $@.tmpdir && $(AR) x ../$(notdir $@.data$(suffix $@))\
    195   $(NL)$(AR) rs $@ $@.tmpdir/* )\
    196   $(if $(^O)$(^LIB),$(NL)$(AR) rs $@ $(^O) $(^LIB))
    197 
    198 # How to create dependencies
    199 MAKEDEP = makedep
    200 MAKEDEPFLAGS = $(CFLAGS.INC)
    201 DO.DEPS = $(MAKEDEP) $(MAKEDEPFLAGS) \
    202   -I$(subst $(SPACE), -I,$(sort $(dir $^))) -I$. -p$(@D)/ -c -S -f$@ $^
    203 
    204 # How to convert an a.out file to the OMF format
    205 #   Emxomf depends on two libs, we have to detect wethere or not emxomf is built
    206 #   or not. Unfortunately make isn't up to the job of figuring this out, so we
    207 #       must use the shell.
    208 EMXOMF = $(call GETTOOL2,emxomf)
    209 DO.EMXOMF = $(EMXOMF) $(strip $1 -o) $@ $(if $<,$<, $(subst /omf-prof/,/aout-prof/,$(subst /omf-log/,/aout-log/,$(subst /omf/,/aout/,$(@:.obj=.o)))) )
    210 
    211 # How to copy some file to installation directory
    212 # In optimize mode we have to strip the libraries after copying
    213 INSTALL=$(call CP,$1,$2)
    214 ifeq ($(MODE),opt)
    215 INSTALL += $(if $(filter-out %.a,$2),$(NL)strip --strip-debug $2)
    216 INSTALL += $(if $(filter-out %.lib,$2),$(NL)emxomf -s $2)
    217 endif
    218 
    219 # How to filter just the object files from $^
    220 ^O = $(filter %.o,$^)
    221 # Just the .imp files from $^ excluing -data.imp files.
    222 ^IC = $(filter-out %-data.imp,$(filter %.imp,$^))
    223 # Just the -data.imp files from $^
    224 ^ID = $(filter %-data.imp,$^)
    225 # How to filter just the .def files from $^
    226 ^DEF = $(filter %.def,$^)
    227 # How to filter the libraries from $^
    228 ^LIB = $(strip $(filter %.a,$^) $(filter %.lib,$^))
    229 
    230 # A newline
    231 define NL
    232 
    233 
    234 endef
    235 # Opening and closing brackets (for use inside variable expansions)
    236 OB := (
    237 CB := )
    238 COMMA := ,
    239 SPACE := $(EMPTY) $(EMPTY)
    240 # Text output separator (cannot begin with '-', echo thinks its a switch)
    241 SEP := ==========================================================================
    242 
    243 # How to remove one or more files without questions
    244 RM = rm -f $1
    245 # How to remove one or more directories without questions
    246 RMDIR = rm -rf $1
    247 # How to copy several files to a directory
    248 CP = cp $1 $2
    249 # Miscelaneous tools
    250 MKDIR = mkdir.exe -p $1
    251 # How to update a file only if it has been changed
    252 UPDATE = (cmp -s $1 $2 || mv -f $1 $2) && rm -f $1
    253 # How to touch a file
    254 TOUCH = touch $1
    255 # Re-build the original string including the ',' between args. Also escape
    256 # dollars since otherwise ash would expand them.
    257 ECHOIZE = $(subst $$,\$$,$1$(strip $(subst $(SPACE)$(COMMA),$(COMMA),$(foreach x,2 3 4 5 6 7 8 9,$(if $($x),$(COMMA) $($x))))))
    258 # How to output a text string (with appended newline)
    259 ECHO = echo "$(call ECHOIZE,$1,$2,$3,$4,$5,$6,$7,$8,$9)"
    260 # Same but append the text to a file (given with first argument)
    261 FECHO = echo "$(call ECHOIZE,$2,$3,$4,$5,$6,$7,$8,$9)" >> "$1"
    262 # How to replace the source file extension with a .o extension
    263 OBJEXT = $(patsubst %.s,%.o,$(patsubst %.asm,%.o,$(patsubst %.c,%.o,$1)))
    264 # Compute object file path given source file path (except the $. prefix)
    265 OBJFILE = $(addprefix $(.TKIND.DIR),$(call OBJEXT,$1))
    266 
    267 #------------ Variables appended by submakefiles ------------
    268 # The list of available modules
    269 MODULES :=
    270 # The help text for module list
    271 DO.HELP.MODULES :=
    272 # The help about public makefile variables
    273 DO.HELP.VARS := $(call ECHO,    MODE={dbg|opt|prf} - choose between debug, optimized and profiled build modes.)$(NL)
    274 DO.HELP.VARS += $(call ECHO,    OBJF={omf|aout} - build object files in omf or a.out format.)$(NL)
    275 # The list of work directories needeed for building all targets
    276 TARGDIRS :=
    277 # Build rules (_@_ replaced by name of generated makefile)
    278 RULES :=
    279 # The list of dependency files
    280 TARGDEPEND :=
    281 # The list of installed files
    282 INS.FILES :=
    283 
    284 .PHONY: default help all libs tools clean install install cleandep \
    285   cleandepend dep depend depdone
    286 .SUFFIXES:
    287 .SUFFIXES: .c .cpp .asm .s .o .exe .dll .a .lib .obj
    288 
    289 # Default target
    290 default: help
    291 
    292 #------------ Submakefiles ------------
    293 ifndef SUBMAK
    294 SUBMAK := version.smak $(wildcard src/*/*.smak) include/include.smak $(wildcard bsd/*/*.smak) $(wildcard gnu/*/*.smak)
    295 endif
    296 
    297 # include template rules
    298 include templates.smak
    299 
    300 # Include all submakefiles
    301 -include $(SUBMAK)
    302 
    303 # Sort and remove duplicate directories
    304 TARGDIRS := $(sort $(TARGDIRS))
    305 # Find out which directories are needed for installation
    306 INSDIRS := $(sort $(dir $(INS.FILES)))
    307 
    308 #------------ Global targets ------------
    309 help:
    310         @$(call ECHO,$(SEP))
    311         @$(call ECHO,Welcome to $(PACKAGE) version $(VERSION) build system!)
    312         @$(call ECHO,$(COPYRIGHT))
    313         @$(call ECHO,To build something, type 'make {target} {vars}', where {target} is one of:)
    314         @$(call ECHO,    all - build all available modules)
    315         @$(call ECHO,    {module-name} - build just a particular module)
    316         @$(call ECHO,    tools - build just the tools)
    317         @$(call ECHO,    libs - build all libraries)
    318         @$(call ECHO,    clean - remove all generated files (remove all built files))
    319         @$(call ECHO,    install - generate a installation tree in $(INS))
    320         @$(call ECHO,    dep - generate dependency files for all changed targets)
    321         @$(call ECHO,    cleandep - remove all dependency file)
    322         @$(call ECHO,$(SEP))
    323         @$(call ECHO,There are a number of variables than can be set in the make)
    324         @$(call ECHO,command line to control various aspects of compilation:)
    325         @$(DO.HELP.VARS)
    326         @$(call ECHO,$(SEP))
    327         @$(call ECHO,The following modules are included in this package:)
    328         @$(DO.HELP.MODULES)
    329         @$(call ECHO,$(SEP))
    330 
    331 all: $(MODULES)
     66tools tool:
     67        $(MAKE) -f toolonly.gmk all
    33268
    33369clean:
    334         $(call RMDIR,$(OUT))
     70        $(MAKE) -f Makefile.gmk $@
    33571
    336 cleandep cleandepend:
    337         $(call RM,$(TARGDEPEND))
     72install:
     73        $(MAKE) -f toolonly.gmk $@
     74        $(MAKE) -f libonly.gmk $@
    33875
    339 dep depend:
    340         @$(MAKE) -f $(MAKEFILE) --no-print-directory BUILD_DEPS=1 depdone
     76bootstrap:
     77        @echo "Warning, this goal hasn't been fully tested yet!"
     78        $(MAKE) -f toolonly.gmk all
     79        $(MAKE) -f libonly.gmk all
     80        $(MAKE) -f toolonly.gmk install
     81        $(MAKE) -f libonly.gmk install
     82        $(MAKE) -f toolonly.gmk all
     83        $(MAKE) -f libonly.gmk all
     84        $(MAKE) -f toolonly.gmk install
     85        $(MAKE) -f libonly.gmk install
    34186
    342 depdone:
    343         @$(call ECHO,Dependency files succesfully updated)
     87core:
     88        $(MAKE) -f libonly.gmk LIBC_CORE_ONLY=1 all
     89       
     90core-install:
     91        $(MAKE) -f libonly.gmk LIBC_CORE_ONLY=1 install
    34492
    345 install: all $(INSDIRS) $(INS.FILES)
    346 
    347 $. $(INSDIRS) $(TARGDIRS):
    348         $(call MKDIR,$@)
    349 
    350 # bird: add rule for forcibly re-generating the rules.
    351 rules:
    352         @$(call ECHO,smak don't generate rules anylonger!)
    353 
    354 # The general a.out -> OMF conversion rules for object files
    355 $.omf/%.obj:   
    356         $(call DO.EMXOMF)
    357 $.omf-log/%.obj:       
    358         $(call DO.EMXOMF)
    359 $.omf-prof/%.obj:       
    360         $(call DO.EMXOMF)
    361 
    362 # The general a.out -> OMF conversion rule for libraries
    363 $.omf%.lib:
    364         $(call DO.EMXOMF)
    365 
    366 #
    367 # Checkout rule
    368 #       
    369 checkout update up:
    370         cvs -q update -d -P 2>&1 | tee up.log
    371 
    372 
  • trunk/src/emx/libonly.gmk

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1719 r1720  
    55SUBMAK   := version.smak $(wildcard src/lib*/*.smak) include/include.smak
    66
    7 include Makefile
     7include Makefile.gmk
    88
    99# dummy dependencies
  • trunk/src/emx/toolonly.gmk

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1719 r1720  
    99
    1010NO_LOCAL_HEADERS=1
    11 include Makefile
     11include Makefile.gmk
Note: See TracChangeset for help on using the changeset viewer.