Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 130 additions & 0 deletions compile-arch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/bin/bash

# Configuration
OUTPUT="hitmanLinux"
SOURCE="hitmanLinux.cpp"
REQUIRED_PACKAGES=(
"gcc"
"pkgconf"
"gtk3"
"libx11"
"libayatana-appindicator"
)

# Compiler flags
CXXFLAGS=(
"-O2" # Optimization level 2
"-Wall" # Enable all warnings
"-Wextra" # Enable extra warnings
"-std=c++11" # C++11 standard
"-fstack-protector-strong" # Stack protection
"-D_FORTIFY_SOURCE=2" # Additional security checks
"-static-libgcc" # Static linking of libgcc
"-static-libstdc++" # Static linking of libstdc++
)

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

# Error handling
set -e # Exit on error

# Print error message and exit
error() {
echo -e "${RED}Error: $1${NC}" >&2
exit 1
}

# Print success message
success() {
echo -e "${GREEN}$1${NC}"
}

# Print warning message
warning() {
echo -e "${YELLOW}Warning: $1${NC}"
}

# Check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}

# Check and install required packages
check_and_install_packages() {
echo "Checking for required packages..."

# Check if we're running on a Debian-based system
if ! command_exists pacman; then
error "This script requires pacman package manager. Please install packages manually."
fi

# Check for sudo privileges
if ! command_exists sudo; then
error "sudo is required to install packages"
fi

local missing_packages=()
for package in "${REQUIRED_PACKAGES[@]}"; do
if ! pacman -Qi "$package" &>/dev/null; then
missing_packages+=("$package")
else
success "$package is already installed."
fi
done

# Install missing packages
if [ ${#missing_packages[@]} -ne 0 ]; then
echo "Installing missing packages: ${missing_packages[*]}"
sudo pacman -Sy --noconfirm "${missing_packages[@]}" || error "Failed to install packages"
fi
}

# Compile source code
compile_source() {
echo "Compiling $SOURCE..."

# Check if source file exists
[ -f "$SOURCE" ] || error "Source file $SOURCE not found"

# Set PKG_CONFIG_PATH
export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig:$PKG_CONFIG_PATH

# Get GTK and X11 flags
local pkg_config_flags
pkg_config_flags=$(pkg-config --cflags --libs gtk+-3.0 x11 ayatana-appindicator3-0.1) || error "Failed to get package config flags"

# Compile
g++ "${CXXFLAGS[@]}" "$SOURCE" -o "$OUTPUT" $pkg_config_flags || error "Compilation failed"

# Make executable
chmod +x "$OUTPUT" || warning "Failed to make file executable"

success "Compilation successful! Output file: $OUTPUT"
}

# Cleanup function
cleanup() {
if [ $? -ne 0 ]; then
echo -e "\n${RED}Compilation failed!${NC}"
# Remove output file if it exists and compilation failed
[ -f "$OUTPUT" ] && rm "$OUTPUT"
fi
}

# Main function
main() {
# Register cleanup function
trap cleanup EXIT

echo "Starting compilation process..."
check_and_install_packages
compile_source
echo -e "\nBuild completed successfully!"
}

# Run main function
main
122 changes: 118 additions & 4 deletions compile.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,119 @@
@echo off
echo Compilation uses g++, make sure you have it installed!
@echo on
windres resources.rc -O coff -o resources.o
g++ -o ProcessHitman.exe hitman.cpp resources.o -mwindows
setlocal enabledelayedexpansion

:: Configuration
set "OUTPUT=ProcessHitman.exe"
set "SOURCE=hitman.cpp"
set "RESOURCE=resources.rc"
set "RESOURCE_OBJ=resources.o"

:: Compiler flags
set "CXXFLAGS=-O2 -Wall -Wextra -std=c++11"
set "LINKFLAGS=-static -static-libgcc -static-libstdc++"
set "WINFLAGS=-mwindows -municode"

:: Colors
set "RED=[91m"
set "GREEN=[92m"
set "YELLOW=[93m"
set "BLUE=[94m"
set "RESET=[0m"

:: Title
title Process Hitman Build Script

echo %BLUE%=================================%RESET%
echo %BLUE% Process Hitman Build Script %RESET%
echo %BLUE%=================================%RESET%
echo.

:: Check for required tools
echo %BLUE%Checking required tools...%RESET%
where g++ >nul 2>&1
if %ERRORLEVEL% neq 0 (
echo %RED%Error: g++ not found! Please install MinGW-w64 and add it to PATH.%RESET%
echo %YELLOW%Download MinGW-w64 from: https://winlibs.com/%RESET%
goto :error
)

where windres >nul 2>&1
if %ERRORLEVEL% neq 0 (
echo %RED%Error: windres not found! Please install MinGW-w64 and add it to PATH.%RESET%
goto :error
)

:: Check if source files exist
echo %BLUE%Checking source files...%RESET%
if not exist "%SOURCE%" (
echo %RED%Error: Source file %SOURCE% not found!%RESET%
goto :error
)

if not exist "%RESOURCE%" (
echo %RED%Error: Resource file %RESOURCE% not found!%RESET%
goto :error
)

:: Clean previous build
echo %BLUE%Cleaning previous build...%RESET%
if exist "%OUTPUT%" (
del "%OUTPUT%" 2>nul
if exist "%OUTPUT%" (
echo %RED%Error: Could not delete previous build!%RESET%
goto :error
) else (
echo %GREEN%Previous build cleaned successfully.%RESET%
)
)

:: Compile resources
echo %BLUE%Compiling resources...%RESET%
windres "%RESOURCE%" -O coff -o "%RESOURCE_OBJ%"
if %ERRORLEVEL% neq 0 (
echo %RED%Error: Failed to compile resources!%RESET%
goto :error
)
echo %GREEN%Resources compiled successfully.%RESET%

:: Compile main program
echo %BLUE%Compiling main program...%RESET%
g++ %CXXFLAGS% %LINKFLAGS% %WINFLAGS% -o "%OUTPUT%" "%SOURCE%" "%RESOURCE_OBJ%"
if %ERRORLEVEL% neq 0 (
echo %RED%Error: Compilation failed!%RESET%
goto :error
)

:: Clean up resource object file
del "%RESOURCE_OBJ%" 2>nul

:: Check if compilation was successful
if exist "%OUTPUT%" (
echo %GREEN%Build completed successfully!%RESET%
echo %GREEN%Output file: %OUTPUT%%RESET%
) else (
echo %RED%Error: Output file not created!%RESET%
goto :error
)

:: Optional: Show file size
for %%A in ("%OUTPUT%") do (
echo %BLUE%File size: %%~zA bytes%RESET%
)

echo.
echo %BLUE%=================================%RESET%
echo %GREEN% Build Process Complete %RESET%
echo %BLUE%=================================%RESET%

goto :end

:error
echo.
echo %RED%=================================%RESET%
echo %RED% Build Process Failed %RESET%
echo %RED%=================================%RESET%
exit /b 1

:end
endlocal
pause
Loading