Files
Vasm/src/unix/Makefile.GCC
2023-04-25 14:39:39 -04:00

281 lines
6.3 KiB
Makefile

#
# VASM VARCem Multi-Target Assembler.
# A simple table-driven assembler for several 8-bit target
# devices, like the 6502, 6800, 80x, Z80 et al series. The
# code originated from Bernd B”ckmann's "asm6502" project.
#
# This file is part of the VARCem Project.
#
# Makefile for UNIX-like systems using the GCC environment.
#
# Version: @(#)Makefile.GCC 1.1.0 2023/04/22
#
# Author: Fred N. van Kempen, <waltje@varcem.com>
#
# Copyright 2023 Fred N. van Kempen.
#
# Redistribution and use in source and binary forms, with
# or without modification, are permitted provided that the
# following conditions are met:
#
# 1. Redistributions of source code must retain the entire
# above notice, this list of conditions and the following
# disclaimer.
#
# 2. Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the
# following disclaimer in the documentation and/or other
# materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names
# of its contributors may be used to endorse or promote
# products derived from this software without specific
# prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
ifndef ARCH
ARCH := x86
endif
ifndef DEBUG
DEBUG := n
endif
# Where is the VARCem tree?
VARCEM := ../../../..
# Where is our Ihex support library?
IHEX := $(VARCEM)/contrib/Ihex
INCS += -I$(IHEX)/include
LDIR += -L$(IHEX)/lib/$(ARCH)/linux
LDLIBS += -lihex #_s
DEFS := -DUSE_IHEX -DALLOW_UNDEFINED_IF
#########################################################################
# Nothing should need changing from here on.. #
#########################################################################
# Import the various platform/architecture names.
ifdef MAKEFILE_LIST
#TOPDIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
TOPDIR := /project/VARCem/src/build
TOPFILE := $(abspath $(firstword $(MAKEFILE_LIST)))
else
TOPDIR := ./build
TOPFILE := Makefile.GCC
endif
include $(TOPDIR)/OSDetect.mk
include $(TOPDIR)/archs.mk
# Definitions for this enivonment.
DEVENV := gcc
DEPS = -MMD -MF $*.d
DEPFILE := .depends-$(DEVENV)
# Compilation for X86.
ifeq ($(ARCH), x86)
TARGET := 32
PREFIX :=
RCTARGET := pe-i386
AFLAGS := -msse2 -mfpmath=sse
ifeq ($(OPTIM), y)
DFLAGS := -march=native
else
DFLAGS := -march=i686
endif
endif
# Compilation for X64.
ifeq ($(ARCH), x64)
TARGET := 64
PREFIX :=
RCTARGET := pe-x86-64
ifeq ($(OPTIM), y)
DFLAGS := -march=native
endif
endif
# Compilation for ARM.
ifeq ($(ARCH), armv7)
error Target ARM7 not supported yet !
endif
# Compilation for ARM64.
ifeq ($(ARCH), aarch64)
error Target ARM64 not supported yet !
endif
# The various toolchain programs.
CC := gcc -m$(TARGET)
CXX := g++ -m$(TARGET)
CPP := cpp -P
LINK := gcc -m$(TARGET)
AR := ar
RANLIB := ranlib
STRIP := strip
ifndef CAT
CAT := cat
endif
# Set up the correct toolchain flags.
OPTS := -DARCH=$(ARCH) \
-D_CRT_NON_CONFORMING_SWPRINTFS
AOPTS := r
LOPTS :=
# General build options.
ifeq ($(DEBUG), y)
DFLAGS += -ggdb -D_DEBUG
AOPTIM :=
ifndef COPTIM
COPTIM := -Og
endif
else
ifeq ($(OPTIM), y)
AOPTIM := -mtune=native
ifndef COPTIM
COPTIM := -O3
endif
else
ifndef COPTIM
COPTIM := -O3
endif
endif
endif
OPTS +=
ifeq ($(PROFILER), y)
LOPTS += -Xlinker -Map=$(PROG).map
endif
# Final fixups.
INCS += -Iunix
# Final versions of the toolchain flags.
CFLAGS = $(WX_FLAGS) $(OPTS) $(DFLAGS) $(COPTIM) $(AOPTIM) \
$(AFLAGS) $(INCS) $(DEFS) -mstackrealign \
-fomit-frame-pointer -fno-strict-aliasing \
-Wall -Wundef #-Wmissing-declarations
LDFLAGS := $(LOPTS) $(DFLAGS) $(LDIR)
ARFLAGS := $(AOPTS)
# Build module rules.
.SUFFIXES: .c .cpp .o
ifeq ($(AUTODEP), y)
%.o: %.c
@echo Compiling $<
@$(CC) $(CFLAGS) $(DEPS) -c $<
else
%.o: %.c
@echo Compiling $<
@$(CC) $(CFLAGS) -c $<
%.d: %.c $(wildcard $*.d)
@echo Compiling $<
@$(CC) $(CFLAGS) $(DEPS) -E $< >NUL
endif
#########################################################################
# Nothing should need changing from here on.. #
#########################################################################
VPATH := unix . targets
#LIBS :=
#LOBJ :=
PROG := vasm
SYSOBJ :=
OBJ := $(SYSOBJ) \
main.o symbol.o expr.o func.o input.o output.o list.o \
parse.o pseudo.o \
target.o \
mos6502.o
all: $(LIBS) $(PROG)
libfoo.dll.a libfoo.so: $(LOBJ)
@echo Linking shared library $@ ..
@$(LINK) $(LDFLAGS) -shared -o $@ \
$(LOBJ)
$(if $(filter $(DEBUG),y),,@$(STRIP) --strip-unneeded $@)
libfoo.a: $(LOBJ)
@echo Creating static library $@ ..
@$(AR) $(ARFLAGS) $@ $(LOBJ)
@$(RANLIB) $@
vasm: $(OBJ)
@echo Linking $@ ..
@$(LINK) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) $(LDLIBS)
$(if $(filter $(DEBUG),y),,@$(STRIP) $@)
test: tests/hello.asm
@echo Assembling hello.asm ..
@asm6502 -v -o hello $<
clean:
@echo Cleaning objects..
@-rm -f *.o
@-rm -f *.d
@echo Cleaning resources..
clobber: clean
@echo Removing executables..
@-rm -f $(PROG)
@echo Cleaning libraries..
@-rm -f *.so
@-rm -f *.a
# @-rm -f $(DEPFILE)
depclean:
@-del $(DEPFILE)
@echo Creating dependencies..
@echo # Run "make depends" to re-create this file. >$(DEPFILE)
depends: DEPOBJ=$(OBJ:%.o=%.d)
depends: depclean $(DEPOBJ)
@$(CAT) $(DEPOBJ) >>$(DEPFILE)
@-del $(DEPOBJ)
$(DEPFILE):
# Module dependencies.
ifeq ($(AUTODEP), y)
-include *.d
else
ifneq ($(wildcard $(DEPFILE)), )
include $(wildcard $(DEPFILE))
endif
endif
# End of Makefile.GCC.