"Fossies" - the Fresh Open Source Software Archive

Member "FreeBASIC-1.07.1-source/makefile" (27 Sep 2019, 39668 Bytes) of package /linux/privat/FreeBASIC-1.07.1-source.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Make source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "makefile": 1.07.0_vs_1.07.1.

    1 #!/usr/bin/make -f
    2 #
    3 # This is the FB makefile that builds the compiler (fbc) and the runtime
    4 # libraries (rtlib -> libfb[mt] and fbrt0.o, gfxlib2 -> libfbgfx[mt]). It will
    5 # also take care of moving the resulting binaries into the proper directory
    6 # layout, allowing the new FB setup to be tested right away, without being
    7 # installed elsewhere.
    8 #
    9 # Building the compiler requires a working FB installation, because it's written
   10 # in FB itself. rtlib/gfxlib2 are written in C and some ASM and have several
   11 # dependencies on external libraries depending on the target system.
   12 # (for example: ncurses/libtinfo, gpm, Linux headers, X11, OpenGL, DirectX)
   13 # More info: http://www.freebasic.net/wiki/wikka.php?wakka=DevBuild
   14 #
   15 # What will be built:
   16 #
   17 #   compiler:
   18 #     src/compiler/*.bas -> fbc[.exe]
   19 #
   20 #   rtlib:
   21 #     src/rtlib/static/fbrt0.c
   22 #     -> fbrt0.o
   23 #     -> fbrt0pic.o, -fPIC version (non-x86 Linux etc.)
   24 #
   25 #     all *.c and *.s files in
   26 #     src/rtlib/
   27 #     src/rtlib/$(TARGET_OS)
   28 #     src/rtlib/$(TARGET_ARCH)
   29 #     -> libfb.a
   30 #     -> libfbmt.a, -DENABLE_MT (threadsafe) version (except for DOS)
   31 #     -> libfbpic.a, -fPIC version (non-x86 Linux etc.)
   32 #     -> libfbmtpic.a, threadsafe and -fPIC (non-x86 Linux etc.)
   33 #
   34 #     contrib/djgpp/libc/...
   35 #     -> libc.a, fixed libc for DOS/DJGPP (see contrib/djgpp/ for more info)
   36 #
   37 #   gfxlib2:
   38 #     all *.c and *.s files in
   39 #     src/gfxlib2/
   40 #     src/gfxlib2/$(TARGET_OS)
   41 #     src/gfxlib2/$(TARGET_ARCH)
   42 #     -> libfbgfx.a
   43 #     -> libfbgfxmt.a, -DENABLE_MT (threadsafe) version (except for DOS)
   44 #     -> libfbgfxpic.a, -fPIC version (non-x86 Linux etc.)
   45 #     -> libfbgfxmtpic.a, threadsafe and -fPIC (non-x86 Linux etc.)
   46 #
   47 # commands:
   48 #
   49 #   <none>|all                 build everything
   50 #   compiler|rtlib|gfxlib2     build specific component only
   51 #   clean[-component]          remove built files
   52 #   install[-component]        install into $(prefix)
   53 #   uninstall[-component]      remove from $(prefix)
   54 #
   55 #   install-includes           (additional commands for just the FB includes,
   56 #   uninstall-includes          which don't need to be built)
   57 #
   58 #   gitdist    Create source code packages using "git archive"
   59 #   bindist    Create binary FB release packages from current build directory content
   60 #   mingw-libs Standalone: Copy libraries from MinGW toolchain into lib/win32/ etc.
   61 #
   62 #   unit-tests   (Convenience wrappers around tests/Makefile, running the tests
   63 #   log-tests     using the newly built fbc)
   64 #   warning-tests
   65 #   clean-tests
   66 #
   67 #   bootstrap-dist      Create source package with precompiled fbc sources
   68 #   bootstrap           Build fbc from the precompiled sources (only if precompiled sources exist)
   69 #   bootstrap-minimal   Build fbc from the precompiled sources (only if precompiled sources exist) with only the minimal features needed to compile another fbc
   70 #
   71 # makefile configuration:
   72 #   FB[C|L]FLAGS     to set -g -exx etc. for the compiler build and/or link
   73 #   CFLAGS           same for the rtlib and gfxlib2 build
   74 #   prefix           install/uninstall directory, default: /usr/local
   75 #   TARGET           GNU triplet for cross-compiling
   76 #   MULTILIB         "32", "64" or empty for cross-compiling using a gcc multilib toolchain
   77 #   FBC, CC, AR      fbc, gcc, ar programs (TARGET may be prefixed to CC/AR)
   78 #   V=1              to see full command lines
   79 #   ENABLE_STANDALONE=1    build source tree into self-contained FB installation
   80 #   ENABLE_PREFIX=1        use "-d ENABLE_PREFIX=$(prefix)" to hard-code the prefix into fbc
   81 #   ENABLE_SUFFIX=-0.24    append a string like "-0.24" to fbc/FB dir names,
   82 #                          and use "-d ENABLE_SUFFIX=$(ENABLE_SUFFIX)" (non-standalone only)
   83 #   ENABLE_LIB64=1         use prefix/lib64/ instead of prefix/lib/ for 64bit libs (non-standalone only)
   84 #   ENABLE_STRIPALL=1      use "-d ENABLE_STRIPALL" with all targets
   85 #   ENABLE_STRIPALL=0      disable "-d ENABLE_STRIPALL" with all targets
   86 #   FBSHA1=1               determine the sha-1 of the current commit in repo and store it in the compiler
   87 #   FBSHA1=some-sha-1      explicitly indicate the sha-1 to store in the compiler
   88 #   FBPACKAGE     bindist: The package/archive file name without path or extension
   89 #   FBPACKSUFFIX  bindist: Allows adding a custom suffix to the normal package name (and the toplevel dir in the archive)
   90 #   FBMANIFEST    bindist: The manifest file name without path or extension
   91 #   FBVERSION     bindist/gitdist: FB version number
   92 #   DISABLE_DOCS  bindist: Don't package readme/changelog/manpage/examples
   93 #
   94 # compiler source code configuration (FBCFLAGS):
   95 #   -d ENABLE_STANDALONE     build for a self-contained installation
   96 #   -d ENABLE_SUFFIX=-0.24   assume FB's lib dir uses the given suffix (non-standalone only)
   97 #   -d ENABLE_PREFIX=/some/path   hard-code specific $(prefix) into fbc
   98 #   -d ENABLE_LIB64          use prefix/lib64/ instead of prefix/lib/ for 64bit libs (non-standalone only)
   99 #   -d ENABLE_STRIPALL       configure fbc to pass down '--strip-all' to linker by default
  100 #   -d FBSHA1=some-sha-1     store 'some-sha-1' in the compiler for version information
  101 #
  102 # rtlib/gfxlib2 source code configuration (CFLAGS):
  103 #   -DDISABLE_X11    build without X11 headers (disables X11 gfx driver)
  104 #   -DDISABLE_GPM    build without gpm.h (disables Linux GetMouse)
  105 #   -DDISABLE_FFI    build without ffi.h (disables ThreadCall)
  106 #   -DDISABLE_OPENGL build without OpenGL headers (disables OpenGL gfx drivers)
  107 #   -DDISABLE_FBDEV  build without Linux framebuffer device headers (disables Linux fbdev gfx driver)
  108 #
  109 # makefile variables may either be set on the make command line,
  110 # or (in a more permanent way) inside a 'config.mk' file.
  111 #
  112 # The makefile searches the sources based on its location, but builds into
  113 # the current directory. It's possible to build in a separate directory by
  114 # running the makefile via "make -f ../path/to/fbc/makefile" from the desired
  115 # build directory.
  116 #
  117 # The makefile supports only one compiler build per build directory, but
  118 # possibly multiple rtlib/gfxlib2 builds, each for a different target.
  119 # This matches how FB works: one fbc per host, plus one rtlib/gfxlib2 per
  120 # target. For example:
  121 #    1) Build host FB setup
  122 #        $ make
  123 #    2) Add rtlib/gfxlib2 for some additional target
  124 #        $ make rtlib gfxlib2 TARGET=i686-w64-mingw32
  125 #
  126 
  127 FBC := fbc
  128 CFLAGS := -Wfatal-errors -O2
  129 # Avoid gcc exception handling bloat
  130 CFLAGS += -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables
  131 FBFLAGS := -maxerr 1
  132 AS = $(TARGET_PREFIX)as
  133 AR = $(TARGET_PREFIX)ar
  134 CC = $(TARGET_PREFIX)gcc
  135 prefix := /usr/local
  136 
  137 # Determine the makefile's directory, this may be a relative path when
  138 # building in a separate build directory via e.g. "make -f ../fbc/makefile".
  139 # MAKEFILE_LIST did not exist in GNU make 3.79.1 (it was only added in 3.80),
  140 # so DJGPP users have to set MAKEFILE_LIST or rootdir manually in order to build
  141 # in a separate directory.
  142 rootdir := $(dir $(MAKEFILE_LIST))
  143 
  144 # Prune ./ prefix for beauty
  145 ifeq ($(rootdir),./)
  146   rootdir :=
  147 endif
  148 
  149 srcdir := $(rootdir)src
  150 
  151 include $(rootdir)version.mk
  152 -include config.mk
  153 
  154 #
  155 # We need to know target OS/architecture names to select the proper
  156 # rtlib/gfxlib2 source directories.
  157 #
  158 # If TARGET is given, we try to parse it to determine TARGET_OS/TARGET_ARCH.
  159 # Otherwise we rely on "uname" and "uname -m".
  160 #
  161 ifdef TARGET
  162   # Parse TARGET
  163   triplet := $(subst -, ,$(TARGET))
  164   TARGET_PREFIX := $(TARGET)-
  165 
  166   ifndef TARGET_OS
  167     ifneq ($(filter cygwin%,$(triplet)),)
  168       TARGET_OS := cygwin
  169     else ifneq ($(filter darwin%,$(triplet)),)
  170       TARGET_OS := darwin
  171     else ifneq ($(filter djgpp%,$(triplet)),)
  172       TARGET_OS := dos
  173     else ifneq ($(filter msdos%,$(triplet)),)
  174       TARGET_OS := dos
  175     else ifneq ($(filter freebsd%,$(triplet)),)
  176       TARGET_OS := freebsd
  177     else ifneq ($(filter linux%,$(triplet)),)
  178       TARGET_OS := linux
  179     else ifneq ($(filter mingw%,$(triplet)),)
  180       TARGET_OS := win32
  181     else ifneq ($(filter netbsd%,$(triplet)),)
  182       TARGET_OS := netbsd
  183     else ifneq ($(filter openbsd%,$(triplet)),)
  184       TARGET_OS := openbsd
  185     else ifneq ($(filter solaris%,$(triplet)),)
  186       TARGET_OS := solaris
  187     else ifneq ($(filter xbox%,$(triplet)),)
  188       TARGET_OS := xbox
  189     endif
  190   endif
  191 
  192   ifndef TARGET_ARCH
  193     # arch = iif(has >= 2 words, first word, empty)
  194     # 'i686 pc linux gnu' -> 'i686'
  195     # 'mingw32'           -> ''
  196     TARGET_ARCH := $(if $(word 2,$(triplet)),$(firstword $(triplet)))
  197   endif
  198 else
  199   # No TARGET given, so try to detect the native system with 'uname'
  200   ifndef TARGET_OS
  201     uname := $(shell uname)
  202     ifneq ($(findstring CYGWIN,$(uname)),)
  203       TARGET_OS := cygwin
  204     else ifeq ($(uname),Darwin)
  205       TARGET_OS := darwin
  206     else ifeq ($(uname),FreeBSD)
  207       TARGET_OS := freebsd
  208     else ifeq ($(uname),Linux)
  209       TARGET_OS := linux
  210     else ifneq ($(findstring MINGW,$(uname)),)
  211       TARGET_OS := win32
  212     else ifneq ($(findstring MSYS_NT,$(uname)),)
  213       TARGET_OS := win32
  214     else ifeq ($(uname),MS-DOS)
  215       TARGET_OS := dos
  216     else ifeq ($(uname),NetBSD)
  217       TARGET_OS := netbsd
  218     else ifeq ($(uname),OpenBSD)
  219       TARGET_OS := openbsd
  220     else ifeq ($(uname),SunOS)
  221       TARGET_OS := solaris
  222     endif
  223   endif
  224 
  225   ifndef TARGET_ARCH
  226     # For DJGPP, always use x86 (DJGPP's uname -m returns just "pc")
  227     ifeq ($(TARGET_OS),dos)
  228       TARGET_ARCH := x86
  229 
  230     # For MSYS2, use default compilers (uname -m returns MSYS2's shell
  231     #  architecture).  For example, from win 7:
  232     #
  233     # host    shell    uname -s -m              default gcc target
  234     # ------  -------  --------------------     ------------------
  235     # msys32  msys2    MSYS_NT-6.1-WOW i686     n/a
  236     # msys32  mingw32  MINGW32_NT-6.1-WOW i686  i686-w64-mingw32
  237     # msys32  mingw64  MINGW64_NT-6.1-WOW i686  x86_64-w64-mingw32
  238     # msys64  msys2    MSYS_NT-6.1 x86_64       n/a
  239     # msys64  mingw32  MINGW32_NT-6.1 x86_64    i686-w64-mingw32
  240     # msys64  mingw64  MINGW64_NT-6.1 x86_64    x86_64-w64-mingw32
  241     #
  242     else ifneq ($(findstring MINGW32,$(uname)),)
  243       TARGET_ARCH := x86
  244     else ifneq ($(findstring MINGW64,$(uname)),)
  245       TARGET_ARCH := x86_64
  246 
  247     # anything, trust 'uname -m', we have no other choice
  248     else
  249       TARGET_ARCH = $(shell uname -m)
  250     endif
  251   endif
  252 endif
  253 
  254 ifndef TARGET_OS
  255   $(error couldn't identify TARGET_OS automatically)
  256 endif
  257 ifndef TARGET_ARCH
  258   $(error couldn't identify TARGET_ARCH automatically)
  259 endif
  260 
  261 # Normalize TARGET_ARCH to x86
  262 ifneq ($(filter 386 486 586 686 i386 i486 i586 i686,$(TARGET_ARCH)),)
  263   TARGET_ARCH := x86
  264 endif
  265 
  266 # Normalize TARGET_ARCH to arm
  267 ifneq ($(filter arm%,$(TARGET_ARCH)),)
  268   TARGET_ARCH := arm
  269 endif
  270 
  271 # Normalize TARGET_ARCH to x86_64 (e.g., FreeBSD's uname -m returns "amd64"
  272 # instead of "x86_64" like Linux)
  273 ifneq ($(filter amd64 x86-64,$(TARGET_ARCH)),)
  274   TARGET_ARCH := x86_64
  275 endif
  276 
  277 # Switch TARGET_ARCH depending on MULTILIB
  278 ifeq ($(MULTILIB),32)
  279   ifeq ($(TARGET_ARCH),x86_64)
  280     TARGET_ARCH := x86
  281   endif
  282 else ifeq ($(MULTILIB),64)
  283   ifeq ($(TARGET_ARCH),x86)
  284     TARGET_ARCH := x86_64
  285   endif
  286 endif
  287 
  288 ifeq ($(TARGET_OS),dos)
  289   FBNAME := freebas$(ENABLE_SUFFIX)
  290   FB_LDSCRIPT := i386go32.x
  291 else
  292   FBNAME := freebasic$(ENABLE_SUFFIX)
  293   FB_LDSCRIPT := fbextra.x
  294 endif
  295 
  296 # ENABLE_PIC for non-x86 Linux etc. (for every system where we need separate
  297 # -fPIC versions of FB libs besides the normal ones)
  298 ifneq ($(filter freebsd linux netbsd openbsd solaris,$(TARGET_OS)),)
  299   ifneq ($(TARGET_ARCH),x86)
  300     ENABLE_PIC := YesPlease
  301   endif
  302 endif
  303 
  304 ifneq ($(filter cygwin dos win32,$(TARGET_OS)),)
  305   EXEEXT := .exe
  306   INSTALL_PROGRAM := cp
  307   INSTALL_FILE := cp
  308 else
  309   INSTALL_PROGRAM := install
  310   INSTALL_FILE := install -m 644
  311 endif
  312 
  313 #
  314 # Determine FB target name:
  315 # dos, win32, win64, xbox, linux-x86, linux-x86_64, ...
  316 #
  317 
  318 # Some use a simple free-form name
  319 ifeq ($(TARGET_OS),dos)
  320   FBTARGET := dos
  321 else ifeq ($(TARGET_OS),xbox)
  322   FBTARGET := xbox
  323 else ifeq ($(TARGET_OS),win32)
  324   ifeq ($(TARGET_ARCH),x86_64)
  325     FBTARGET := win64
  326   else
  327     FBTARGET := win32
  328   endif
  329 endif
  330 
  331 # The rest uses the <os>-<cpufamily> format
  332 ifndef FBTARGET
  333   FBTARGET := $(TARGET_OS)-$(TARGET_ARCH)
  334 endif
  335 
  336 #
  337 # Determine directory layout for .o files and final binaries.
  338 #
  339 libsubdir := $(FBTARGET)
  340 ifdef ENABLE_STANDALONE
  341   # Traditional standalone layout: fbc.exe at toplevel, libs in lib/<fbtarget>/,
  342   # includes in inc/
  343   FBC_EXE     := fbc$(EXEEXT)
  344   FBCNEW_EXE  := fbc-new$(EXEEXT)
  345   libdir         := lib/$(libsubdir)
  346   PREFIX_FBC_EXE := $(prefix)/fbc$(EXEEXT)
  347   prefixbindir   := $(prefix)
  348   prefixincdir   := $(prefix)/inc
  349   prefixlibdir   := $(prefix)/$(libdir)
  350 else
  351   # With ENABLE_LIB64, put 64bit libs into
  352   #    lib64/freebasic/<fbtarget>/
  353   # instead of the default
  354   #    lib/freebasic/<fbtarget>/
  355   libdirname := lib
  356   ifdef ENABLE_LIB64
  357     ifneq ($(filter x86_64 aarch64,$(TARGET_ARCH)),)
  358       libdirname := lib64
  359     endif
  360   endif
  361 
  362   # Normal (non-standalone) setup: bin/fbc, include/freebasic/, lib[64]/freebasic/<fbtarget>/.
  363   FBC_EXE     := bin/fbc$(ENABLE_SUFFIX)$(EXEEXT)
  364   FBCNEW_EXE  := bin/fbc$(ENABLE_SUFFIX)-new$(EXEEXT)
  365   libdir         := $(libdirname)/$(FBNAME)/$(libsubdir)
  366   PREFIX_FBC_EXE := $(prefix)/bin/fbc$(ENABLE_SUFFIX)$(EXEEXT)
  367   prefixbindir   := $(prefix)/bin
  368   prefixincdir   := $(prefix)/include/$(FBNAME)
  369   prefixlibdir   := $(prefix)/$(libdir)
  370 endif
  371 fbcobjdir           := src/compiler/obj/$(FBTARGET)
  372 libfbobjdir         := src/rtlib/obj/$(libsubdir)
  373 libfbpicobjdir      := src/rtlib/obj/$(libsubdir)/pic
  374 libfbmtobjdir       := src/rtlib/obj/$(libsubdir)/mt
  375 libfbmtpicobjdir    := src/rtlib/obj/$(libsubdir)/mt/pic
  376 libfbgfxobjdir      := src/gfxlib2/obj/$(libsubdir)
  377 libfbgfxpicobjdir   := src/gfxlib2/obj/$(libsubdir)/pic
  378 libfbgfxmtobjdir    := src/gfxlib2/obj/$(libsubdir)/mt
  379 libfbgfxmtpicobjdir := src/gfxlib2/obj/$(libsubdir)/mt/pic
  380 djgpplibcobjdir     := contrib/djgpp/libc/crt0/obj/$(libsubdir)
  381 
  382 # If cross-compiling, use -target
  383 ifdef TARGET
  384   ALLFBCFLAGS += -target $(TARGET)
  385   ALLFBLFLAGS += -target $(TARGET)
  386 endif
  387 ifdef MULTILIB
  388   ALLFBCFLAGS += -arch $(MULTILIB)
  389   ALLFBLFLAGS += -arch $(MULTILIB)
  390   ALLCFLAGS   += -m$(MULTILIB)
  391 endif
  392 
  393 ALLFBCFLAGS += -e -m fbc -w pedantic
  394 ALLFBLFLAGS += -e -m fbc -w pedantic
  395 ALLCFLAGS += -Wall -Wextra -Wno-unused-parameter -Werror-implicit-function-declaration
  396 
  397 ifneq ($(filter bootstrap-minimal, $(MAKECMDGOALS)),)
  398   # Disable features not needed to compile a minimal bootstrap fbc
  399   ALLCFLAGS += -DDISABLE_GPM -DDISABLE_FFI -DDISABLE_X11
  400 endif
  401 
  402 ifeq ($(TARGET_OS),xbox)
  403   ifeq ($(OPENXDK),)
  404     $(error Please set OPENXDK=<OpenXDK directory>)
  405   endif
  406 
  407   MINGWGCCLIBDIR := $(dir $(shell $(CC) -print-file-name=libgcc.a))
  408 
  409   ALLCFLAGS += -ffreestanding -nostdinc -fno-exceptions -march=i386 \
  410     -I$(OPENXDK)/i386-pc-xbox/include \
  411     -I$(OPENXDK)/include \
  412     -I$(MINGWGCCLIBDIR)/include
  413 
  414   # src/rtlib/fb_config.h cannot auto-detect this
  415   ALLCFLAGS += -DHOST_XBOX
  416 
  417   # Assume no libffi for now (does it work on Xbox?)
  418   ALLCFLAGS += -DDISABLE_FFI
  419 
  420   # -DENABLE_MT parts of rtlib XBox code aren't finished
  421   DISABLE_MT := YesPlease
  422 endif
  423 
  424 ifeq ($(TARGET_OS),netbsd)
  425   ALLCFLAGS += -I/usr/X11R7/include \
  426     -I/usr/pkg/include
  427 endif
  428 
  429 ifeq ($(TARGET_OS),darwin)
  430   ALLCFLAGS += -I/opt/X11/include -I/usr/include/ffi
  431   
  432   ifdef ENABLE_XQUARTZ
  433     ALLFBCFLAGS += -d ENABLE_XQUARTZ
  434   else
  435     ALLCFLAGS += -DDISABLE_X11
  436   endif
  437 endif
  438 
  439 ifneq ($(filter cygwin win32,$(TARGET_OS)),)
  440   # Increase compiler's available stack size, it uses lots of recursion
  441   ALLFBLFLAGS += -t 2048
  442 endif
  443 
  444 # Pass the configuration defines on to the compiler source code
  445 ifdef ENABLE_STANDALONE
  446   ALLFBCFLAGS += -d ENABLE_STANDALONE
  447 endif
  448 ifdef FBSHA1
  449   ifeq ($(FBSHA1),1)
  450     ALLFBCFLAGS += -d 'FBSHA1="$(shell git rev-parse HEAD)"'
  451   else
  452     ALLFBCFLAGS += -d 'FBSHA1="$(FBSHA1)"'
  453   endif
  454 endif
  455 ifdef ENABLE_SUFFIX
  456   ALLFBCFLAGS += -d 'ENABLE_SUFFIX="$(ENABLE_SUFFIX)"'
  457 endif
  458 ifdef ENABLE_PREFIX
  459   ALLFBCFLAGS += -d 'ENABLE_PREFIX="$(prefix)"'
  460 endif
  461 ifdef ENABLE_LIB64
  462   ALLFBCFLAGS += -d ENABLE_LIB64
  463 endif
  464 ifdef ENABLE_STRIPALL
  465   ifneq ($(ENABLE_STRIPALL),0)
  466     ALLFBCFLAGS += -d ENABLE_STRIPALL
  467   endif
  468 else
  469   # by default dos and windows use --strip-all
  470   ifneq ($(filter dos win32,$(TARGET_OS)),)
  471     ALLFBCFLAGS += -d ENABLE_STRIPALL
  472   endif
  473 endif
  474 
  475 
  476 ALLFBCFLAGS += $(FBCFLAGS) $(FBFLAGS)
  477 ALLFBLFLAGS += $(FBLFLAGS) $(FBFLAGS)
  478 ALLCFLAGS += $(CFLAGS)
  479 
  480 # compiler headers and modules
  481 FBC_BI  :=        $(wildcard $(srcdir)/compiler/*.bi)
  482 FBC_BAS := $(sort $(wildcard $(srcdir)/compiler/*.bas))
  483 FBC_BAS := $(patsubst $(srcdir)/compiler/%.bas,$(fbcobjdir)/%.o,$(FBC_BAS))
  484 
  485 # rtlib/gfxlib2 headers and modules
  486 RTLIB_DIRS := $(srcdir)/rtlib $(srcdir)/rtlib/$(TARGET_OS) $(srcdir)/rtlib/$(TARGET_ARCH)
  487 ifeq ($(TARGET_OS),cygwin)
  488   RTLIB_DIRS += $(srcdir)/rtlib/win32
  489 endif
  490 ifneq ($(filter darwin freebsd linux netbsd openbsd solaris,$(TARGET_OS)),)
  491   RTLIB_DIRS += $(srcdir)/rtlib/unix
  492 endif
  493 GFXLIB2_DIRS := $(patsubst $(srcdir)/rtlib%,$(srcdir)/gfxlib2%,$(RTLIB_DIRS))
  494 
  495 LIBFB_H := $(sort $(foreach i,$(RTLIB_DIRS),$(wildcard $(i)/*.h)))
  496 LIBFB_C := $(sort $(foreach i,$(RTLIB_DIRS),$(patsubst $(i)/%.c,$(libfbobjdir)/%.o,$(wildcard $(i)/*.c))))
  497 LIBFB_S := $(sort $(foreach i,$(RTLIB_DIRS),$(patsubst $(i)/%.s,$(libfbobjdir)/%.o,$(wildcard $(i)/*.s))))
  498 LIBFBPIC_C   := $(patsubst $(libfbobjdir)/%,$(libfbpicobjdir)/%,$(LIBFB_C))
  499 LIBFBMT_C    := $(patsubst $(libfbobjdir)/%,$(libfbmtobjdir)/%,$(LIBFB_C))
  500 LIBFBMT_S    := $(patsubst $(libfbobjdir)/%,$(libfbmtobjdir)/%,$(LIBFB_S))
  501 LIBFBMTPIC_C := $(patsubst $(libfbobjdir)/%,$(libfbmtpicobjdir)/%,$(LIBFB_C))
  502 
  503 LIBFBGFX_H := $(sort $(foreach i,$(GFXLIB2_DIRS),$(wildcard $(i)/*.h)) $(LIBFB_H))
  504 LIBFBGFX_C := $(sort $(foreach i,$(GFXLIB2_DIRS),$(patsubst $(i)/%.c,$(libfbgfxobjdir)/%.o,$(wildcard $(i)/*.c))))
  505 LIBFBGFX_S := $(sort $(foreach i,$(GFXLIB2_DIRS),$(patsubst $(i)/%.s,$(libfbgfxobjdir)/%.o,$(wildcard $(i)/*.s))))
  506 LIBFBGFXPIC_C   := $(patsubst $(libfbgfxobjdir)/%,$(libfbgfxpicobjdir)/%,$(LIBFBGFX_C))
  507 LIBFBGFXMT_C    := $(patsubst $(libfbgfxobjdir)/%,$(libfbgfxmtobjdir)/%,$(LIBFBGFX_C))
  508 LIBFBGFXMT_S    := $(patsubst $(libfbgfxobjdir)/%,$(libfbgfxmtobjdir)/%,$(LIBFBGFX_S))
  509 LIBFBGFXMTPIC_C := $(patsubst $(libfbgfxobjdir)/%,$(libfbgfxmtpicobjdir)/%,$(LIBFBGFX_C))
  510 
  511 RTL_LIBS := $(libdir)/$(FB_LDSCRIPT) $(libdir)/fbrt0.o $(libdir)/libfb.a
  512 GFX_LIBS := $(libdir)/libfbgfx.a
  513 ifdef ENABLE_PIC
  514   RTL_LIBS += $(libdir)/fbrt0pic.o $(libdir)/libfbpic.a
  515   GFX_LIBS += $(libdir)/libfbgfxpic.a
  516 endif
  517 ifndef DISABLE_MT
  518   RTL_LIBS += $(libdir)/libfbmt.a
  519   GFX_LIBS += $(libdir)/libfbgfxmt.a
  520   ifdef ENABLE_PIC
  521     RTL_LIBS += $(libdir)/libfbmtpic.a
  522     GFX_LIBS += $(libdir)/libfbgfxmtpic.a
  523   endif
  524 endif
  525 ifeq ($(TARGET_OS),dos)
  526   RTL_LIBS += $(libdir)/libc.a
  527 endif
  528 
  529 #
  530 # Build rules
  531 #
  532 
  533 VPATH = $(RTLIB_DIRS) $(GFXLIB2_DIRS)
  534 
  535 # We don't want to use any of make's built-in suffixes/rules
  536 .SUFFIXES:
  537 
  538 ifndef V
  539   QUIET_FBC   = @echo "FBC $@";
  540   QUIET_LINK  = @echo "LINK $@";
  541   QUIET_CC    = @echo "CC $@";
  542   QUIET_CPPAS = @echo "CPPAS $@";
  543   QUIET_AS    = @echo "AS $@";
  544   QUIET_AR    = @echo "AR $@";
  545   QUIET       = @
  546 endif
  547 
  548 ################################################################################
  549 
  550 .PHONY: all
  551 all: compiler rtlib gfxlib2
  552 
  553 $(fbcobjdir) \
  554 $(libfbobjdir) \
  555 $(libfbpicobjdir) \
  556 $(libfbmtobjdir) \
  557 $(libfbmtpicobjdir) \
  558 $(libfbgfxobjdir) \
  559 $(libfbgfxpicobjdir) \
  560 $(libfbgfxmtobjdir) \
  561 $(libfbgfxmtpicobjdir) \
  562 $(djgpplibcobjdir) \
  563 bin $(libdir):
  564     mkdir -p $@
  565 
  566 ################################################################################
  567 
  568 .PHONY: compiler
  569 compiler: $(FBC_EXE)
  570 
  571 $(FBC_EXE): $(FBC_BAS) | bin
  572     $(QUIET_LINK)$(FBC) $(ALLFBLFLAGS) -x $(FBCNEW_EXE) $^
  573     $(QUIET)mv $(FBCNEW_EXE) $@
  574 
  575 $(FBC_BAS): $(fbcobjdir)/%.o: $(srcdir)/compiler/%.bas $(FBC_BI) | $(fbcobjdir)
  576     $(QUIET_FBC)$(FBC) $(ALLFBCFLAGS) -c $< -o $@
  577 
  578 ################################################################################
  579 
  580 .PHONY: rtlib
  581 rtlib: $(RTL_LIBS)
  582 
  583 $(libdir)/fbextra.x: $(rootdir)lib/fbextra.x | $(libdir)
  584     cp $< $@
  585 
  586 $(libdir)/i386go32.x: $(rootdir)contrib/djgpp/i386go32.x | $(libdir)
  587     cp $< $@
  588 
  589 $(libdir)/fbrt0.o: $(srcdir)/rtlib/static/fbrt0.c $(LIBFB_H) | $(libdir)
  590     $(QUIET_CC)$(CC) $(ALLCFLAGS) -c $< -o $@
  591 
  592 $(libdir)/fbrt0pic.o: $(srcdir)/rtlib/static/fbrt0.c $(LIBFB_H) | $(libdir)
  593     $(QUIET_CC)$(CC) -fPIC $(ALLCFLAGS) -c $< -o $@
  594 
  595 $(libdir)/libfb.a: $(LIBFB_C) $(LIBFB_S) | $(libdir)
  596 ifeq ($(TARGET_OS),dos)
  597   # Avoid hitting the command line length limit (the libfb.a ar command line
  598   # is very long...)
  599     $(QUIET)rm -f $@
  600     $(QUIET_AR)$(AR) rcs $@ $(libfbobjdir)/*.o
  601 else ifneq ($(findstring MSYS_NT,$(shell uname)),)
  602     $(QUIET)rm -f $@
  603     $(QUIET_AR)$(AR) rcs $@ $(libfbobjdir)/*.o
  604 else
  605     $(QUIET_AR)rm -f $@; $(AR) rcs $@ $^
  606 endif
  607 $(LIBFB_C): $(libfbobjdir)/%.o: %.c $(LIBFB_H) | $(libfbobjdir)
  608     $(QUIET_CC)$(CC) $(ALLCFLAGS) -c $< -o $@
  609 $(LIBFB_S): $(libfbobjdir)/%.o: %.s $(LIBFB_H) | $(libfbobjdir)
  610     $(QUIET_CPPAS)$(CC) -x assembler-with-cpp $(ALLCFLAGS) -c $< -o $@
  611 
  612 $(libdir)/libfbpic.a: $(LIBFBPIC_C) | $(libdir)
  613     $(QUIET_AR)rm -f $@; $(AR) rcs $@ $^
  614 $(LIBFBPIC_C): $(libfbpicobjdir)/%.o: %.c $(LIBFB_H) | $(libfbpicobjdir)
  615     $(QUIET_CC)$(CC) -fPIC $(ALLCFLAGS) -c $< -o $@
  616 
  617 $(libdir)/libfbmt.a: $(LIBFBMT_C) $(LIBFBMT_S) | $(libdir)
  618 ifeq ($(TARGET_OS),dos)
  619   # Avoid hitting the command line length limit (the libfb.a ar command line
  620   # is very long...)
  621     $(QUIET)rm -f $@
  622     $(QUIET_AR)$(AR) rcs $@ $(libfbmtobjdir)/*.o
  623 else ifneq ($(findstring MSYS_NT,$(shell uname)),)
  624     $(QUIET)rm -f $@
  625     $(QUIET_AR)$(AR) rcs $@ $(libfbmtobjdir)/*.o
  626 else
  627     $(QUIET_AR)rm -f $@; $(AR) rcs $@ $^
  628 endif
  629 $(LIBFBMT_C): $(libfbmtobjdir)/%.o: %.c $(LIBFB_H) | $(libfbmtobjdir)
  630     $(QUIET_CC)$(CC) -DENABLE_MT $(ALLCFLAGS) -c $< -o $@
  631 $(LIBFBMT_S): $(libfbmtobjdir)/%.o: %.s $(LIBFB_H) | $(libfbmtobjdir)
  632     $(QUIET_CPPAS)$(CC) -x assembler-with-cpp -DENABLE_MT $(ALLCFLAGS) -c $< -o $@
  633 
  634 $(libdir)/libfbmtpic.a: $(LIBFBMTPIC_C) | $(libdir)
  635     $(QUIET_AR)rm -f $@; $(AR) rcs $@ $^
  636 $(LIBFBMTPIC_C): $(libfbmtpicobjdir)/%.o: %.c $(LIBFB_H) | $(libfbmtpicobjdir)
  637     $(QUIET_CC)$(CC) -DENABLE_MT -fPIC $(ALLCFLAGS) -c $< -o $@
  638 
  639 ifeq ($(TARGET_OS),dos)
  640 djgpplibc := $(shell $(CC) -print-file-name=libc.a)
  641 libcmaino := $(djgpplibcobjdir)/_main.o
  642 $(libcmaino): $(rootdir)contrib/djgpp/libc/crt0/_main.c | $(djgpplibcobjdir)
  643     $(QUIET_CC)$(CC) $(ALLCFLAGS) -c $< -o $@
  644 $(libdir)/libc.a: $(djgpplibc) $(libcmaino) | $(libdir)
  645     cp $(djgpplibc) $@
  646     $(QUIET_AR)ar rs $@ $(libcmaino)
  647 endif
  648 
  649 ################################################################################
  650 
  651 .PHONY: gfxlib2
  652 gfxlib2: $(GFX_LIBS)
  653 
  654 $(libdir)/libfbgfx.a: $(LIBFBGFX_C) $(LIBFBGFX_S) | $(libdir)
  655     $(QUIET_AR)rm -f $@; $(AR) rcs $@ $^
  656 $(LIBFBGFX_C): $(libfbgfxobjdir)/%.o: %.c $(LIBFBGFX_H) | $(libfbgfxobjdir)
  657     $(QUIET_CC)$(CC) $(ALLCFLAGS) -c $< -o $@
  658 $(LIBFBGFX_S): $(libfbgfxobjdir)/%.o: %.s $(LIBFBGFX_H) | $(libfbgfxobjdir)
  659     $(QUIET_CPPAS)$(CC) -x assembler-with-cpp $(ALLCFLAGS) -c $< -o $@
  660 
  661 $(libdir)/libfbgfxpic.a: $(LIBFBGFXPIC_C) | $(libdir)
  662     $(QUIET_AR)rm -f $@; $(AR) rcs $@ $^
  663 $(LIBFBGFXPIC_C): $(libfbgfxpicobjdir)/%.o: %.c $(LIBFBGFX_H) | $(libfbgfxpicobjdir)
  664     $(QUIET_CC)$(CC) -fPIC $(ALLCFLAGS) -c $< -o $@
  665 
  666 $(libdir)/libfbgfxmt.a: $(LIBFBGFXMT_C) $(LIBFBGFXMT_S) | $(libdir)
  667     $(QUIET_AR)rm -f $@; $(AR) rcs $@ $^
  668 $(LIBFBGFXMT_C): $(libfbgfxmtobjdir)/%.o: %.c $(LIBFBGFX_H) | $(libfbgfxmtobjdir)
  669     $(QUIET_CC)$(CC) -DENABLE_MT $(ALLCFLAGS) -c $< -o $@
  670 $(LIBFBGFXMT_S): $(libfbgfxmtobjdir)/%.o: %.s $(LIBFBGFX_H) | $(libfbgfxmtobjdir)
  671     $(QUIET_CPPAS)$(CC) -x assembler-with-cpp -DENABLE_MT $(ALLCFLAGS) -c $< -o $@
  672 
  673 $(libdir)/libfbgfxmtpic.a: $(LIBFBGFXMTPIC_C) | $(libdir)
  674     $(QUIET_AR)rm -f $@; $(AR) rcs $@ $^
  675 $(LIBFBGFXMTPIC_C): $(libfbgfxmtpicobjdir)/%.o: %.c $(LIBFBGFX_H) | $(libfbgfxmtpicobjdir)
  676     $(QUIET_CC)$(CC) -DENABLE_MT -fPIC $(ALLCFLAGS) -c $< -o $@
  677 
  678 ################################################################################
  679 
  680 .PHONY: install install-compiler install-includes install-rtlib install-gfxlib2
  681 install:        install-compiler install-includes install-rtlib install-gfxlib2
  682 
  683 install-compiler: compiler
  684     mkdir -p $(DESTDIR)$(prefixbindir)
  685     $(INSTALL_PROGRAM) $(FBC_EXE) $(DESTDIR)$(PREFIX_FBC_EXE)
  686 
  687 install-includes:
  688     mkdir -p $(DESTDIR)$(prefixincdir)
  689     cp -r $(rootdir)inc/* $(DESTDIR)$(prefixincdir)
  690 
  691 install-rtlib: rtlib
  692     mkdir -p $(DESTDIR)$(prefixlibdir)
  693     $(INSTALL_FILE) $(RTL_LIBS) $(DESTDIR)$(prefixlibdir)
  694 
  695 install-gfxlib2: gfxlib2
  696     mkdir -p $(DESTDIR)$(prefixlibdir)
  697     $(INSTALL_FILE) $(GFX_LIBS) $(DESTDIR)$(prefixlibdir)
  698 
  699 ################################################################################
  700 
  701 .PHONY: uninstall uninstall-compiler uninstall-includes uninstall-rtlib uninstall-gfxlib2
  702 uninstall:        uninstall-compiler uninstall-includes uninstall-rtlib uninstall-gfxlib2
  703     -rmdir $(DESTDIR)$(prefixlibdir)
  704 
  705 uninstall-compiler:
  706     rm -f $(DESTDIR)$(PREFIX_FBC_EXE)
  707 
  708 uninstall-includes:
  709     rm -rf $(DESTDIR)$(prefixincdir)
  710 
  711 uninstall-rtlib:
  712     rm -f $(patsubst $(libdir)/%,$(DESTDIR)$(prefixlibdir)/%,$(RTL_LIBS))
  713 
  714 uninstall-gfxlib2:
  715     rm -f $(patsubst $(libdir)/%,$(DESTDIR)$(prefixlibdir)/%,$(GFX_LIBS))
  716 
  717 ################################################################################
  718 
  719 .PHONY: clean clean-compiler clean-rtlib clean-gfxlib2
  720 clean:        clean-compiler clean-rtlib clean-gfxlib2
  721 
  722 clean-compiler:
  723     rm -rf $(FBC_EXE) $(fbcobjdir)
  724   ifndef ENABLE_STANDALONE
  725     -rmdir bin
  726   endif
  727 
  728 clean-rtlib:
  729     rm -rf $(RTL_LIBS) $(libfbobjdir)
  730   ifeq ($(TARGET_OS),dos)
  731     rm -rf $(djgpplibcobjdir)
  732   endif
  733 
  734 clean-gfxlib2:
  735     rm -rf $(GFX_LIBS) $(libfbgfxobjdir)
  736 
  737 ################################################################################
  738 
  739 .PHONY: help
  740 help:
  741     @echo "Take a look at the top of this makefile!"
  742 
  743 ################################################################################
  744 
  745 .PHONY: unit-tests log-tests clean-tests
  746 
  747 unit-tests:
  748     cd tests && make unit-tests FBC="`pwd`/../$(FBC_EXE) -i `pwd`/../inc"
  749 
  750 log-tests:
  751     cd tests && make   log-tests FBC="`pwd`/../$(FBC_EXE) -i `pwd`/../inc"
  752 
  753 warning-tests:
  754     cd tests/warnings && FBC="`pwd`/../../$(FBC_EXE)" ./test.sh
  755 
  756 clean-tests:
  757     cd tests && make clean
  758 
  759 
  760 ################################################################################
  761 
  762 FBSOURCETITLE = FreeBASIC-$(FBVERSION)-source
  763 
  764 .PHONY: gitdist
  765 gitdist:
  766     # (using git archive --prefix ... to avoid tarbombs)
  767     # .tar.gz and .tar.xz, with LF line endings
  768     git -c core.autocrlf=false archive --format tar --prefix "$(FBSOURCETITLE)/" HEAD | tar xf -
  769     tar -czf "$(FBSOURCETITLE).tar.gz" "$(FBSOURCETITLE)"
  770     tar -cJf "$(FBSOURCETITLE).tar.xz" "$(FBSOURCETITLE)"
  771     rm -rf "$(FBSOURCETITLE)"
  772 
  773     # .zip with low word size/fast bytes setting (for DOS), and .7z, with CRLF line endings
  774     git -c core.autocrlf=true archive --format tar --prefix "$(FBSOURCETITLE)/" HEAD | tar xf -
  775     zip -q -r "$(FBSOURCETITLE).zip" "$(FBSOURCETITLE)"
  776     7z a      "$(FBSOURCETITLE).7z"  "$(FBSOURCETITLE)" > /dev/null
  777     rm -rf "$(FBSOURCETITLE)"
  778 
  779 #
  780 # Traditionally, the FB release package names depend on whether its a normal or
  781 # standalone build and on the platform. The "FreeBASIC-x.xx.x-target" name
  782 # format is traditionally used for the "default" builds for the respective
  783 # platform.
  784 #
  785 # Linux/BSD standalone = FreeBASIC-x.xx.x-target-standalone
  786 # Linux/BSD normal     = FreeBASIC-x.xx.x-target
  787 # Windows/DOS standalone = FreeBASIC-x.xx.x-target
  788 # Windows/DOS normal     = fbc-x.xx.x-target (MinGW/DJGPP-style packages)
  789 #
  790 ifndef FBPACKAGE
  791   ifneq ($(filter darwin freebsd linux netbsd openbsd solaris,$(TARGET_OS)),)
  792     ifdef ENABLE_STANDALONE
  793       FBPACKAGE := FreeBASIC-$(FBVERSION)-$(FBTARGET)-standalone
  794     else
  795       FBPACKAGE := FreeBASIC-$(FBVERSION)-$(FBTARGET)
  796     endif
  797   else
  798     ifdef ENABLE_STANDALONE
  799       FBPACKAGE := FreeBASIC-$(FBVERSION)-$(FBTARGET)
  800     else
  801       FBPACKAGE := fbc-$(FBVERSION)-$(FBTARGET)
  802     endif
  803   endif
  804 endif
  805 
  806 FBPACKAGE := $(FBPACKAGE)$(FBPACKSUFFIX)
  807 
  808 ifndef FBMANIFEST
  809   FBMANIFEST := $(subst -$(FBVERSION),,$(FBPACKAGE))
  810 endif
  811 
  812 packbin := $(patsubst $(prefix)%,$(FBPACKAGE)%,$(prefixbindir))
  813 packinc := $(patsubst $(prefix)%,$(FBPACKAGE)%,$(prefixincdir))
  814 packlib := $(patsubst $(prefix)%,$(FBPACKAGE)%,$(prefixlibdir))
  815 
  816 .PHONY: bindist
  817 bindist:
  818     # Extra directory in which we'll put together the binary release package
  819     # (needed anyways to avoid tarbombs)
  820     mkdir -p $(packbin) $(packinc) $(packlib)
  821 
  822     # Copy fbc, binutils + gcc's libexec/.../cc1.exe (standalone), includes,
  823     # libs (including the non-FB ones for standalone)
  824     cp $(FBC_EXE) $(packbin)
  825     cp -r $(rootdir)inc/* $(packinc)
  826   ifdef ENABLE_STANDALONE
  827     mkdir -p $(FBPACKAGE)/bin/$(FBTARGET)
  828     cp bin/$(FBTARGET)/* $(FBPACKAGE)/bin/$(FBTARGET)
  829     cp lib/$(FBTARGET)/*.a lib/$(FBTARGET)/*.o lib/$(FBTARGET)/*.x $(packlib)
  830     if [ -d bin/libexec ]; then \
  831         cp -R bin/libexec $(FBPACKAGE)/bin; \
  832     fi
  833   else
  834     cp $(RTL_LIBS) $(GFX_LIBS) $(packlib)
  835   endif
  836 
  837   ifeq ($(TARGET_OS),dos)
  838     rm -r $(packinc)/AL
  839     rm -r $(packinc)/allegro5
  840     rm -r $(packinc)/atk
  841     rm -r $(packinc)/bass.bi
  842     rm -r $(packinc)/bassmod.bi
  843     rm -r $(packinc)/cairo
  844     rm -r $(packinc)/cd
  845     rm -r $(packinc)/chipmunk
  846     rm -r $(packinc)/crt/arpa
  847     rm -r $(packinc)/crt/bits
  848     rm -r $(packinc)/crt/iconv.bi
  849     rm -r $(packinc)/crt/linux
  850     rm -r $(packinc)/crt/netdb.bi
  851     rm -r $(packinc)/crt/netinet/in.bi
  852     rm -r $(packinc)/crt/netinet/linux/in.bi
  853     rm -r $(packinc)/crt/pthread.bi
  854     rm -r $(packinc)/crt/regex.bi
  855     rm -r $(packinc)/crt/sched.bi
  856     rm -r $(packinc)/crt/sys/linux
  857     rm -r $(packinc)/crt/sys/socket.bi
  858     rm -r $(packinc)/crt/sys/win32
  859     rm -r $(packinc)/crt/win32
  860     rm -r $(packinc)/curses/ncurses.bi
  861     rm -r $(packinc)/disphelper
  862     rm -r $(packinc)/fastcgi
  863     rm -r $(packinc)/ffi.bi
  864     rm -r $(packinc)/flite
  865     rm -r $(packinc)/fmod.bi
  866     rm -r $(packinc)/fontconfig
  867     rm -r $(packinc)/FreeImage.bi
  868     rm -r $(packinc)/freetype2
  869     rm -r $(packinc)/gdk*
  870     rm -r $(packinc)/gio
  871     rm -r $(packinc)/GL
  872     rm -r $(packinc)/GLFW
  873     rm -r $(packinc)/glade
  874     rm -r $(packinc)/glib*
  875     rm -r $(packinc)/gmodule.bi
  876     rm -r $(packinc)/goocanvas.bi
  877     rm -r $(packinc)/gtk*
  878     rm -r $(packinc)/im
  879     rm -r $(packinc)/IUP*
  880     rm -r $(packinc)/japi*
  881     rm -r $(packinc)/jni.bi
  882     rm -r $(packinc)/json*
  883     rm -r $(packinc)/libart_lgpl
  884     rm -r $(packinc)/MediaInfo*
  885     rm -r $(packinc)/modplug.bi
  886     rm -r $(packinc)/mpg123.bi
  887     rm -r $(packinc)/mysql
  888     rm -r $(packinc)/Newton.bi
  889     rm -r $(packinc)/ode
  890     rm -r $(packinc)/ogg
  891     rm -r $(packinc)/pango
  892     rm -r $(packinc)/pdflib.bi
  893     rm -r $(packinc)/portaudio.bi
  894     rm -r $(packinc)/postgresql
  895     rm -r $(packinc)/SDL
  896     rm -r $(packinc)/SDL2
  897     rm -r $(packinc)/sndfile.bi
  898     rm -r $(packinc)/spidermonkey
  899     rm -r $(packinc)/uuid.bi
  900     rm -r $(packinc)/vlc
  901     rm -r $(packinc)/vorbis
  902     rm -r $(packinc)/win
  903     rm -r $(packinc)/windows.bi
  904     rm -r $(packinc)/wx-c
  905     rm -r $(packinc)/X11
  906     rm -r $(packinc)/xcb
  907     rm -r $(packinc)/xmp.bi
  908     rm -r $(packinc)/zmq
  909   endif
  910 
  911   ifeq ($(TARGET_ARCH),x86_64)
  912     # Exclude headers which don't support 64bit yet
  913     rm -r $(packinc)/big_int
  914     rm -r $(packinc)/dislin.bi
  915     rm -r $(packinc)/gettext-po.bi
  916     rm -r $(packinc)/glade
  917     rm -r $(packinc)/goocanvas.bi
  918     rm -r $(packinc)/japi.bi
  919     rm -r $(packinc)/jni.bi
  920     rm -r $(packinc)/jpgalleg.bi
  921     rm -r $(packinc)/libart_lgpl
  922     rm -r $(packinc)/libintl.bi
  923     rm -r $(packinc)/mysql
  924     rm -r $(packinc)/pdflib.bi
  925     rm -r $(packinc)/quicklz.bi
  926     rm -r $(packinc)/spidermonkey
  927     rm -r $(packinc)/tinyptc.bi
  928     rm -r $(packinc)/win/ddk
  929     rm -r $(packinc)/win/rc
  930     rm -r $(packinc)/wx-c
  931   endif
  932 
  933   ifndef DISABLE_DOCS
  934     # Docs
  935     cp $(rootdir)changelog.txt $(rootdir)readme.txt $(FBPACKAGE)
  936     mkdir $(FBPACKAGE)/doc
  937     cp $(rootdir)doc/fbc.1 $(rootdir)doc/gpl.txt $(rootdir)doc/lgpl.txt $(FBPACKAGE)/doc
  938     ifneq ($(filter win32 win64,$(TARGET_OS)),)
  939       ifdef ENABLE_STANDALONE
  940     cp $(rootdir)doc/GoRC.txt $(rootdir)doc/libffi-license.txt $(FBPACKAGE)/doc
  941       endif
  942     endif
  943 
  944     # Examples
  945     cp -R $(rootdir)examples $(FBPACKAGE)
  946     ifeq ($(TARGET_OS),dos)
  947     rm -r $(FBPACKAGE)/examples/database/mysql_test.bas
  948     rm -r $(FBPACKAGE)/examples/database/postgresql_test.bas
  949     rm -r $(FBPACKAGE)/examples/dll
  950     rm -r $(FBPACKAGE)/examples/files/FreeImage
  951     rm -r $(FBPACKAGE)/examples/files/pdflib
  952     rm -r $(FBPACKAGE)/examples/graphics/cairo
  953     rm -r $(FBPACKAGE)/examples/graphics/FreeType
  954     rm -r $(FBPACKAGE)/examples/graphics/OpenGL
  955     rm -r $(FBPACKAGE)/examples/graphics/SDL
  956     rm -r $(FBPACKAGE)/examples/GUI/GTK+
  957     rm -r $(FBPACKAGE)/examples/GUI/IUP
  958     rm -r $(FBPACKAGE)/examples/GUI/win32
  959     rm -r $(FBPACKAGE)/examples/GUI/wx-c
  960     rm -r $(FBPACKAGE)/examples/manual/threads
  961     rm -r $(FBPACKAGE)/examples/math/cryptlib
  962     rm -r $(FBPACKAGE)/examples/math/Newton
  963     rm -r $(FBPACKAGE)/examples/math/ODE
  964     rm -r $(FBPACKAGE)/examples/misc/glib
  965     rm -r $(FBPACKAGE)/examples/network/http-get.bas
  966     rm -r $(FBPACKAGE)/examples/network/win32
  967     rm -r $(FBPACKAGE)/examples/other-languages/Java*
  968     rm -r $(FBPACKAGE)/examples/other-languages/VB
  969     rm -r $(FBPACKAGE)/examples/sound
  970     rm -r $(FBPACKAGE)/examples/threads
  971     rm -r $(FBPACKAGE)/examples/unicode
  972     rm -r $(FBPACKAGE)/examples/win32
  973     endif
  974   endif
  975 
  976     # install.sh for normal Linux/BSD setups
  977   ifndef ENABLE_STANDALONE
  978     ifneq ($(filter darwin freebsd linux netbsd openbsd solaris,$(TARGET_OS)),)
  979     cp $(rootdir)contrib/unix-installer/install.sh $(FBPACKAGE)
  980     endif
  981   endif
  982 
  983     # Regenerate the manifest in the source tree, based on the package directory content
  984     find $(FBPACKAGE) -type f | LC_ALL=C sort \
  985         | sed -e 's,^$(FBPACKAGE)/,,g' \
  986         > $(rootdir)contrib/manifest/$(FBMANIFEST).lst
  987 
  988     # Create the archive(s)
  989     # (overwriting existing ones, instead of adding to them)
  990   ifeq ($(TARGET_OS),dos)
  991     rm -f $(FBPACKAGE).zip
  992     zip -q -r $(FBPACKAGE).zip $(FBPACKAGE)
  993   else
  994   ifneq ($(filter win32 win64,$(TARGET_OS)),)
  995     rm -f $(FBPACKAGE).zip
  996     rm -f $(FBPACKAGE).7z
  997     zip -q -r $(FBPACKAGE).zip $(FBPACKAGE)
  998     7z a $(FBPACKAGE).7z  $(FBPACKAGE) > /dev/null
  999   else
 1000     rm -f $(FBPACKAGE).tar.gz
 1001     rm -f $(FBPACKAGE).tar.xz
 1002     tar -czf $(FBPACKAGE).tar.gz $(FBPACKAGE)
 1003     tar -cJf $(FBPACKAGE).tar.xz $(FBPACKAGE)
 1004   endif
 1005   endif
 1006 
 1007     # Clean up
 1008     rm -rf $(FBPACKAGE)
 1009 
 1010 ifdef ENABLE_STANDALONE
 1011 ifeq ($(TARGET_OS),win32)
 1012 
 1013 mingwlibs += crtbegin.o
 1014 mingwlibs += crtend.o
 1015 mingwlibs += crt2.o
 1016 mingwlibs += dllcrt2.o
 1017 mingwlibs += gcrt2.o
 1018 mingwlibs += libgcc.a
 1019 mingwlibs += libmingw32.a
 1020 mingwlibs += libmingwex.a
 1021 mingwlibs += libmoldname.a
 1022 mingwlibs += libsupc++.a
 1023 mingwlibs += libstdc++.a
 1024 mingwlibs += libgmon.a
 1025 
 1026 winapilibsignore += -e libdelayimp
 1027 winapilibsignore += -e libgcc
 1028 winapilibsignore += -e libgmon
 1029 winapilibsignore += -e libiconv
 1030 winapilibsignore += -e liblargeint
 1031 winapilibsignore += -e 'libm\.a$$'
 1032 winapilibsignore += -e libmangle
 1033 winapilibsignore += -e libmingw
 1034 winapilibsignore += -e libmoldname
 1035 winapilibsignore += -e libpseh
 1036 winapilibsignore += -e libpthread
 1037 winapilibsignore += -e libwinpthread
 1038 winapilibsignore += -e 'libz\.a$$'
 1039 
 1040 .PHONY: mingw-libs
 1041 mingw-libs:
 1042     # MinGW/CRT libs
 1043     for i in $(mingwlibs); do \
 1044         cp `$(CC) -print-file-name=$$i` $(libdir); \
 1045     done
 1046 
 1047     # libgcc_eh.a too, if it exists (TDM-GCC doesn't have it)
 1048     libgcc_eh=`$(CC) -print-file-name=libgcc_eh.a`; \
 1049         if [ -f "$$libgcc_eh" ]; then \
 1050             cp "$$libgcc_eh" $(libdir); \
 1051         fi
 1052 
 1053     # Windows API libs
 1054     #  * copy all lib*.a files from the directory of libkernel32.a
 1055     #  * renaming lib*.a to lib*.dll.a - this isn't 100% correct, because
 1056     #    not all libs really are import libs, but it follows FB tradition.
 1057     #  * Filtering out some libs which are included in MinGW toolchains
 1058     #    sometimes, but we don't want (e.g. libpthread).
 1059     dir=$$(dirname $$($(CC) -print-file-name=libkernel32.a)); \
 1060         ls $$dir/lib*.a | grep -v $(winapilibsignore) | while read i; do \
 1061             cp $$i $(libdir)/`basename $$i | sed -e 's/\.a$$/.dll.a/g'`; \
 1062         done
 1063 
 1064 endif
 1065 endif
 1066 
 1067 #
 1068 # Precompile the compiler sources into .asm/.c files and put them into a
 1069 # bootstrap/ directory, then package the source tree including the bootstrap/
 1070 # sources. This package can then be distributed, and people can do
 1071 # "make bootstrap" to build an fbc from the precompiled sources.
 1072 #
 1073 # The precompiled sources should be compatible to the rtlib in the same source
 1074 # tree, so that it's safe to link the bootstrapped fbc against it. This way
 1075 # there's no need to worry about choosing the right rtlib when bootstrapping
 1076 # fbc -- it's just always possible to use the version from the same source tree.
 1077 #
 1078 FBBOOTSTRAPTITLE := $(FBSOURCETITLE)-bootstrap
 1079 .PHONY: bootstrap-dist
 1080 bootstrap-dist:
 1081     # Precompile fbc sources for various targets
 1082     rm -rf bootstrap
 1083     mkdir -p bootstrap/dos
 1084     mkdir -p bootstrap/freebsd-x86
 1085     mkdir -p bootstrap/freebsd-x86_64
 1086     mkdir -p bootstrap/linux-x86
 1087     mkdir -p bootstrap/linux-x86_64
 1088     mkdir -p bootstrap/win32
 1089     mkdir -p bootstrap/win64
 1090     ./$(FBC_EXE) src/compiler/*.bas -m fbc -i inc -e -r -v -target dos            && mv src/compiler/*.asm bootstrap/dos
 1091     ./$(FBC_EXE) src/compiler/*.bas -m fbc -i inc -e -r -v -target freebsd-x86    && mv src/compiler/*.asm bootstrap/freebsd-x86
 1092     ./$(FBC_EXE) src/compiler/*.bas -m fbc -i inc -e -r -v -target freebsd-x86_64 && mv src/compiler/*.c   bootstrap/freebsd-x86_64
 1093     ./$(FBC_EXE) src/compiler/*.bas -m fbc -i inc -e -r -v -target linux-x86      && mv src/compiler/*.asm bootstrap/linux-x86
 1094     ./$(FBC_EXE) src/compiler/*.bas -m fbc -i inc -e -r -v -target linux-x86_64   && mv src/compiler/*.c   bootstrap/linux-x86_64
 1095     ./$(FBC_EXE) src/compiler/*.bas -m fbc -i inc -e -r -v -target win32          && mv src/compiler/*.asm bootstrap/win32
 1096     ./$(FBC_EXE) src/compiler/*.bas -m fbc -i inc -e -r -v -target win64          && mv src/compiler/*.c   bootstrap/win64
 1097 
 1098     # Ensure to have LFs regardless of host system (LFs will probably work
 1099     # on DOS/Win32, but CRLFs could cause issues on Linux)
 1100     dos2unix bootstrap/dos/*
 1101     dos2unix bootstrap/freebsd-x86/*
 1102     dos2unix bootstrap/freebsd-x86_64/*
 1103     dos2unix bootstrap/linux-x86/*
 1104     dos2unix bootstrap/linux-x86_64/*
 1105     dos2unix bootstrap/win32/*
 1106     dos2unix bootstrap/win64/*
 1107 
 1108     # Package FB sources (similar to our "gitdist" command), and add the bootstrap/ directory
 1109     # Making a .tar.xz should be good enough for now.
 1110     git -c core.autocrlf=false archive --format tar --prefix "$(FBBOOTSTRAPTITLE)/" HEAD | tar xf -
 1111     mv bootstrap $(FBBOOTSTRAPTITLE)
 1112     tar -cJf "$(FBBOOTSTRAPTITLE).tar.xz" "$(FBBOOTSTRAPTITLE)"
 1113     rm -rf "$(FBBOOTSTRAPTITLE)"
 1114 
 1115 #
 1116 # Build the fbc[.exe] binary from the precompiled sources in the bootstrap/
 1117 # directory.
 1118 #
 1119 .PHONY: bootstrap bootstrap-minimal
 1120 bootstrap: gfxlib2 bootstrap-minimal
 1121 
 1122 BOOTSTRAP_FBC := bootstrap/fbc$(EXEEXT)
 1123 bootstrap-minimal: $(BOOTSTRAP_FBC)
 1124     mkdir -p bin
 1125     cp $(BOOTSTRAP_FBC) $(FBC_EXE)
 1126 
 1127 ifeq ($(TARGET_ARCH),x86)
 1128   # x86: .asm => .o (using the same assembler options as fbc)
 1129   BOOTSTRAP_OBJ = $(patsubst %.asm,%.o,$(sort $(wildcard bootstrap/$(FBTARGET)/*.asm)))
 1130   $(BOOTSTRAP_OBJ): %.o: %.asm
 1131     $(QUIET_AS)$(AS) --strip-local-absolute $< -o $@
 1132 else
 1133   # x86_64 etc.: .c => .o (using the same gcc options as fbc -gen gcc)
 1134   BOOTSTRAP_CFLAGS := -nostdinc
 1135   BOOTSTRAP_CFLAGS += -Wall -Wno-unused-label -Wno-unused-function -Wno-unused-variable
 1136   BOOTSTRAP_CFLAGS += -Wno-unused-but-set-variable -Wno-main
 1137   BOOTSTRAP_CFLAGS += -fno-strict-aliasing -frounding-math -fwrapv
 1138   BOOTSTRAP_CFLAGS += -Wfatal-errors
 1139   BOOTSTRAP_OBJ := $(patsubst %.c,%.o,$(sort $(wildcard bootstrap/$(FBTARGET)/*.c)))
 1140   $(BOOTSTRAP_OBJ): %.o: %.c
 1141     $(QUIET_CC)$(CC) -c $(BOOTSTRAP_CFLAGS) $< -o $@
 1142 endif
 1143 
 1144 # Use gcc to link fbc from the bootstrap .o's
 1145 # (assuming the rtlib was built already)
 1146 ifneq ($(filter darwin freebsd linux netbsd openbsd solaris,$(TARGET_OS)),)
 1147   BOOTSTRAP_LIBS := -lncurses -lm -pthread
 1148 endif
 1149 $(BOOTSTRAP_FBC): rtlib $(BOOTSTRAP_OBJ)
 1150     $(QUIET_LINK)$(CC) -o $@ $(libdir)/fbrt0.o bootstrap/$(FBTARGET)/*.o $(libdir)/libfb.a $(BOOTSTRAP_LIBS)
 1151 
 1152 .PHONY: clean-bootstrap
 1153 clean-bootstrap:
 1154     rm -f $(BOOTSTRAP_FBC) bootstrap/$(FBTARGET)/*.o