1## BeOS and Haiku Generic Makefile Engine v2.2.0 2## Does all the hard work for the Generic Makefile 3## which simply defines the project parameters 4 5## Supports Generic Makefile v2.0, 2.01, 2.1, 2.2 6 7# determine wheather running on x86 or ppc 8MACHINE=$(shell uname -m) 9ifeq ($(MACHINE), BePC) 10 CPU = x86 11else 12 CPU = ppc 13endif 14 15# set the directory where object files and binaries will be created 16 OBJ_DIR := obj.$(CPU) 17 18# create some default settings 19ifeq ($(NAME), ) 20 NAME = NameThisApp 21endif 22 23ifeq ($(TYPE), ) 24 TYPE = APP 25endif 26 27ifeq ($(DRIVER_PATH), ) 28 DRIVER_PATH = misc 29endif 30 31# specify that the binary should be created in the object directory 32# NOTE: make doesn't find the target if its name is enclosed in 33# quotation marks 34# TARGET := "$(OBJ_DIR)/$(NAME)" 35 TARGET := $(OBJ_DIR)/$(NAME) 36 37# specify the mimeset tool 38 MIMESET := mimeset 39 40# specify the tools for adding and removing resources 41 XRES = xres 42 43# specify the tools for compiling resource definition files 44 RESCOMP = rc 45 46# platform specific settings 47 48# x86 Settings 49ifeq ($(CPU), x86) 50# set the compiler and compiler flags 51 CC = gcc 52 53# SETTING: set the CFLAGS for each binary type 54 ifeq ($(TYPE), DRIVER) 55 CFLAGS += -D_KERNEL_MODE=1 -no-fpic 56 else 57 CFLAGS += 58 endif 59 60# SETTING: set the proper optimization level 61 ifeq ($(OPTIMIZE), FULL) 62 OPTIMIZER = -O3 63 else 64 ifeq ($(OPTIMIZE), SOME) 65 OPTIMIZER = -O1 66 else 67 ifeq ($(OPTIMIZE), NONE) 68 OPTIMIZER = -O0 69 else 70# OPTIMIZE not set so set to full 71 OPTIMIZER = -O3 72 endif 73 endif 74 endif 75 76 77 78# SETTING: set proper debugger flags 79 ifeq ($(DEBUGGER), TRUE) 80 DEBUG += -g 81 OPTIMIZER = -O0 82 endif 83 84 CFLAGS += $(OPTIMIZER) $(DEBUG) 85 86# SETTING: set warning level 87 ifeq ($(WARNINGS), ALL) 88 CFLAGS += -Wall -Wno-multichar -Wno-ctor-dtor-privacy 89 else 90 ifeq ($(WARNINGS), NONE) 91 CFLAGS += -w 92 endif 93 endif 94 95# set the linker and linker flags 96 LD = gcc 97 LDFLAGS += $(DEBUG) 98 99# SETTING: set linker flags for each binary type 100 ifeq ($(TYPE), APP) 101 LDFLAGS += -Xlinker -soname=_APP_ 102 else 103 ifeq ($(TYPE), SHARED) 104 LDFLAGS += -nostart -Xlinker -soname=$(NAME) 105 else 106 ifeq ($(TYPE), DRIVER) 107 LDFLAGS += -nostdlib /boot/develop/lib/x86/_KERNEL_ \ 108 /boot/develop/lib/x86/haiku_version_glue.o 109 endif 110 endif 111 endif 112 113 114else 115 116# ppc Settings 117ifeq ($(CPU), ppc) 118# set the compiler and compiler flags 119 CC = mwcc 120 CFLAGS += 121 122# SETTING: set the proper optimization level 123 ifeq ($(OPTIMIZE), FULL) 124 OPTIMIZER = -O7 125 else 126 ifeq ($(OPTIMIZE), SOME) 127 OPTIMIZER = -O3 128 else 129 ifeq ($(OPTIMIZE), NONE) 130 OPTIMIZER = -O0 131 else 132# OPTIMIZE not set so set to full 133 OPTIMIZER = -O7 134 endif 135 endif 136 endif 137 138 #set the proper debugger settings 139 ifeq ($(DEBUGGER), TRUE) 140 DEBUG += -g 141 endif 142 143 CFLAGS += $(OPTIMIZER) $(DEBUG) 144 145# SETTING: set warning level 146 ifeq ($(WARNINGS), ALL) 147 CFLAGS += -w on -requireprotos 148 else 149 ifeq ($(WARNINGS), NONE) 150 CFLAGS += -w off 151 endif 152 endif 153 154 # clear the standard environment variable 155 # now there are no standard libraries to link against 156 BELIBFILES= 157 158# set the linker and linker flags 159 LD = mwldppc 160 161# SETTING: set linker flags for each binary type 162 ifeq ($(TYPE), APP) 163 LDFLAGS += 164 else 165 ifeq ($(TYPE), SHARED) 166 LDFLAGS += -xms 167 endif 168 endif 169 170 ifeq ($(TYPE), DRIVER) 171 LDFLAGS += -nodefaults \ 172 -export all \ 173 -G \ 174 /boot/develop/lib/ppc/glue-noinit.a \ 175 /boot/develop/lib/ppc/_KERNEL_ 176 else 177 LDFLAGS += -export pragma \ 178 -init _init_routine_ \ 179 -term _term_routine_ \ 180 -lroot \ 181 /boot/develop/lib/ppc/glue-noinit.a \ 182 /boot/develop/lib/ppc/init_term_dyn.o \ 183 /boot/develop/lib/ppc/start_dyn.o 184 endif 185 186 187# SETTING: output symbols in an xMAP file 188 ifeq ($(SYMBOLS), TRUE) 189 LDFLAGS += -map $(TARGET).xMAP 190 endif 191 192# SETTING: output debugging info to a .SYM file 193 ifeq ($(DEBUGGER), TRUE) 194 LDFLAGS += -g -osym $(TARGET).SYM 195 endif 196 197endif 198endif 199 200 201# psuedo-function for converting a list of source files in SRCS variable 202# to a corresponding list of object files in $(OBJ_DIR)/xxx.o 203# The "function" strips off the src file suffix (.ccp or .c or whatever) 204# and then strips of the directory name, leaving just the root file name. 205# It then appends the .o suffix and prepends the $(OBJ_DIR)/ path 206define SRCS_LIST_TO_OBJS 207 $(addprefix $(OBJ_DIR)/, $(addsuffix .o, $(foreach file, $(SRCS), \ 208 $(basename $(notdir $(file)))))) 209endef 210 211define SRCS_LIST_TO_DEPENDS 212 $(addprefix $(OBJ_DIR)/, $(addsuffix .d, $(foreach file, $(SRCS), \ 213 $(basename $(notdir $(file)))))) 214endef 215 216OBJS = $(SRCS_LIST_TO_OBJS) 217DEPENDS = $(SRCS_LIST_TO_DEPENDS) 218 219# create a unique list of paths to our sourcefiles 220SRC_PATHS += $(sort $(foreach file, $(SRCS), $(dir $(file)))) 221 222# add source paths to VPATH if not already present 223VPATH := 224VPATH += $(addprefix :, $(subst ,:, $(filter-out $($(subst, :, ,$(VPATH))), $(SRC_PATHS)))) 225 226# SETTING: build the local and system include paths 227ifeq ($(CPU), x86) 228 LOC_INCLUDES = $(foreach path, $(SRC_PATHS) $(LOCAL_INCLUDE_PATHS), $(addprefix -I, $(path))) 229 SYS_INCLUDES += -I- 230 SYS_INCLUDES += $(foreach path, $(SYSTEM_INCLUDE_PATHS), $(addprefix -I, $(path))) 231else 232ifeq ($(CPU), ppc) 233 LOC_INCLUDES = $(foreach path, $(SRC_PATHS) $(LOCAL_INCLUDE_PATHS), $(addprefix -I, $(path))) 234 SYS_INCLUDES += -i- 235 SYS_INCLUDES += $(foreach path, $(SYSTEM_INCLUDE_PATHS), $(addprefix -i , $(path))) 236endif 237endif 238 239INCLUDES = $(LOC_INCLUDES) $(SYS_INCLUDES) 240 241# SETTING: add the -L prefix to all library paths to search 242LINK_PATHS = $(foreach path, $(SRC_PATHS) $(LIBPATHS), \ 243 $(addprefix -L, $(path))) 244 245# SETTING: specify the additional libraries to link against 246# if the libraries have a .so or .a prefix, or if they are _APP_ or _KERNEL_ 247# simply add them to the list 248LINK_LIBS += $(filter %.so %.a _APP_ _KERNEL_, $(LIBS)) 249# if the libraries do not have suffixes and are not _APP_ or _KERNEL_ 250# prepend -l to each name: be becomes -lbe 251LINK_LIBS += $(foreach lib, $(filter-out %.so %.a _APP_ _KERNEL_, $(LIBS)), $(addprefix -l, $(lib))) 252 253# add to the linker flags 254LDFLAGS += $(LINK_PATHS) $(LINK_LIBS) 255 256# SETTING: add the defines to the compiler flags 257CFLAGS += $(foreach define, $(DEFINES), $(addprefix -D, $(define))) 258 259# SETTING: add the additional compiler flags 260CFLAGS += $(COMPILER_FLAGS) 261 262# SETTING: add the additional linker flags 263LDFLAGS += $(LINKER_FLAGS) 264 265# SETTING: use the archive tools if building a static library 266# otherwise use the linker 267ifeq ($(TYPE), STATIC) 268 BUILD_LINE = ar -cru "$(TARGET)" $(OBJS) 269else 270 BUILD_LINE = $(LD) -o $@ $(OBJS) $(LDFLAGS) 271endif 272 273# pseudo-function for converting a list of resource definition files in RDEFS 274# variable to a corresponding list of object files in $(OBJ_DIR)/xxx.rsrc 275# The "function" strips off the rdef file suffix (.rdef) and then strips 276# of the directory name, leaving just the root file name. 277# It then appends the .rsrc suffix and prepends the $(OBJ_DIR)/ path 278define RDEFS_LIST_TO_RSRCS 279 $(addprefix $(OBJ_DIR)/, $(addsuffix .rsrc, $(foreach file, $(RDEFS), \ 280 $(basename $(notdir $(file)))))) 281endef 282 283# create the resource definitions instruction in case RDEFS is not empty 284 ifeq ($(RDEFS), ) 285 RSRCS += 286 else 287 RSRCS += $(RDEFS_LIST_TO_RSRCS) 288 endif 289 290# create the resource instruction 291 ifeq ($(RSRCS), ) 292 DO_RSRCS := 293 else 294 DO_RSRCS := $(XRES) -o "$(TARGET)" $(RSRCS) 295 endif 296 297 298# define the actual work to be done 299default: $(TARGET) 300 301$(TARGET): $(OBJ_DIR) $(OBJS) $(RSRCS) 302 $(BUILD_LINE) 303 $(DO_RSRCS) 304 $(MIMESET) -f $@ 305 306 307# rule to create the object file directory if needed 308$(OBJ_DIR):: 309 @[ -d $(OBJ_DIR) ] || mkdir $(OBJ_DIR) > /dev/null 2>&1 310 311# rules to make the dependency files 312$(OBJ_DIR)/%.d : %.c 313 [ -d $(OBJ_DIR) ] || mkdir $(OBJ_DIR) > /dev/null 2>&1; \ 314 mkdepend $(LOC_INCLUDES) -p .c:$(OBJ_DIR)/%n.o -m -f $@ $< 315$(OBJ_DIR)/%.d : %.cpp 316 [ -d $(OBJ_DIR) ] || mkdir $(OBJ_DIR) > /dev/null 2>&1; \ 317 mkdepend $(LOC_INCLUDES) -p .cpp:$(OBJ_DIR)/%n.o -m -f $@ $< 318$(OBJ_DIR)/%.d : %.cp 319 [ -d $(OBJ_DIR) ] || mkdir $(OBJ_DIR) > /dev/null 2>&1; \ 320 mkdepend $(LOC_INCLUDES) -p .cp:$(OBJ_DIR)/%n.o -m -f $@ $< 321$(OBJ_DIR)/%.d : %.cc 322 [ -d $(OBJ_DIR) ] || mkdir $(OBJ_DIR) > /dev/null 2>&1; \ 323 mkdepend $(LOC_INCLUDES) -p .cc:$(OBJ_DIR)/%n.o -m -f $@ $< 324$(OBJ_DIR)/%.d : %.C 325 [ -d $(OBJ_DIR) ] || mkdir $(OBJ_DIR) > /dev/null 2>&1; \ 326 mkdepend $(LOC_INCLUDES) -p .C:$(OBJ_DIR)/%n.o -m -f $@ $< 327$(OBJ_DIR)/%.d : %.CC 328 [ -d $(OBJ_DIR) ] || mkdir $(OBJ_DIR) > /dev/null 2>&1; \ 329 mkdepend $(LOC_INCLUDES) -p .CC:$(OBJ_DIR)/%n.o -m -f $@ $< 330$(OBJ_DIR)/%.d : %.CPP 331 [ -d $(OBJ_DIR) ] || mkdir $(OBJ_DIR) > /dev/null 2>&1; \ 332 mkdepend $(LOC_INCLUDES) -p .CPP:$(OBJ_DIR)/%n.o -m -f $@ $< 333 334-include $(DEPENDS) 335 336# rules to make the object files 337$(OBJ_DIR)/%.o : %.c 338 $(CC) -c $< $(INCLUDES) $(CFLAGS) -o $@ 339$(OBJ_DIR)/%.o : %.cpp 340 $(CC) -c $< $(INCLUDES) $(CFLAGS) -o $@ 341$(OBJ_DIR)/%.o : %.cp 342 $(CC) -c $< $(INCLUDES) $(CFLAGS) -o $@ 343$(OBJ_DIR)/%.o : %.cc 344 $(CC) -c $< $(INCLUDES) $(CFLAGS) -o $@ 345$(OBJ_DIR)/%.o : %.C 346 $(CC) -c $< $(INCLUDES) $(CFLAGS) -o $@ 347$(OBJ_DIR)/%.o : %.CC 348 $(CC) -c $< $(INCLUDES) $(CFLAGS) -o $@ 349$(OBJ_DIR)/%.o : %.CPP 350 $(CC) -c $< $(INCLUDES) $(CFLAGS) -o $@ 351 352# rules to compile resource definition files 353$(OBJ_DIR)/%.rsrc : %.rdef 354 $(RESCOMP) -o $@ $< 355$(OBJ_DIR)/%.rsrc : %.RDEF 356 $(RESCOMP) -o $@ $< 357 358# rules to handle lex/flex and yacc/bison files 359 360$(OBJ_DIR)/%.o: %.l 361 flex $< 362 $(CC) -c $(INCLUDES) $(CFLAGS) lex.yy.c -o $@ 363$(OBJ_DIR)/%.o: %.y 364 bison -d -y $< 365 $(CC) -c $(INCLUDES) $(CFLAGS) y.tab.c -o $@ 366 367# empty rule. Things that depend on this rule will always get triggered 368FORCE: 369 370# The generic clean command. Delete everything in the object folder. 371clean :: FORCE 372 -rm -rf $(OBJ_DIR) 373 374# remove just the application from the object folder 375rmapp :: 376 -rm -f $(TARGET) 377 378# make it easy to install drivers for testing 379USER_BIN_PATH = /boot/home/config/add-ons/kernel/drivers/bin 380USER_DEV_PATH = /boot/home/config/add-ons/kernel/drivers/dev 381 382driverinstall :: 383ifeq ($(TYPE), DRIVER) 384 copyattr --data $(OBJ_DIR)/$(NAME) $(USER_BIN_PATH)/$(NAME) 385 mkdir -p $(USER_DEV_PATH)/$(DRIVER_PATH) 386 ln -sf $(USER_BIN_PATH)/$(NAME) $(USER_DEV_PATH)/$(DRIVER_PATH)/$(NAME) 387endif 388