#!/bin/sh # shmake_init.sh - Project initialization for shmake # Author: Emilia Marigold init_project() { printf "Initializing new project...\n\n" read_input "Project Name" "" PROJECT_NAME if [ -z "$PROJECT_NAME" ]; then printf "Error: Project Name cannot be empty.\n" exit 1 fi read_input "C Compiler (gcc, clang, tcc, cc)" "gcc" COMPILER read_input "C Standard (C99, C11, C17, C23)" "C11" C_VERSION read_input "Test Library (Unity, Check, CMOCKA, None)" "None" TEST_LIB printf "\nSelect License:\n" printf " 1) 0BSD\n" printf " 2) AGPL-3.0\n" printf " 3) Apache-2.0\n" printf " 4) BSD-2-Clause\n" printf " 5) BSD-3-Clause\n" printf " 6) BSD-3-Clause-Clear\n" printf " 7) BSL-1.0\n" printf " 8) CC0-1.0\n" printf " 9) CC-BY-4.0\n" printf " 10) CC-BY-SA-4.0\n" printf " 11) EPL-1.0\n" printf " 12) EPL-2.0\n" printf " 13) EUPL-1.2\n" printf " 14) GPL-2.0\n" printf " 15) GPL-3.0\n" printf " 16) ISC\n" printf " 17) LGPL-2.1\n" printf " 18) LGPL-3.0\n" printf " 19) MIT\n" printf " 20) MIT-0\n" printf " 21) MPL-2.0\n" printf " 22) MulanPSL-2.0\n" printf " 23) OFL-1.1\n" printf " 24) OSL-3.0\n" printf " 25) Unlicense\n" printf " 26) UPL-1.0\n" printf " 27) WTFPL\n" printf " 28) Zlib\n" printf " 29) Custom/None\n" printf "\nOption [1-29]: " read -r LICENSE_CHOICE case "$LICENSE_CHOICE" in 1) LICENSE="0BSD" ;; 2) LICENSE="AGPL-3.0" ;; 3) LICENSE="Apache-2.0" ;; 4) LICENSE="BSD-2-Clause" ;; 5) LICENSE="BSD-3-Clause" ;; 6) LICENSE="BSD-3-Clause-Clear" ;; 7) LICENSE="BSL-1.0" ;; 8) LICENSE="CC0-1.0" ;; 9) LICENSE="CC-BY-4.0" ;; 10) LICENSE="CC-BY-SA-4.0" ;; 11) LICENSE="EPL-1.0" ;; 12) LICENSE="EPL-2.0" ;; 13) LICENSE="EUPL-1.2" ;; 14) LICENSE="GPL-2.0" ;; 15) LICENSE="GPL-3.0" ;; 16) LICENSE="ISC" ;; 17) LICENSE="LGPL-2.1" ;; 18) LICENSE="LGPL-3.0" ;; 19) LICENSE="MIT" ;; 20) LICENSE="MIT-0" ;; 21) LICENSE="MPL-2.0" ;; 22) LICENSE="MulanPSL-2.0" ;; 23) LICENSE="OFL-1.1" ;; 24) LICENSE="OSL-3.0" ;; 25) LICENSE="Unlicense" ;; 26) LICENSE="UPL-1.0" ;; 27) LICENSE="WTFPL" ;; 28) LICENSE="Zlib" ;; 29) printf "Enter license name: " read -r LICENSE [ -z "$LICENSE" ] && LICENSE="Custom" ;; *) printf "Invalid selection. Defaulting to Custom\n" LICENSE="Custom" ;; esac TARGETS="linux macos windows bsd ios ipados android" ENABLED_TARGETS="" printf "\nSelect Build Targets (y/n for each):\n" for target in $TARGETS; do printf " Enable %s? [y/n]: " "$target" read -r choice case "$choice" in y|Y) ENABLED_TARGETS="$ENABLED_TARGETS $target" ;; esac done [ -z "$ENABLED_TARGETS" ] && printf "No targets selected. Defaulting to linux.\n" && ENABLED_TARGETS=" linux" printf "\nDo you need a resources folder? [y/n]: " read -r NEED_RESOURCES ENABLED_RESOURCES="" if [ "$NEED_RESOURCES" = "y" ] || [ "$NEED_RESOURCES" = "Y" ]; then printf "\nSelect Resource Sub-directories (y/n for each):\n" RESOURCE_TYPES="fonts images models music sound_effects text textures" for resource in $RESOURCE_TYPES; do printf " Enable %s? [y/n]: " "$resource" read -r choice case "$choice" in y|Y) ENABLED_RESOURCES="$ENABLED_RESOURCES $resource" ;; esac done [ -z "$ENABLED_RESOURCES" ] && printf "No resources selected. Enabling all by default.\n" && ENABLED_RESOURCES=" fonts images models music sound_effects text textures" fi printf "\nVersion Control (git, hg, svn, fossil, bzr, darcs, none): " read -r VCS [ -z "$VCS" ] && VCS="git" VERSION=$(date +"%y.%j.%H%M") printf "\nCreating project folder '%s'...\n" "$PROJECT_NAME" mkdir -p "$PROJECT_NAME" cd "$PROJECT_NAME" || { printf "Error: Failed to enter project directory.\n"; exit 1; } printf "Creating subdirectories...\n" mkdir -p "source_code" mkdir -p "external_code/shared_libraries/source_code" mkdir -p "external_code/shared_libraries/binary" mkdir -p "external_code/test_only/source_code" mkdir -p "external_code/test_only/binary" mkdir -p "external_code/debug_only/source_code" mkdir -p "external_code/debug_only/binary" mkdir -p "external_code/release_only/source_code" mkdir -p "external_code/release_only/binary" mkdir -p "build_output" mkdir -p "intermediate_code" mkdir -p "shmake_config" mkdir -p "shmake_config/shmake_cache" for resource in $ENABLED_RESOURCES; do mkdir -p "resources/$resource" done if [ "$LICENSE_CHOICE" != "29" ]; then process_license "$PROJECT_NAME" "$LICENSE" || { printf "Error: License processing failed.\n"; exit 1; } else printf "Custom license selected. Creating stub...\n" cat > "LICENSE" << EOF $LICENSE License Copyright (c) $(date +%Y) $PROJECT_NAME Permission is hereby granted... EOF fi if [ "$TEST_LIB" != "None" ] && [ "$TEST_LIB" != "none" ]; then clone_test_library "$TEST_LIB" || printf "Note: Test library may need manual installation.\n" fi printf "Creating files...\n" cat > "shmake_config/project.conf" << EOF PROJECT_NAME=$PROJECT_NAME COMPILER=$COMPILER C_VERSION=$C_VERSION TEST_LIB=$TEST_LIB LICENSE=$LICENSE VCS=$VCS VERSION=$VERSION ENABLED_RESOURCES=$ENABLED_RESOURCES ENABLED_TARGETS=$ENABLED_TARGETS EOF cat > "README.md" << EOF # $PROJECT_NAME A C project built with **shmake**. ## Requirements - C Compiler: $COMPILER - C Standard: $C_VERSION Support - Test Library: $TEST_LIB ## License $LICENSE ## Build Run \`shmake sync\` to generate Makefile configs, then \`make\` to build. ## Build Modes - \`make\` (Default: Release) - \`make BUILD_MODE=debug\` - \`make BUILD_MODE=test\` ## Version $VERSION ## Resources $(for res in $ENABLED_RESOURCES; do printf "- %s\n" "$res"; done) EOF case "$VCS" in git) cat > ".gitignore" << EOF build_output/ intermediate_code/ external_code/ *.swp *.swo *~ .DS_Store Thumbs.db shmake_config/ EOF ;; hg) cat > ".hgignore" << EOF syntax: glob build_output/ intermediate_code/ external_code/ *.swp *.swo *~ .DS_Store Thumbs.db shmake_config/ EOF ;; svn) cat > ".svnignore" << EOF build_output intermediate_code external_code *.swp *.swo *~ .DS_Store Thumbs.db shmake_config EOF ;; *) cat > ".gitignore" << EOF build_output/ intermediate_code/ external_code/ *.swp *.swo *~ .DS_Store shmake_config/ EOF ;; esac cat > "source_code/main.c" << EOF #include int main(void) { printf("Hello, %s!\\n", "$PROJECT_NAME"); printf("Version: %s\\n", "$VERSION"); return 0; } EOF for conf in makefile.conf makefile_test.conf makefile_debug.conf makefile_release.conf makefile_clean.conf; do printf "# %s - Initialized by shmake\n" "$conf" > "shmake_config/$conf" done cat > "shmake_config/linked.conf" << 'EOF' # --- shmake Linked Libraries Configuration --- # Format: library names (automatically converted to -l flags) # Example: LINKED_LIBS = -lX11 -lpthread -lm LINKED_LIBS = EOF cat > "Makefile" << 'EOF' # Generated by shmake init # Run 'shmake sync' to populate build configurations. # Portable: Works on GNU Make, bmake, BSD Make (macOS) include shmake_config/makefile.conf PROJECT_NAME = $(PROJECT_NAME) .PHONY: all clean all: @echo "Please run 'shmake sync' to generate build rules." @echo "Then run 'make' to build." clean: rm -rf build_output intermediate_code EOF printf "\nProject '%s' initialized successfully!\n" "$PROJECT_NAME" printf " Version: %s\n" "$VERSION" printf " Build Targets: %s\n" "$ENABLED_TARGETS" printf " Resources: %s\n" "$ENABLED_RESOURCES" printf " License: %s\n" "$LICENSE" printf " Test Library: %s\n" "$TEST_LIB" [ "$TEST_LIB" != "None" ] && [ "$TEST_LIB" != "none" ] && printf " Test Library Location: external_code/test_only/source_code/\n" printf " Next steps:\n" printf " 1. Add your source files to source_code/\n" printf " 2. Run 'shmake sync' to generate Makefile build rules\n" printf " 3. Run 'make' to build\n" printf " 4. Use 'make BUILD_MODE=test' for test builds\n" printf " 5. Use 'shmake link X11 pthread m' to add linked libraries\n" # Return to parent directory cd .. }