1# 2# Copyright (C) 2017 and later: Unicode, Inc. and others. 3# License & terms of use: http://www.unicode.org/copyright.html 4# 5# 6# Copyright (C) 2010-2012 IBM Corporation and Others, All Rights Reserved. 7# 8all: glurens ii plugs testprog 9 10# extra files that need generation. 11PLUG_EXTRA_DEPS= 12UNAME=$(shell uname) 13DOT=../../c 14SOBJ=ao 15ifeq ($(UNAME),Linux) 16LIBPATH_VAR=LD_LIBRARY_PATH 17PLUG_EXTRA_LDFLAGS=-fPIC 18PBLD_EXTRA_FLAGS=-fPIC 19GLUE_EXTRA_CFLAGS= -fPIC 20PLUGLIB_SO=so 21else 22ifeq ($(UNAME),Darwin) 23LIBPATH_VAR=DYLD_LIBRARY_PATH 24PLUG_EXTRA_LDFLAGS=-exported_symbols_list $(GLUE_EXPORT) -dynamiclib -dynamic 25PLUG_EXTRA_DEPS+=$(GLUE_EXPORT) 26PLUGLIB_SO=dylib 27else 28ifeq ($(UNAME),AIX) 29LIBPATH_VAR=LIBPATH 30#PLUG_EXTRA_LDFLAGS=-exported_symbols_list $(GLUE_EXPORT) -dynamiclib -dynamic 31PLUG_EXTRA_DEPS+=$(GLUE_EXPORT) 32PLUGLIB_SO=a 33SOBJ=o 34else 35$(warning **********************************) 36$(warning this script may not know how to handle your $(UNAME) system) 37endif 38endif 39endif 40 41SUBHEAD="*** ICU" 42 43srcdir=$(shell pwd) 44 45PROVIDER=provider 46LIBPROVIDER=lib$(PROVIDER).a 47 48#libs: $(ICU_TARBALLS_VERS:%=$(OUT)/%/lib/$(LIBPROVIDER)) 49 50PLUGLIB_INST=$(C_INS)/r$(PLUGLIB) 51PLUGLIB_ICU_CONFIG=$(PLUGLIB_INST)/bin/icu-config 52#PLUGLIB_SO=$(shell $(PLUGLIB_ICU_CONFIG) --so 2>/dev/null ) 53PLUGLIB_NAME=libicuprov.$(PLUGLIB_MAJ).$(PLUGLIB_SO) 54#PLUGLIB_MAJ=$(echo $(PLUGLIB) | cut -d_ -f-1 | tr -d _ ) 55#GLOUT_ICU=$(ICU_TARBALLS_VERS:%=$(GLOUT)/%/$(OK)) 56PLUGLIB_AVAILABLE=$(shell echo $(PROVIDER_AVAILABLE) | tr '.' '_') 57PLUGLIB_AVAILABLE_DATA=$(PLUGLIB_AVAILABLE:%=$(BUILD)/%/data/out/tmp/*.o) 58PLUGLIB_AVAILABLE_STATICS=$(PLUGLIB_AVAILABLE:%=$(BUILD)/%/[ci]*/*.$(SOBJ)) 59PLUGLIB_OUTLIBS=$(PLUGLIB:%=$(OUT)/%/lib/$(PLUGLIB_NAME)) 60 61 62 63## configuration 64# Absolute path to this dir. 65# dir holding ICUs to be built 66MULTICU_ROOT=../.. 67include $(MULTICU_ROOT)/c/Makefile-c.inc 68ICU_CONFIG=icu-config-nosanity 69ICU_CONFIG_ORIG=icu-config 70 71# subdirs... 72# prefix to distinguish it from non-provider builds 73P_PREFIX=p 74BUILD=$(M_TMP)/$(P_PREFIX)bld 75INST=$(M_TMP)/$(P_PREFIX)ins 76SRC=$(M_TMP)/$(P_PREFIX)src 77OUT=$(TOP)/out 78SOURCE=$(S_SRCDIR) 79GLUE=glue 80GLUE_EXPORT=$(GLUE)/export.txt 81GLOUT=$(M_TMP)/$(P_PREFIX)glout 82# header locations 83INCGLUE=$(TOP)/$(GLUE)/include 84# relative path to icuglue within glout 85GLUREN=gluren/include/icuglue 86# relative path to gluren.h 87GLUREN_H=$(GLUREN)/gluren.h 88# Special 'configure' caller 89SUPERCONF=$(TOP)/$(MULTICU_ROOT)/c/superconf.sh 90# options to compilation (such as, debug) 91XOPTS=$(EXTRA_COMPILE_OPTS) 92OK=ok 93MOPTS= 94 95# directories that need to be built 96ALLDIRS=$(INST) $(BUILD) $(SRC) $(GLOUT) $(OUT) $(GLOUT)/$(PLUGLIB) $(OUT)/$(PLUGLIB)/bin 97# The 'ok' flag file for installations 98INST_ICU=$(PLUGLIB_AVAILABLE:%=$(INST)/%/$(OK)) 99BUILD_ICU=$(PLUGLIB_AVAILABLE:%=$(BUILD)/%/$(OK)) 100# this has to do with the pluglib 101GLOUT_ICU=$(PLUGLIB:%=$(GLOUT)/%/obj-$(OK)) 102#SRC_ICU=$(ICU_TARBALLS_VERS:%=$(SRC)/%/$(OK)) 103# gluren.h files for each version 104GLUREN_ICU=$(PLUGLIB_AVAILABLE:%=$(BUILD)/%/$(GLUREN_H)) 105#? 106CONFIGURE_CMD= 107# Options passed to configure 108CONFIGURE_OPTS=--enable-static --disable-shared --with-data-packaging=static --disable-extras --disable-icuio --disable-layout --disable-tests --disable-samples $(EXTRA_CONFIGURE_OPTS) 109# additional options passed to make 110MAKE_XTRA_OPTS="PKGDATA_MODE=static" 111# additional options passed to make install 112MAKE_INSTALL_XTRA_OPTS=$(MAKE_XTRA_OPTS) 113 114# Munged source names: list of C++, O etc files for Frontend 115PARTSUFF=_fe 116GL_FE_CXX=$(notdir $(wildcard $(GLUE)/*$(PARTSUFF).cpp)) 117GL_FE_FILES=$(GL_FE_CXX:%.cpp=$(GLUE)/%.cpp) 118GL_FE_O=$(GL_FE_CPP:%.cpp=%.o) 119GL_PARTS=$(GL_FE_CXX:%$(PARTSUFF).cpp=%) 120# C flags used in Glue compilation 121GLUE_CFLAGS=-I$(INCGLUE) $(GLUE_EXTRA_CFLAGS) 122 123# icu-config switches for compiling: C and C++ 124ICU_CONFIG_COMMON=--cppflags 125# icu-config switches for C 126ICU_CONFIG_CC=--cc $(ICU_CONFIG_COMMON) --cflags 127# icu-config switches for C++ 128ICU_CONFIG_CXX=--cxx $(ICU_CONFIG_COMMON) --cxxflags 129 130# sigh, include common. 131PLUG_EXTRA_FLAGS=-I$(BUILD)/$(PLUGLIB)/common -I$(M_TMP)/build/r$(PLUGLIB)/icu/source/common 132 133include Makefile.local 134 135 136 137# Usage: $(call SILENT_COMPILE,logfile,cmd) 138ifndef VERBOSE 139 LOG_COMPILE=echo build with VERBOSE=1 to unhide compile ; ( ($(2) 2>&1) > $(1) || (echo "Compile failed, see logfile in $(1) for details." ;exit 1)) 140else 141 LOG_COMPILE=$(2) 2>&1 | tee $(1) 142endif 143 144ECHO_COMPILE=echo "\# ${subst ",\",$(1)}" ; ( $(1) || ( exit 1) ) 145 146PLUGLIB=$(shell echo $(PROVIDER_TARGET) | tr '.' '_' ) 147PLUGLIB_MAJ=$(shell ./icu2symver.sh $(PLUGLIB)) 148 149## @build All installed ICUs 150ii: $(GLOUT_ICU) 151 152# Don't delete these files 153.PRECIOUS: (INST_ICU) $(BUILD_ICU) $(SRC_ICU) $(ICU_TARBALLS_VERS:%=$(BUILD)/%/config.status) $(ICU_TARBALLS_VERS:%=$(GLOUT)/%/obj-$(OK)) $(ICU_TARBALLS_VERS:%=$(BUILD)/%/config/$(ICU_CONFIG)) $(PLUGLIB_ICU_CONFIG) 154 155# cleanup 156clean: 157 -rm -rf $(ALLDIRS) 158 -$(MAKE) -C ../.. clean 159 160# create all empty work dirs 161$(ALLDIRS): 162 -mkdir -p $(@) 163 164# Build r$(PLUGLIB) from ../../c 165$(PLUGLIB_ICU_CONFIG): 166 @echo "$(SUBHEAD) "$(PLUGLIB) "(plugin) building..." 167 $(call LOG_COMPILE,../../c/ricus$(PLUGLIB).log,$(MAKE) MAKE_OPTS=$(MAKE_OPTS) XTRA_RICU_CPPFLAGS=$(XTRA_RICU_CPPFLAGS) -C ../../c ICUVERS=$(PLUGLIB) ricus) 168 169# build the glue objects for TARGET 170# used to be %/* instead of $(PLUGLIB) - now, wire it down to pluglib. 171$(GLOUT)/$(PLUGLIB)/obj-$(OK): $(GLOUT) glurens $(PLUGLIB_ICU_CONFIG) $(GL_FE_FILES) $(ALLDIRS) 172 @echo $(SUBHEAD) $(PLUGLIB) "(plugin) building glue.." 173# $(shell $(BUILD)/$(PLUGLIB)/config/$(ICU_CONFIG) $(ICU_CONFIG_CC)) $(GLUE_CFLAGS) -c -DICUGLUE_VER=$(PLUGLIB) -o $(GLOUT)/$(PLUGLIB)/gl_be_c_$(PLUGLIB).o $(GL_BE_C:%.c=$(GLUE)/%.c) 174# $(shell $(BUILD)/$(PLUGLIB)/config/$(ICU_CONFIG) $(ICU_CONFIG_CXX)) $(GLUE_CFLAGS) -c -DICUGLUE_VER=$(PLUGLIB) -o $(GLOUT)/$(PLUGLIB)/gl_be_cxx_$(PLUGLIB).o $(GL_BE_CXX:%.cpp=$(GLUE)/%.cpp) 175 -rm -rf $(GLOUT)/$(PLUGLIB)/include 176 mkdir -p $(GLOUT)/$(PLUGLIB)/include/icuglue/include 177# for each version.. build all OTHER FE files 178# TODO: check is unnecessary, not permitted. 179# TODO: change to depend instead of for list. 180 @for ver in $(PLUGLIB_AVAILABLE) ; \ 181 do \ 182 echo "*$(SUBHEAD)" $$ver "(provider)" for $(PLUGLIB) "(plugin)" ; \ 183 if [ ! "$$ver" = "$(PLUGLIB)" ]; \ 184 then \ 185 for part in $(GL_PARTS) ; \ 186 do \ 187 echo "**$(SUBHEAD)" $$ver "(provider) backend: ---- " "$$part" "----" ; \ 188 $(call ECHO_COMPILE,$(shell $(PLUGLIB_ICU_CONFIG) --noverify $(ICU_CONFIG_CXX)) $(GLUE_CFLAGS) -c -I$(TOP)/$(BUILD)/$$ver/gluren/include -DICUGLUE_VER=$$ver -DICUGLUE_VER_STR=\"$$ver\" "-DGLUE_SYM(x)=glue ## x ## $$ver" -o $(GLOUT)/$(PLUGLIB)/$${part}_$${ver}_for_$(PLUGLIB).o $(GLUE)/$${part}$(PARTSUFF).cpp $(XOPTS) ) || exit 1 ; \ 189 done ; \ 190 echo " GLUE_VER( $$ver ) " >> $(GLOUT)/$(PLUGLIB)/include/icuglue/glver.h; \ 191 fi \ 192 done 193# build 'this version' FE files 194 @for part in $(GL_PARTS) ; \ 195 do \ 196 echo "ICU" $(PLUGLIB) "(plugin) building plugin for ------- $$part -----" ; \ 197 $(call ECHO_COMPILE,$(shell $(PLUGLIB_ICU_CONFIG) --noverify $(ICU_CONFIG_CXX)) $(GLUE_CFLAGS) -I$(GLOUT)/$(PLUGLIB)/include -c -o $(GLOUT)/$(PLUGLIB)/$${part}_$(PLUGLIB).o $(GLUE)/$${part}$(PARTSUFF).cpp $(XOPTS) $(PLUG_EXTRA_FLAGS) ) || exit 1 ; \ 198 done 199 touch $@ 200 201plugs: $(PLUGLIB_OUTLIBS) $(OUT)/$(PLUGLIB_MAJ:%=icuplugins%.txt) 202 203install-plugs: $(PLUGLIB_INST)/lib/$(PLUGLIB_NAME) $(PLUGLIB_INST)/lib/icu/icuplugins$(PLUGLIB_MAJ).txt 204 echo "Plugins installed for testing." 205 206#TODO: should be 'install' not 'cp' 207$(PLUGLIB_INST)/lib/$(PLUGLIB_NAME) $(PLUGLIB_INST)/lib/icu/icuplugins$(PLUGLIB_MAJ).txt: $(PLUGLIB_OUTLIBS) 208 cp $(PLUGLIB_OUTLIBS) $(PLUGLIB_INST)/lib 209 echo "# Generated. " > $(PLUGLIB_INST)/lib/icu/icuplugins$(PLUGLIB_MAJ).txt 210 @for part in $(GL_PARTS) ; \ 211 do \ 212 echo "$(PLUGLIB_NAME) $${part}_provider_plugin" >> $(PLUGLIB_INST)/lib/icu/icuplugins$(PLUGLIB_MAJ).txt ; \ 213 echo " $${part}_provider_plugin" ; \ 214 done 215 216$(GLUE_EXPORT): Makefile $(GL_FE_FILES) 217 echo "# Generated for installation. " > $@ 218 @for part in $(GL_PARTS) ; \ 219 do \ 220 echo "_$${part}_provider_plugin" >> $@ ; \ 221 echo " _$${part}_provider_plugin" ; \ 222 done 223 224$(OUT)/icuplugins$(PLUGLIB_MAJ).txt: $(PLUGLIB_OUTLIBS) Makefile 225 echo "# Generated for testing." > $@ 226 @for part in $(GL_PARTS) ; \ 227 do \ 228 echo "$(PLUGLIB_NAME) $${part}_provider_plugin" >> $@ ; \ 229 echo " $${part}_provider_plugin" ; \ 230 done 231 232TESTPROG=$(GL_PARTS:%=%diff$(EXEEXT)) 233 234testprog: $(PLUGLIB:%=$(OUT)/%/bin/$(TESTPROG)) 235 236check-icu2symver: 237 ./check-icu2symver.sh 238 239generate-gdbrc: 240 echo "# generated by $@" > .gdbrc 241 echo "set environment ICU_PLUGINS=$(OUT)" >> .gdbrc 242 echo "set environment $(LIBPATH_VAR)=$(OUT)/../$(PLUGLIB_INST)/lib:$(OUT)/$(PLUGLIB)/lib" >> .gdbrc 243 244 245check: check-icu2symver all testprog $(OUT)/icuplugins$(PLUGLIB_MAJ).txt 246 ICU_PLUGINS=$(OUT) $(LIBPATH_VAR)=$(PLUGLIB_INST)/lib:out/$(PLUGLIB)/lib $(PLUGLIB_INST)/bin/icuinfo || ( echo "ICU broken." ; /bin/false ) 247 ICU_PLUGINS=$(OUT) $(LIBPATH_VAR)=$(PLUGLIB_INST)/lib:out/$(PLUGLIB)/lib $(PLUGLIB_INST)/bin/icuinfo -L || ( echo "Plugin broken." ; /bin/false ) 248 @for prog in $(TESTPROG) ; \ 249 do \ 250 echo "# ICU_PLUGINS=$(OUT) $(LIBPATH_VAR)=$(PLUGLIB_INST)/lib:out/$(PLUGLIB)/lib out/$(PLUGLIB)/bin/$${prog}" ; \ 251 ICU_PLUGINS=$(OUT) $(LIBPATH_VAR)=$(PLUGLIB_INST)/lib:out/$(PLUGLIB)/lib out/$(PLUGLIB)/bin/$${prog} || ( echo "$${prog} failed." ; exit 1 ) ; \ 252 done 253 254install-check: install-plugs 255 $(LIBPATH_VAR)=$(PLUGLIB_INST)/lib $(PLUGLIB_INST)/bin/icuinfo -L || ( echo "Plugin broken." ; /bin/false ) 256 @for prog in $(TESTPROG) ; \ 257 do \ 258 echo "# $${prog}" ; \ 259 $(LIBPATH_VAR)=$(PLUGLIB_INST)/lib out/$(PLUGLIB)/bin/$${prog} || ( echo "$${prog} against installed failed." ; exit 1 ) ; \ 260 done 261 262$(OUT)/$(PLUGLIB)/bin/$(TESTPROG): $(GLOUT)/$(PLUGLIB)/obj-$(OK) $(OUT)/$(PLUGLIB)/provider_version.h $(ALLDIRS) 263 @for prog in $(TESTPROG) ; \ 264 do \ 265 ${call ECHO_COMPILE,$(shell $(PLUGLIB_ICU_CONFIG) --cxx --cxxflags --cppflags --ldflags) -o $(OUT)/$(PLUGLIB)/bin/$${prog} -I$(OUT)/$(PLUGLIB) $(TESTPROG_XTRA_OPTS) $(srcdir)/$${prog}.cpp} || exit 1 ; \ 266 done 267 268$(OUT)/%/lib/$(PLUGLIB_NAME): $(GLOUT)/%/obj-$(OK) $(PLUG_EXTRA_DEPS) 269 -mkdir -p $(OUT)/$*/lib 270 $(shell $(PLUGLIB_ICU_CONFIG) --cxx --cxxflags --cppflags --ldflags) $(PLUG_EXTRA_LDFLAGS) -shared -o $@ $(GLOUT)/$*/*.o $(PLUGLIB_AVAILABLE_DATA) $(PLUGLIB_AVAILABLE_STATICS) 271 272# cp $@ $(C_INS)/r$*/lib/ 273 274$(OUT)/%/lib/$(LIBPROVIDER): $(GLOUT)/%/obj-$(OK) 275 -mkdir -p $(OUT)/$*/lib 276 echo copy includes 277 ar -rv $@ $(GLOUT)/$*/*.o 278 ranlib $@ 279 280## @@ build glu rename files 281glurens: $(GLUREN_ICU) 282 283# build single gluren.h 284$(BUILD)/%/$(GLUREN_H): $(BUILD)/%/ok Makefile makegluren.sh 285 -mkdir -p $(BUILD)/$*/$(GLUREN) 286 env SRC="$(SRC)" SOURCE="$(SOURCE)" GLUE="$(GLUE)" ./makegluren.sh $@ $* 287 @fgrep -q OICU_ $@ || ( echo "Error: $@: no OICU_ symbols found. Removing gluren.h " ; rm -f $@ ; exit 1) 288 289$(BUILD)/%/config/$(ICU_CONFIG): $(BUILD)/%/config/$(ICU_CONFIG_ORIG) icu-config.sed $(BUILD)/%/ok 290 sed -f icu-config.sed < $(BUILD)/$*/config/$(ICU_CONFIG_ORIG) > $(BUILD)/$*/config/$(ICU_CONFIG) && chmod a+rx $(BUILD)/$*/config/$(ICU_CONFIG) 291 292# perform installation 293$(INST)/%/ok: $(BUILD)/%/ok 294 echo $(SUBHEAD) $* "(backend) installing..." 295 echo "INST " "[" $* "]" 296 mkdir -p $(INST)/$* 297 -$(call LOG_COMPILE,$(BUILD)$*/ok.log,$(MAKE) $(MOPTS) -C $(BUILD)/$* install $(MAKE_INSTALL_XTRA_OPTS)) 298 touch $@ 299 300# unpack ICU and patch 301$(SRC)/%/ok: $(ICUS)/icu4c-%-src.tgz 302 -[ -d $(SRC)/$* ] && rm -rf $(SRC)/$* 303 @echo $(SUBHEAD) $* "(backend) unpacking..." 304 mkdir -p $(SRC)/$* 305 $(call LOG_COMPILE,$(SRC)/$*/unpack.log,( cd $(SRC)/$* && gunzip -d < $(TOP)/$(ICUS)/icu4c-$*-src.tgz | tar xvfp - )) 306 ([ -f $(DOT)/patch/$* ] && patch -d $(SRC)/$* -p1 < $(DOT)/patch/$*) || true 307 touch $@ 308 309# config 310$(BUILD)/%/config.status: $(SRC)/%/ok 311 @echo $(SUBHEAD) $* "(backend) configuring..." 312 -[ -d $(BUILD)/$* ] && rm -rf $(BUILD)/$* 313 mkdir -p $(BUILD)/$* 314 $(call LOG_COMPILE,$(BUILD)/$*/configure.log,( cd $(BUILD)/$* && env CFLAGS="$(CFLAGS) $(PBLD_EXTRA_FLAGS)" CXXFLAGS="$(CXXFLAGS) $(PBLD_EXTRA_FLAGS)" $(shell $(SUPERCONF) $(TOP)/$(SRC)/$*/$(SOURCE) $*) $(CONFIGURE_OPTS) --srcdir=$(TOP)/$(SRC)/$*/$(SOURCE) --prefix=$(TOP)/$(INST)/$* )) 315 316# build 317# note: regex had renaming problems, and spoof depends on regex. Nuke them. 318$(BUILD)/%/ok: $(BUILD)/%/config.status 319 @echo $(SUBHEAD) $* "(backend) building.." 320 $(call LOG_COMPILE,$(BUILD)/$*/ok2.log,( $(MAKE) $(MOPTS) -C $(BUILD)/$* all $(MAKE_XTRA_OPTS) )) 321 @if [ ! -f $(BUILD)/$*/common/putil.$(SOBJ) ]; \ 322 then \ 323 echo re-unpacking $(BUILD)/$*/common ; \ 324 ( cd $(BUILD)/$*/common && ar xf ../lib/libsicuuc.a || echo could not unpack ../lib/libsicuuc.a ) ; \ 325 echo re-unpacking $(BUILD)/$*/i18n ; \ 326 ( cd $(BUILD)/$*/i18n && ar xf ../lib/libsicui18n.a || echo could not unpack ../lib/libsicui18n.a ) ; \ 327 fi 328 @if [ ! -f $(BUILD)/$*/common/putil.$(SOBJ) ]; \ 329 then \ 330 echo ERROR: still could not find $(BUILD)/$*/common/putil.$(SOBJ) - build may fail.; \ 331 fi 332 -rm -f $(BUILD)/$*/i18n/uregex*.* $(BUILD)/$*/i18n/uspoof*.*o* 333 touch $@ 334 335info help: 336 @echo $(SUBHEAD) Provider Build 337 @echo "Targetting Provider against ICU $(PROVIDER_TARGET) ($(PLUGLIB), major $(PLUGLIB_MAJ))" 338 @echo "Available plugins: $(PROVIDER_AVAILABLE) ($(PLUGLIB_AVAILABLE))" 339 @echo "Available keywords:" 340 @for ver in $(PROVIDER_AVAILABLE); do \ 341 echo " ...@provider=icu"`echo $$ver | ./icu2symver.sh`; \ 342 done 343 @echo "Plugin library will be $(PLUGLIB_NAME)" 344 @echo 345 @echo Available ICU tarballs: $(ICU_TARBALLS) 346 @echo Available ICU versions: $(shell echo $(ICU_TARBALLS_VERS) | tr '_' '.') 347 348$(OUT)/$(PLUGLIB)/provider_version.h: Makefile.local Makefile $(ALLDIRS) 349 @echo $(SUBHEAD) $(PLUGIN) "(plugin)" Generating $@ .. 350 @echo "/* Generated file. */" > $@ 351 @echo "const char *provider_version[] = {" >> $@ 352 @for ver in $(PROVIDER_AVAILABLE); do \ 353 sym=`echo $$ver | ./icu2symver.sh` ; \ 354 echo Version $$ver, Symbol $$sym ; \ 355 echo "\"$$sym\"", >> $@ ; \ 356 done 357 @echo " }; " >> $@ 358 @echo "#define PROVIDER_COUNT (sizeof(provider_version)/sizeof(provider_version[0]))" >> $@ 359 @echo >> $@ 360 @echo $(SUBHEAD) $(PLUGIN) "(plugin)" Generated $@ 361 362#-- for the prototype 363