source: branches/libc-0.6/src/emx/Makefile.gmk@ 2533

Last change on this file since 2533 was 2457, checked in by bird, 20 years ago

it's OFFICIAL_BIRD_VERSION not _BUILD! Rebuilding ga as ga2.

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