Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File Restructure #335

Merged
merged 1 commit into from
Jul 15, 2024
Merged
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
281 changes: 233 additions & 48 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,65 +1,250 @@
# See LICENSE file for copyright and license details.
# The MIT License (MIT)

# Copyright (c) 2014 Michael Crawford

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
#
#### PROJECT SETTINGS ####
include config.mk
# The name of the executable to be created
BIN_NAME := xcb-wswm
# Extension of source files used in the project
SRC_EXT = c
# Path to the source directory, relative to the makefile
SRC_PATH = .
# Space-separated pkg-config libraries used by this project
LIBRARIES = ${LIBS}
# Compilation Architecture.
ARCH32 = -m32 -mtune=generic
ARCH64 = -march=x86-64 -mtune=generic
ARCH = ${ARCH64}
# General compiler flags
COMPILE_FLAGS = ${CFLAGS} ${PRELINKERFLAGS} -DXINERAMA -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L
# Additional release-specific flags
RCOMPILE_FLAGS = -DNDEBUG ${RELEASES}
# Additional debug-specific flags
DCOMPILE_FLAGS = -DDEBUG -DENABLE_DEBUG -DXCB_TRL_ENABLE_DEBUG ${DEBUG}
# Add additional include paths
INCLUDES = -I $(SRC_PATH) ${INCS}
# General linker settings
LINK_FLAGS = ${LINKERFLAGS}
# Additional release-specific linker settings
RLINK_FLAGS = -Wl,--strip-all
# Additional debug-specific linker settings
DLINK_FLAGS = -Wl,--gc-sections
# Destination directory, like a jail or mounted system
DESTDIR = /
# Install path (bin/ is appended automatically)
INSTALL_PREFIX = usr/local
#### END PROJECT SETTINGS ####

SRCDIR = XCB-TRL
# Optionally you may move the section above to a separate config.mk file, and
# uncomment the line below
# include config.mk

BIN = binary
SRC = $(wildcard *.c)
SRC += $(foreach dir, $(SRCDIR), $(wildcard $(dir)/*.c))
SRCH= $(foreach dir, $(SRCDIR), $(wildcard $(dir)/*.h))
OBJ = $(patsubst %.c,${BIN}/%.o,$(SRC))
VERSION = 2.4.0
EXE = dwm
EXEPATH = ${BIN}/${EXE}
CMACROS += -DVERSION=\"${VERSION}\" -DMARK=\"${EXE}\"
CFLAGS += ${CMACROS}
# Generally should not need to edit below this line

all: options default
# Obtains the OS type, either 'Darwin' (OS X) or 'Linux'
UNAME_S:=$(shell uname -s)

${BIN}:
mkdir -p ${BIN}
mkdir -p ${BIN}/${SRCDIR}
options:
@echo ${EXE} build options:
@echo "CFLAGS = ${CFLAGS}"
@echo "LDFLAGS = ${LDFLAGS}"
@echo "CC = ${CC}"
# Function used to check variables. Use on the command line:
# make print-VARNAME
# Useful for debugging and adding features
print-%: ; @echo $*=$($*)

${BIN}/%.o: %.c | ${BIN}
@${CC} ${CFLAGS} -c $< -o $@
@echo "Building:" $<
# Shell used in this makefile
# bash is used for 'echo -en'
SHELL = /bin/bash
# Clear built-in rules
.SUFFIXES:
# Programs for installation
INSTALL = install
INSTALL_PROGRAM = $(INSTALL)
INSTALL_DATA = $(INSTALL) -m 644

default: ${OBJ}
@echo "_Linking:" ${OBJ}
@${CC} -o ${BIN}/${EXE} ${OBJ} ${LDFLAGS}
@echo "Done."
@echo -e "Executable File: "${BIN}/"\033[0;32m"${EXE}'\033[0m'
# Append pkg-config specific libraries if need be
ifneq ($(LIBRARIES),)
COMPILE_FLAGS += $(shell pkg-config --cflags $(LIBRARIES))
LINK_FLAGS += $(shell pkg-config --libs $(LIBRARIES))
endif

# Verbose option, to output compile and link commands
export V := false
export CMD_PREFIX := @
ifeq ($(V),true)
CMD_PREFIX :=
endif

__CLEANARGS = ${RM} ${BIN}/*.o ${BIN}/${SRCDIR}/*.o ${EXEPATH}
# Combine compiler and linker flags
release: export CFLAGS := $(CFLAGS) $(COMPILE_FLAGS) $(RCOMPILE_FLAGS)
release: export LDFLAGS := $(LDFLAGS) $(LINK_FLAGS) $(RLINK_FLAGS)
debug: export CFLAGS := $(CFLAGS) $(COMPILE_FLAGS) $(DCOMPILE_FLAGS)
debug: export LDFLAGS := $(LDFLAGS) $(LINK_FLAGS) $(DLINK_FLAGS)

clean:
${__CLEANARGS}
claen:
${__CLEANARGS}
clen:
${__CLEANARGS}
clena:
${__CLEANARGS}
clane:
${__CLEANARGS}
clear: clean
# Build and output paths
release: export BUILD_PATH := build/release
release: export BIN_PATH := bin/release
debug: export BUILD_PATH := build/debug
debug: export BIN_PATH := bin/debug
install: export BIN_PATH := bin/release

# Find all source files in the source directory, sorted by most
# recently modified
ifeq ($(UNAME_S),Darwin)
SOURCES = $(shell find $(SRC_PATH) -name '*.$(SRC_EXT)' | sort -k 1nr | cut -f2-)
else
SOURCES = $(shell find $(SRC_PATH) -name '*.$(SRC_EXT)' -printf '%T@\t%p\n' \
| sort -k 1nr | cut -f2-)
endif

# fallback in case the above fails
rwildcard = $(foreach d, $(wildcard $1*), $(call rwildcard,$d/,$2) \
$(filter $(subst *,%,$2), $d))
ifeq ($(SOURCES),)
SOURCES := $(call rwildcard, $(SRC_PATH), *.$(SRC_EXT))
endif

# Set the object file names, with the source directory stripped
# from the path, and the build path prepended in its place
OBJECTS = $(SOURCES:$(SRC_PATH)/%.$(SRC_EXT)=$(BUILD_PATH)/%.o)
# Set the dependency files that will be used to add header dependencies
DEPS = $(OBJECTS:.o=.d)

# Macros for timing compilation
ifeq ($(UNAME_S),Darwin)
CUR_TIME = awk 'BEGIN{srand(); print srand()}'
TIME_FILE = $(dir $@).$(notdir $@)_time
START_TIME = $(CUR_TIME) > $(TIME_FILE)
END_TIME = read st < $(TIME_FILE) ; \
$(RM) $(TIME_FILE) ; \
st=$$((`$(CUR_TIME)` - $$st)) ; \
echo $$st
else
TIME_FILE = $(dir $@).$(notdir $@)_time
START_TIME = date '+%s' > $(TIME_FILE)
END_TIME = read st < $(TIME_FILE) ; \
$(RM) $(TIME_FILE) ; \
st=$$((`date '+%s'` - $$st - 86400)) ; \
echo `date -u -d @$$st '+%H:%M:%S'`
endif

# Version macros
# Comment/remove this section to remove versioning
USE_VERSION := false
# If this isn't a git repo or the repo has no tags, git describe will return non-zero
ifeq ($(shell git describe > /dev/null 2>&1 ; echo $$?), 0)
USE_VERSION := true
VERSION := $(shell git describe --tags --long --dirty --always | \
sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)-\?.*-\([0-9]*\)-\(.*\)/\1 \2 \3 \4 \5/g')
VERSION_MAJOR := $(word 1, $(VERSION))
VERSION_MINOR := $(word 2, $(VERSION))
VERSION_PATCH := $(word 3, $(VERSION))
VERSION_REVISION := $(word 4, $(VERSION))
VERSION_HASH := $(word 5, $(VERSION))
VERSION_STRING := \
"$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH).$(VERSION_REVISION)-$(VERSION_HASH)"
override CFLAGS := $(CFLAGS) \
-D VERSION_MAJOR=$(VERSION_MAJOR) \
-D VERSION_MINOR=$(VERSION_MINOR) \
-D VERSION_PATCH=$(VERSION_PATCH) \
-D VERSION_REVISION=$(VERSION_REVISION) \
-D VERSION_HASH=\"$(VERSION_HASH)\"
endif

rebuild: clean default
# Standard, non-optimized release build
.PHONY: release
release: dirs
ifeq ($(USE_VERSION), true)
@echo "Beginning release build v$(VERSION_STRING)"
else
@echo "Beginning release build"
endif
@$(START_TIME)
@$(MAKE) all --no-print-directory
@echo -n "Total build time: "
@$(END_TIME)

install: all
mkdir -p ${DESTDIR}${PREFIX}/bin
cp -f ${EXEPATH} ${DESTDIR}${PREFIX}/bin
chmod 755 ${DESTDIR}${PREFIX}/bin/${EXE}
# Debug build for gdb debugging
.PHONY: debug
debug: dirs
ifeq ($(USE_VERSION), true)
@echo "Beginning debug build v$(VERSION_STRING)"
else
@echo "Beginning debug build"
endif
@$(START_TIME)
@$(MAKE) all --no-print-directory
@echo -n "Total build time: "
@$(END_TIME)

# Create the directories used in the build
.PHONY: dirs
dirs:
@echo "Creating directories"
@mkdir -p $(dir $(OBJECTS))
@mkdir -p $(BIN_PATH)

# Installs to the set path
.PHONY: install
install:
@echo "Installing to $(DESTDIR)$(INSTALL_PREFIX)/bin"
@$(INSTALL_PROGRAM) $(BIN_PATH)/$(BIN_NAME) $(DESTDIR)$(INSTALL_PREFIX)/bin

# Uninstalls the program
.PHONY: uninstall
uninstall:
rm -f ${DESTDIR}${PREFIX}/bin/${EXE}
@echo "Removing $(DESTDIR)$(INSTALL_PREFIX)/bin/$(BIN_NAME)"
@$(RM) $(DESTDIR)$(INSTALL_PREFIX)/bin/$(BIN_NAME)

# Removes all build files
.PHONY: clean
clean:
# @echo "Deleting $(BIN_NAME) symlink"
# @$(RM) $(BIN_NAME)
@echo "Deleting directories"
@$(RM) -r build
@$(RM) -r bin

# Main rule, checks the executable and symlinks to the output
all: $(BIN_PATH)/$(BIN_NAME)
@echo "Making symlink: $(BIN_NAME) -> $<"
@$(RM) $(BIN_NAME)
# @ln -s $(BIN_PATH)/$(BIN_NAME) $(BIN_NAME)

# Link the executable
$(BIN_PATH)/$(BIN_NAME): $(OBJECTS)
@echo "Linking: $@"
@$(START_TIME)
$(CMD_PREFIX)$(CC) $(OBJECTS) $(LDFLAGS) -o $@
@echo -en "\t Link time: "
@$(END_TIME)

# Add dependency files, if they exist
-include $(DEPS)

.PHONY: all options clean clear release dist install uninstall
# Source file rules
# After the first compilation they will be joined with the rules from the
# dependency files to provide header dependencies
$(BUILD_PATH)/%.o: $(SRC_PATH)/%.$(SRC_EXT)
@echo "Building: $< -> $@"
# @$(START_TIME)
$(CMD_PREFIX)$(CC) $(CFLAGS) $(INCLUDES) -MP -MMD -c $< -o $@
# @echo -en "\t Compile time: "
# @$(END_TIME)
40 changes: 10 additions & 30 deletions config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ MANPREFIX = ${PREFIX}/share/man
# For more just do (GNU)
# cd /usr/lib/pkgconfig/
# grep -r xcb
INCS = `pkg-config --cflags --libs xcb xcb-util xcb-aux xcb-xinerama xcb-event xcb-keysyms`

# fallback
XCB_INCS_PKG = `pkg-config --cflags --libs xcb xcb-util xcb-aux xcb-xinerama xcb-event xcb-keysyms`
XCB_INCS = -Ixcb -Ixcb-util -Ixcb-aux -Ixcb-xinerama -Ixcb-event -Ixcb-keysyms
TOOLS = -Itools
INCLUDE_INCS = -Iinclude
INCS = ${XCB_INCS} ${INCLUDE_INCS} ${TOOLS}
#-lxcb-util -lxcb-icccm -lxcb-keysyms
LIBS = ${INCS}
LIBS = ${XCB_INCS_PKG}

#X86 isnt explicitly supported.
X86 = -m32
X32 = -m32
X64 = -march=x86-64 -mtune=generic
CCVERSION = -std=c99
XNATIVE = -march=native -mtune=native
# Some libraries dont have static linking for some reason??
Expand All @@ -42,7 +44,7 @@ PRELINKERFLAGS = -fstack-protector-strong -fstack-clash-protection -fpie ${LINKT

# can set higher but function overhead is pretty small so meh
INLINELIMIT = 15
LINKERFLAGS = ${LINKMODE} -Wl,--gc-sections,--as-needed,--relax,--strip-all,-z,relro,-z,now,-z,noexecstack,-z,defs,-pie -finline-limit=${INLINELIMIT} ${LINKTIMEOPTIMIZATIONS}
LINKERFLAGS = ${LINKMODE} -Wl,--gc-sections,--as-needed,--relax,-z,relro,-z,now,-z,noexecstack,-z,defs,-pie -finline-limit=${INLINELIMIT} ${LINKTIMEOPTIMIZATIONS}

BINARY = ${X64}
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L ${XINERAMAFLAGS}
Expand All @@ -65,29 +67,7 @@ RELEASES= ${RELEASEFLAGS} -O3
# Build using cpu specific instruction set for more performance (Optional)
BUILDSELF = ${RELEASEFLAGS} ${XNATIVE} -O3

# Set your options or presets (see above) ex: ${PRESETNAME} (Compiler used is on top)
CFLAGS = ${DEBUG}

CMACROS = -DXINERAMA




STRIP = 0

ifeq ($(STRIP), 0)
LINKERFLAGS = ${DYNAMICLINK} -Wl,--gc-sections
endif


# debug macros
ifeq ($(CFLAGS), $(DEBUG))
CMACROS += -DENABLE_DEBUG
CMACROS += -DXCB_TRL_ENABLE_DEBUG
LINKERFLAGS += ${DEBUGFLAGS}
endif

# Linker flags
LDFLAGS = ${LIBS} ${LINKERFLAGS} ${BINARY}
LDFLAGS = ${LIBS} ${LINKERFLAGS} ${BINARY}
# Solaris
#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
File renamed without changes.
1 change: 0 additions & 1 deletion client.h → include/client.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef _WM_CLIENT_H
#define _WM_CLIENT_H


#include "XCB-TRL/xcb_trl.h"
#include "decorations.h"

Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion desktop.h → include/desktop.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ struct Desktop
Client *sel; /* Selected Client */
Desktop *next; /* Next Client in linked list */
Desktop *prev; /* Previous Client in list */
UserSettings *settings; /* User settings data */
};

struct Layout
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading